'Displaying the loading state in Fragment with Android paging 3 java

I am trying to use jetpack android's new paging 3 library, to implement paging in my application. A lot of documentation and examples is for kotlin, I am writing in java and I am having difficulty. In particular I would like to show a progress bar throughout the fagment view while the list of items is being loaded or updated.

I found this example from the official documentation, but I can't figure out how to implement it in java and in my case: https://developer.android.com/codelabs/android-paging#10

This way I am inserting an adapter to my recyclerview (an adapter is for adding the progress bar at the end of the recyclerview):

binding.recyclerView.setAdapter(
                // concat flyer adapter with header and footer loading view
                // This will show end user a progress bar while pages are being requested from server
                flyerAdapter.withLoadStateFooter(
                        // Pass footer load state adapter.
                        // When we will scroll down and next page request will be sent
                        // while we get response form server Progress bar will show to end user
                        // If request success Progress bar will hide and next page of movies
                        // will be shown to end user or if request will fail error message and
                        // retry button will be shown to resend the request
                        new FlyersLoadStateAdapter(v -> {
                            flyerAdapter.retry();
                        })));

What I try to do is also add a progressbar that hides the recyclerview when I download data from the network and populate the recyclerview or in cases of error. Any idea how to do this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source