2020-06-02 18:50:46 +02:00
|
|
|
package com.github.apognu.otter.repositories
|
|
|
|
|
|
|
|
import android.content.Context
|
2020-07-13 23:32:42 +02:00
|
|
|
import com.github.apognu.otter.Otter
|
|
|
|
import com.github.apognu.otter.models.api.FunkwhaleTrack
|
|
|
|
import kotlinx.coroutines.Dispatchers.IO
|
|
|
|
import kotlinx.coroutines.runBlocking
|
2020-06-02 18:50:46 +02:00
|
|
|
|
2020-07-13 23:32:42 +02:00
|
|
|
class ArtistTracksRepository(override val context: Context?, private val artistId: Int) : Repository<FunkwhaleTrack>() {
|
|
|
|
override val upstream = HttpUpstream(HttpUpstream.Behavior.AtOnce, "/api/v1/tracks/?playable=true&artist=$artistId", FunkwhaleTrack.serializer())
|
2020-06-02 18:50:46 +02:00
|
|
|
|
2020-07-13 23:32:42 +02:00
|
|
|
override fun onDataFetched(data: List<FunkwhaleTrack>) = runBlocking(IO) {
|
|
|
|
data.forEach {
|
|
|
|
Otter.get().database.tracks().insertWithAssocs(it)
|
|
|
|
}
|
|
|
|
|
|
|
|
super.onDataFetched(data)
|
|
|
|
}
|
2020-06-02 18:50:46 +02:00
|
|
|
}
|