android / codelab-android-paging

Jetpack Paging codelab
Apache License 2.0
495 stars 268 forks source link

monitor the refresh status doesn't work #140

Closed JichinX closed 3 months ago

JichinX commented 3 years ago

SearchRepositoriesActivity -> initAdapter:

//...
 adapter.addLoadStateListener { loadState ->
        // Only show the list if refresh succeeds.
        binding.list.isVisible = loadState.source.refresh is LoadState.NotLoading
        // Show loading spinner during initial load or refresh.
        binding.progressBar.isVisible = loadState.source.refresh is LoadState.Loading
        // Show the retry state if initial load or refresh fails.
        binding.retryButton.isVisible = loadState.source.refresh is LoadState.Error
//...

It is effective before using RemoteMediator. after using RemoteMediator,loadState.source.refresh is always NotLoading because Error or Loading is now changed within loadState.mediator so, I replace loadState.source.refresh with loadState.refresh and it works look good .

This is my personal opinion,Thanks

JichinX commented 3 years ago

before:

after changed:

florina-muntenescu commented 3 years ago

If you only show the list when loadState.refresh is LoadState.NotLoading then you have items in your database that are not actually displayed. For good user experience, you should be able to show items even if the device is offline.