I've implemented paging library with Room. I'm using Single Source of Truth. Articles (my data) will be fetched via Retrofit and will be inserted into Room database. Then recyclerview adapter listens for data via ArticleItemBoundaryCallback:
public class ArticleItemBoundaryCallback extends PagedList.BoundaryCallback<ArticleModel> {
ArticleRepository repository;
public ArticleItemBoundaryCallback(ArticleRepository repository) {
this.repository =repository;
}
@Override
public void onZeroItemsLoaded() {
super.onZeroItemsLoaded();
repository.getTenArticlesfromFirebaseAndRetrofit(1);
}
@Override
public void onItemAtEndLoaded(@NonNull ArticleModel itemAtEnd) {
super.onItemAtEndLoaded(itemAtEnd);
int page=0;
if (itemAtEnd.getPage() == 0) {
page = itemAtEnd.getPage() + 2;
} else {
page = itemAtEnd.getPage()+1;
}
repository.getTenArticlesfromFirebaseAndRetrofit(page);
}}
Repository decides if it needs to fetch data from internet or look for local cache (room database).
But my problem is that there is no loading indicator at the end of my recyclerview. Users may not be sure if they reached end of the list or loading. I saw this google code sample but i couldn't find where they added loading view at.
With the help of new Paging 3 library, you can present loading state as well as retry functionality at both start and end of the list.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With