Created
September 17, 2017 11:59
-
-
Save brainail/8f61d99934664faf8ac2afef76b0ff07 to your computer and use it in GitHub Desktop.
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