2021-07-12 10:14:26 +02:00
|
|
|
package audio.funkwhale.ffa.repositories
|
2020-06-02 18:50:46 +02:00
|
|
|
|
|
|
|
import android.content.Context
|
2021-07-12 10:14:26 +02:00
|
|
|
import audio.funkwhale.ffa.utils.OtterResponse
|
|
|
|
import audio.funkwhale.ffa.utils.Track
|
|
|
|
import audio.funkwhale.ffa.utils.TracksCache
|
|
|
|
import audio.funkwhale.ffa.utils.TracksResponse
|
2020-06-02 18:50:46 +02:00
|
|
|
import com.github.kittinunf.fuel.gson.gsonDeserializerOf
|
|
|
|
import com.google.gson.reflect.TypeToken
|
|
|
|
import java.io.BufferedReader
|
|
|
|
|
|
|
|
class ArtistTracksRepository(override val context: Context?, private val artistId: Int) : Repository<Track, TracksCache>() {
|
2020-06-11 00:01:39 +02:00
|
|
|
override val cacheId = "tracks-artist-$artistId"
|
2020-07-10 20:40:18 +02:00
|
|
|
override val upstream = HttpUpstream<Track, OtterResponse<Track>>(HttpUpstream.Behavior.AtOnce, "/api/v1/tracks/?playable=true&artist=$artistId", object : TypeToken<TracksResponse>() {}.type)
|
2020-06-02 18:50:46 +02:00
|
|
|
|
|
|
|
override fun cache(data: List<Track>) = TracksCache(data)
|
|
|
|
override fun uncache(reader: BufferedReader) = gsonDeserializerOf(TracksCache::class.java).deserialize(reader)
|
2021-07-02 13:55:49 +02:00
|
|
|
}
|