Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Our ViewModel for Kitsu Screen
class KitsuViewModel(app: Application) : AndroidViewModel(app) {
private var allKitsuLiveData: LiveData<PagedList<KitsuItem>>? = null
val allKitsu: LiveData<PagedList<KitsuItem>>
get() {
if (null == allKitsuLiveData) {
allKitsuLiveData = KitsuMediaPagedListProvider.allKitsu().create(0,
PagedList.Config.Builder()
.setPageSize(PAGED_LIST_PAGE_SIZE)
.setInitialLoadSizeHint(PAGED_LIST_PAGE_SIZE)
.setEnablePlaceholders(PAGED_LIST_ENABLE_PLACEHOLDERS)
.build())!!
}
return allKitsuLiveData ?: throw AssertionError("Check your threads ...")
}
fun setQueryFilter(queryFilter: String) {
KitsuMediaPagedListProvider.setQueryFilter(queryFilter)
allKitsuLiveData = null // invalidate
}
companion object {
private const val PAGED_LIST_PAGE_SIZE = 20
private const val PAGED_LIST_ENABLE_PLACEHOLDERS = false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment