I'm using paging library and room, making my room db as the single layer of truth of my app. when fetching is done from the server using retrofit, i save the result locally in the db then i get the data from the db using paging library. I'm using BoundaryCallback .
@Override
public void onZeroItemsLoaded() {
requestAndSaveData();
}
@Override
public void onItemAtEndLoaded(@NonNull Photo itemAtEnd) {
requestAndSaveData();
}
private void requestAndSaveData() {
if (isRequestInProgress) return;
isRequestInProgress = true;
apiInterface.getPhotos(lastRequestPage, NETWORK_PAGE_SIZE).enqueue(new Callback<PhotoList>() {
@Override
public void onResponse(Call<PhotoList> call, Response<PhotoList> response) {
if (response.isSuccessful()) {
cache.insertPhotos(response.body().getHits()); //todo only save 20 - 40 items
lastRequestPage++;
isRequestInProgress = false;
Log.i("deb", "number from boundary: " + response.body().getHits().size());
}
}
When there is no item in the db or the user scroll to the last item i call requestAndSaveData()
method that fetch the data from the server and save it into the db.
My question is how to show a progress bar at the bottom of the list while loading the next page from the server and saving it to the db as it may take a long time?