|
|
@ -18,21 +18,7 @@ class TracksRepository(override val context: Context?, albumId: Int) : Repositor |
|
|
|
override fun cache(data: List<Track>) = TracksCache(data) |
|
|
|
override fun cache(data: List<Track>) = TracksCache(data) |
|
|
|
override fun uncache(reader: BufferedReader) = gsonDeserializerOf(TracksCache::class.java).deserialize(reader) |
|
|
|
override fun uncache(reader: BufferedReader) = gsonDeserializerOf(TracksCache::class.java).deserialize(reader) |
|
|
|
|
|
|
|
|
|
|
|
override fun onDataFetched(data: List<Track>): List<Track> = runBlocking { |
|
|
|
companion object { |
|
|
|
val favorites = FavoritedRepository(context).fetch(Origin.Network.origin) |
|
|
|
|
|
|
|
.map { it.data } |
|
|
|
|
|
|
|
.toList() |
|
|
|
|
|
|
|
.flatten() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val downloaded = getDownloadedIds() ?: listOf() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data.map { track -> |
|
|
|
|
|
|
|
track.favorite = favorites.contains(track.id) |
|
|
|
|
|
|
|
track.downloaded = downloaded.contains(track.id) |
|
|
|
|
|
|
|
track |
|
|
|
|
|
|
|
}.sortedBy { it.position } |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
suspend fun getDownloadedIds(): List<Int>? { |
|
|
|
suspend fun getDownloadedIds(): List<Int>? { |
|
|
|
return RequestBus.send(Request.GetDownloads).wait<com.github.apognu.otter.utils.Response.Downloads>()?.let { response -> |
|
|
|
return RequestBus.send(Request.GetDownloads).wait<com.github.apognu.otter.utils.Response.Downloads>()?.let { response -> |
|
|
|
val ids: MutableList<Int> = mutableListOf() |
|
|
|
val ids: MutableList<Int> = mutableListOf() |
|
|
@ -50,4 +36,20 @@ class TracksRepository(override val context: Context?, albumId: Int) : Repositor |
|
|
|
ids |
|
|
|
ids |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onDataFetched(data: List<Track>): List<Track> = runBlocking { |
|
|
|
|
|
|
|
val favorites = FavoritedRepository(context).fetch(Origin.Network.origin) |
|
|
|
|
|
|
|
.map { it.data } |
|
|
|
|
|
|
|
.toList() |
|
|
|
|
|
|
|
.flatten() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val downloaded = getDownloadedIds() ?: listOf() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data.map { track -> |
|
|
|
|
|
|
|
track.favorite = favorites.contains(track.id) |
|
|
|
|
|
|
|
track.downloaded = downloaded.contains(track.id) |
|
|
|
|
|
|
|
track |
|
|
|
|
|
|
|
}.sortedBy { it.position } |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |