2021-07-02 13:55:49 +02:00
|
|
|
package org.funkwhale.ffa.repositories
|
2019-08-19 16:50:33 +02:00
|
|
|
|
|
|
|
import android.content.Context
|
2021-07-02 13:55:49 +02:00
|
|
|
import org.funkwhale.ffa.utils.Album
|
|
|
|
import org.funkwhale.ffa.utils.AlbumsCache
|
|
|
|
import org.funkwhale.ffa.utils.AlbumsResponse
|
|
|
|
import org.funkwhale.ffa.utils.OtterResponse
|
2019-08-19 16:50:33 +02:00
|
|
|
import com.github.kittinunf.fuel.gson.gsonDeserializerOf
|
|
|
|
import com.google.gson.reflect.TypeToken
|
|
|
|
import java.io.BufferedReader
|
|
|
|
|
|
|
|
class AlbumsRepository(override val context: Context?, artistId: Int? = null) : Repository<Album, AlbumsCache>() {
|
|
|
|
override val cacheId: String by lazy {
|
|
|
|
if (artistId == null) "albums"
|
|
|
|
else "albums-artist-$artistId"
|
|
|
|
}
|
|
|
|
|
|
|
|
override val upstream: Upstream<Album> by lazy {
|
|
|
|
val url =
|
2020-07-08 13:19:03 +02:00
|
|
|
if (artistId == null) "/api/v1/albums/?playable=true&ordering=title"
|
|
|
|
else "/api/v1/albums/?playable=true&artist=$artistId&ordering=release_date"
|
2019-08-19 16:50:33 +02:00
|
|
|
|
2020-07-10 20:40:18 +02:00
|
|
|
HttpUpstream<Album, OtterResponse<Album>>(
|
2019-08-19 16:50:33 +02:00
|
|
|
HttpUpstream.Behavior.Progressive,
|
|
|
|
url,
|
|
|
|
object : TypeToken<AlbumsResponse>() {}.type
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun cache(data: List<Album>) = AlbumsCache(data)
|
|
|
|
override fun uncache(reader: BufferedReader) = gsonDeserializerOf(AlbumsCache::class.java).deserialize(reader)
|
2021-07-02 13:55:49 +02:00
|
|
|
}
|