2021-07-12 10:14:26 +02:00
|
|
|
package audio.funkwhale.ffa.repositories
|
2020-05-30 21:16:28 +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.Radio
|
|
|
|
import audio.funkwhale.ffa.utils.RadiosCache
|
|
|
|
import audio.funkwhale.ffa.utils.RadiosResponse
|
2020-05-30 21:16:28 +02:00
|
|
|
import com.github.kittinunf.fuel.gson.gsonDeserializerOf
|
|
|
|
import com.google.gson.reflect.TypeToken
|
|
|
|
import java.io.BufferedReader
|
|
|
|
|
|
|
|
class RadiosRepository(override val context: Context?) : Repository<Radio, RadiosCache>() {
|
2021-07-23 14:10:13 +02:00
|
|
|
|
2021-07-30 10:57:49 +02:00
|
|
|
private val oAuth = OAuthFactory.instance()
|
|
|
|
|
2020-05-30 21:16:28 +02:00
|
|
|
override val cacheId = "radios"
|
2021-07-23 14:10:13 +02:00
|
|
|
|
|
|
|
override val upstream = HttpUpstream<Radio, OtterResponse<Radio>>(
|
|
|
|
context,
|
|
|
|
HttpUpstream.Behavior.Progressive,
|
|
|
|
"/api/v1/radios/radios/?ordering=name",
|
2021-07-30 10:57:49 +02:00
|
|
|
object : TypeToken<RadiosResponse>() {}.type,
|
|
|
|
oAuth
|
2021-07-23 14:10:13 +02:00
|
|
|
)
|
2020-05-30 21:16:28 +02:00
|
|
|
|
|
|
|
override fun cache(data: List<Radio>) = RadiosCache(data)
|
2021-07-23 14:10:13 +02:00
|
|
|
override fun uncache(reader: BufferedReader) =
|
|
|
|
gsonDeserializerOf(RadiosCache::class.java).deserialize(reader)
|
2020-06-01 14:38:50 +02:00
|
|
|
|
|
|
|
override fun onDataFetched(data: List<Radio>): List<Radio> {
|
|
|
|
return data
|
2020-06-21 13:36:42 +02:00
|
|
|
.map { radio -> radio.apply { radio_type = "custom" } }
|
2020-06-01 14:38:50 +02:00
|
|
|
.toMutableList()
|
|
|
|
}
|
2021-07-02 13:55:49 +02:00
|
|
|
}
|