2020-05-30 21:16:28 +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.FunkwhaleRadio
|
|
|
|
import com.github.apognu.otter.models.dao.toDao
|
2020-05-30 21:16:28 +02:00
|
|
|
|
2020-07-13 23:32:42 +02:00
|
|
|
class RadiosRepository(override val context: Context?) : Repository<FunkwhaleRadio>() {
|
|
|
|
override val upstream =
|
|
|
|
HttpUpstream(HttpUpstream.Behavior.Progressive, "/api/v1/radios/radios/?playable=true&ordering=name", FunkwhaleRadio.serializer())
|
2020-05-30 21:16:28 +02:00
|
|
|
|
2020-07-13 23:32:42 +02:00
|
|
|
override fun onDataFetched(data: List<FunkwhaleRadio>): List<FunkwhaleRadio> {
|
|
|
|
data.forEach {
|
|
|
|
Otter.get().database.radios().insert(it.toDao())
|
|
|
|
}
|
2020-06-01 14:38:50 +02:00
|
|
|
|
|
|
|
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()
|
|
|
|
}
|
2020-05-30 21:16:28 +02:00
|
|
|
}
|