Created
September 21, 2021 06:56
-
-
Save Kashif-E/8f2e1aa23281b7c4ddd95baedc9b9290 to your computer and use it in GitHub Desktop.
load state listener for paging
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
/* | |
* Progress Updater | |
* */ | |
adapter.addLoadStateListener { loadState -> | |
if (loadState.refresh is LoadState.Loading || | |
loadState.append is LoadState.Loading) | |
// Show ProgressBar | |
else { | |
// Hide ProgressBar | |
// If we have an error, show a toast | |
val errorState = when { | |
loadState.append is LoadState.Error -> loadState.append as LoadState.Error | |
loadState.prepend is LoadState.Error -> loadState.prepend as LoadState.Error | |
loadState.refresh is LoadState.Error -> loadState.refresh as LoadState.Error | |
else -> null | |
} | |
errorState?.let { | |
Toast.makeText(this, it.error.toString(), Toast.LENGTH_LONG).show() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment