funkwhale-app-android/app/src/main/java/audio/funkwhale/ffa/repositories/ArtistTracksRepository.kt

32 lines
1.0 KiB
Kotlin
Raw Normal View History

package audio.funkwhale.ffa.repositories
import android.content.Context
2021-07-30 10:57:49 +02:00
import audio.funkwhale.ffa.utils.OAuthFactory
import audio.funkwhale.ffa.utils.OtterResponse
import audio.funkwhale.ffa.utils.Track
import audio.funkwhale.ffa.utils.TracksCache
import audio.funkwhale.ffa.utils.TracksResponse
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
)
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
}