-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
709 additions
and
11 deletions.
There are no files selected for viewing
545 changes: 545 additions & 0 deletions
545
app/schemas/me.vanpetegem.accentor.data.AccentorDatabase/8.json
Large diffs are not rendered by default.
Oops, something went wrong.
25 changes: 25 additions & 0 deletions
25
app/src/main/java/me/vanpetegem/accentor/api/plays/Play.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package me.vanpetegem.accentor.api.plays | ||
|
||
import com.github.kittinunf.fuel.httpPost | ||
import java.time.Instant | ||
import me.vanpetegem.accentor.data.authentication.AuthenticationData | ||
import me.vanpetegem.accentor.data.plays.Play | ||
import me.vanpetegem.accentor.util.Result | ||
import me.vanpetegem.accentor.util.jsonBody | ||
import me.vanpetegem.accentor.util.responseObject | ||
|
||
data class Arguments(val play: PlayArguments) | ||
data class PlayArguments(val trackId: Int, val playedAt: Instant) | ||
|
||
fun create(server: String, authenticationData: AuthenticationData, trackId: Int, playedAt: Instant): Result<Play> { | ||
return "$server/api/plays".httpPost() | ||
.set("Accept", "application/json") | ||
.set("X-Secret", authenticationData.secret) | ||
.set("X-Device-Id", authenticationData.deviceId) | ||
.jsonBody(Arguments(PlayArguments(trackId, playedAt))) | ||
.responseObject<Play>().third | ||
.fold( | ||
{ play: Play -> Result.Success(play) }, | ||
{ e: Throwable -> Result.Error(Exception("Error creating play", e)) }, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
app/src/main/java/me/vanpetegem/accentor/data/plays/Play.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package me.vanpetegem.accentor.data.plays | ||
|
||
import java.time.Instant | ||
|
||
data class Play( | ||
val id: Int, | ||
val playedAt: Instant, | ||
val trackId: Int, | ||
val userId: Int, | ||
) |
27 changes: 27 additions & 0 deletions
27
app/src/main/java/me/vanpetegem/accentor/data/plays/PlayRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package me.vanpetegem.accentor.data.plays | ||
|
||
import java.time.Instant | ||
import javax.inject.Inject | ||
import me.vanpetegem.accentor.api.plays.create | ||
import me.vanpetegem.accentor.data.authentication.AuthenticationRepository | ||
import me.vanpetegem.accentor.util.Result | ||
|
||
class PlayRepository @Inject constructor( | ||
private val authenticationRepository: AuthenticationRepository, | ||
private val unreportedPlayDao: UnreportedPlayDao, | ||
) { | ||
suspend fun reportPlay(trackId: Int, playedAt: Instant) { | ||
when (create(authenticationRepository.server.value!!, authenticationRepository.authData.value!!, trackId, playedAt)) { | ||
is Result.Success -> { | ||
for (play in unreportedPlayDao.getAllUnreportedPlays()) { | ||
when (create(authenticationRepository.server.value!!, authenticationRepository.authData.value!!, play.trackId, play.playedAt)) { | ||
is Result.Success -> unreportedPlayDao.delete(play) | ||
} | ||
} | ||
} | ||
is Result.Error -> { | ||
unreportedPlayDao.insert(UnreportedPlay(trackId = trackId, playedAt = playedAt)) | ||
} | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
app/src/main/java/me/vanpetegem/accentor/data/plays/UnreportedPlay.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package me.vanpetegem.accentor.data.plays | ||
|
||
import androidx.room.ColumnInfo | ||
import androidx.room.Entity | ||
import androidx.room.PrimaryKey | ||
import java.time.Instant | ||
|
||
@Entity(tableName = "unreported_plays") | ||
data class UnreportedPlay( | ||
@PrimaryKey(autoGenerate = true) | ||
val id: Int = 0, | ||
@ColumnInfo(name = "track_id") | ||
val trackId: Int, | ||
@ColumnInfo(name = "played_at") | ||
val playedAt: Instant, | ||
) |
18 changes: 18 additions & 0 deletions
18
app/src/main/java/me/vanpetegem/accentor/data/plays/UnreportedPlayDao.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package me.vanpetegem.accentor.data.plays | ||
|
||
import androidx.room.Dao | ||
import androidx.room.Delete | ||
import androidx.room.Insert | ||
import androidx.room.Query | ||
|
||
@Dao | ||
interface UnreportedPlayDao { | ||
@Query("SELECT * FROM unreported_plays") | ||
fun getAllUnreportedPlays(): List<UnreportedPlay> | ||
|
||
@Insert | ||
fun insert(play: UnreportedPlay) | ||
|
||
@Delete | ||
fun delete(play: UnreportedPlay) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters