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-08-22 09:48:33 +02:00
|
|
|
import audio.funkwhale.ffa.model.FFAResponse
|
|
|
|
import audio.funkwhale.ffa.model.Track
|
|
|
|
import audio.funkwhale.ffa.model.TracksCache
|
|
|
|
import audio.funkwhale.ffa.model.TracksResponse
|
|
|
|
import audio.funkwhale.ffa.utils.OAuth
|
2022-06-16 15:08:29 +02:00
|
|
|
import audio.funkwhale.ffa.utils.gsonDeserializerOf
|
2020-06-02 18:50:46 +02:00
|
|
|
import com.google.gson.reflect.TypeToken
|
2021-08-09 06:50:46 +02:00
|
|
|
import org.koin.java.KoinJavaComponent.inject
|
2020-06-02 18:50:46 +02:00
|
|
|
|
2021-07-23 14:10:13 +02:00
|
|
|
class ArtistTracksRepository(override val context: Context?, private val artistId: Int) :
|
|
|
|
Repository<Track, TracksCache>() {
|
|
|
|
|
2021-08-09 06:50:46 +02:00
|
|
|
private val oAuth: OAuth by inject(OAuth::class.java)
|
2021-07-30 10:57:49 +02:00
|
|
|
|
2020-06-11 00:01:39 +02:00
|
|
|
override val cacheId = "tracks-artist-$artistId"
|
2021-07-23 14:10:13 +02:00
|
|
|
|
2021-08-22 09:48:33 +02:00
|
|
|
override val upstream = HttpUpstream<Track, FFAResponse<Track>>(
|
2021-07-23 14:10:13 +02:00
|
|
|
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)
|
2022-06-12 14:48:32 +02:00
|
|
|
override fun uncache(json: String) =
|
2022-07-14 13:12:30 +02:00
|
|
|
gsonDeserializerOf(TracksCache::class.java).deserialize(json.reader())
|
2021-07-02 13:55:49 +02:00
|
|
|
}
|