Otter-App-Android-Funkwhale/app/src/main/java/com/github/apognu/otter/repositories/PlaylistsRepository.kt

19 lines
691 B
Kotlin
Raw Normal View History

2019-08-19 16:50:33 +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.FunkwhalePlaylist
import com.github.apognu.otter.models.dao.toDao
2019-08-19 16:50:33 +02:00
2020-07-13 23:32:42 +02:00
class PlaylistsRepository(override val context: Context?) : Repository<FunkwhalePlaylist>() {
override val upstream =
HttpUpstream(HttpUpstream.Behavior.Progressive, "/api/v1/playlists/?playable=true&ordering=name", FunkwhalePlaylist.serializer())
2019-08-19 16:50:33 +02:00
2020-07-13 23:32:42 +02:00
override fun onDataFetched(data: List<FunkwhalePlaylist>): List<FunkwhalePlaylist> {
data.forEach {
Otter.get().database.playlists().insert(it.toDao())
}
return super.onDataFetched(data)
}
2019-08-19 16:50:33 +02:00
}