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-30 10:57:49 +02:00
|
|
|
import audio.funkwhale.ffa.utils.OAuthFactory
|
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
|
|
|
|
|
2021-07-23 14:10:13 +02:00
|
|
|
class ArtistTracksRepository(override val context: Context?, private val artistId: Int) :
|
|
|
|
Repository<Track, TracksCache>() {
|
|
|
|
|
2021-07-30 10:57:49 +02:00
|
|
|
private val oAuth = OAuthFactory.instance()
|
|
|
|
|
2020-06-11 00:01:39 +02:00
|
|
|
override val cacheId = "tracks-artist-$artistId"
|
2021-07-23 14:10:13 +02:00
|
|
|
|
|
|
|
override val upstream = HttpUpstream<Track, OtterResponse<Track>>(
|
|
|
|
context,
|
|
|
|
HttpUpstream.Behavior.AtOnce,
|
|
|
|
"/api/v1/tracks/?playable=true&artist=$artistId",
|
2021-07-30 10:57:49 +02:00
|
|
|
object : TypeToken<TracksResponse>() {}.type,
|
|
|
|
oAuth
|
2021-07-23 14:10:13 +02:00
|
|
|
)
|
2020-06-02 18:50:46 +02:00
|
|
|
|
|
|
|
override fun cache(data: List<Track>) = TracksCache(data)
|
2021-07-23 14:10:13 +02:00
|
|
|
override fun uncache(reader: BufferedReader) =
|
|
|
|
gsonDeserializerOf(TracksCache::class.java).deserialize(reader)
|
2021-07-02 13:55:49 +02:00
|
|
|
}
|