2021-07-12 10:14:26 +02:00
|
|
|
package audio.funkwhale.ffa.repositories
|
2019-08-19 16:50:33 +02:00
|
|
|
|
|
|
|
import android.content.Context
|
2021-07-12 10:14:26 +02:00
|
|
|
import audio.funkwhale.ffa.utils.Artist
|
|
|
|
import audio.funkwhale.ffa.utils.ArtistsCache
|
|
|
|
import audio.funkwhale.ffa.utils.ArtistsResponse
|
|
|
|
import audio.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 ArtistsRepository(override val context: Context?) : Repository<Artist, ArtistsCache>() {
|
2021-07-23 14:10:13 +02:00
|
|
|
|
2019-08-19 16:50:33 +02:00
|
|
|
override val cacheId = "artists"
|
2021-07-23 14:10:13 +02:00
|
|
|
|
|
|
|
override val upstream = HttpUpstream<Artist, OtterResponse<Artist>>(
|
|
|
|
context,
|
|
|
|
HttpUpstream.Behavior.Progressive,
|
|
|
|
"/api/v1/artists/?playable=true&ordering=name",
|
|
|
|
object : TypeToken<ArtistsResponse>() {}.type
|
|
|
|
)
|
2019-08-19 16:50:33 +02:00
|
|
|
|
|
|
|
override fun cache(data: List<Artist>) = ArtistsCache(data)
|
2021-07-23 14:10:13 +02:00
|
|
|
override fun uncache(reader: BufferedReader) =
|
|
|
|
gsonDeserializerOf(ArtistsCache::class.java).deserialize(reader)
|
2021-07-02 13:55:49 +02:00
|
|
|
}
|