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

37 lines
1.2 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.Radio
import audio.funkwhale.ffa.utils.RadiosCache
import audio.funkwhale.ffa.utils.RadiosResponse
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()
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
)
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)
override fun onDataFetched(data: List<Radio>): List<Radio> {
return data
.map { radio -> radio.apply { radio_type = "custom" } }
.toMutableList()
}
2021-07-02 13:55:49 +02:00
}