Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Provider for PagedList with Kitsu items
object KitsuMediaPagedListProvider {
private val dataSource = object: KitsuLimitOffsetNetworkDataSource<KitsuItem>(KitsuRestApi) {
override fun convertToItems(items: KitsuResponse, size: Int): List<KitsuItem> {
return List(size, { index ->
items.data.elementAtOrElse(index, { KitsuItem(0, null, null) })
})
}
}
fun allKitsu(): LivePagedListProvider<Int, KitsuItem> {
return object : LivePagedListProvider<Int, KitsuItem>() {
override fun createDataSource(): KitsuLimitOffsetNetworkDataSource<KitsuItem> = dataSource
}
}
fun setQueryFilter(queryFilter: String) {
dataSource.queryFilter = queryFilter
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment