-
-
Save CristianMG/72b7fb445e4f32ca175d14065f30a402 to your computer and use it in GitHub Desktop.
Android paging Network + Database 6 snippet
This file contains hidden or 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 MainViewModel( | |
| private val characterRepository: CharacterRepository | |
| ) : ViewModel() { | |
| private val listing: LiveData<Listing<CharacterModel>> by lazy { | |
| liveData(characterRepository.getListable()) | |
| } | |
| private val boundaryCallback = switchMap(listing) { it.getBoundaryCallback() }!! | |
| val dataSource = switchMap(listing) { it.getDataSource() }!! | |
| val networkState = switchMap(listing) { it.getNetworkState() }!! | |
| /** | |
| * Retry all failed petitions boundary callback | |
| */ | |
| fun retry() { | |
| boundaryCallback.value?.retryPetitions() | |
| } | |
| /** | |
| * Cleared all references and petitions boundary callback | |
| */ | |
| override fun onCleared() { | |
| boundaryCallback.value?.cleared() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment