Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying loading indicator with Paging Library

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.

like image 365
Teyyihan Aksu Avatar asked Nov 07 '22 09:11

Teyyihan Aksu


1 Answers

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.

like image 179
Teyyihan Aksu Avatar answered Nov 14 '22 21:11

Teyyihan Aksu