Our ViewModel for Kitsu Screen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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