Skip to content

Commit a081a7f

Browse files
committed
Handle final page
Change-Id: I7e3ca99bc9f682e7989a40155b7bbd3437b98559
1 parent 8bede03 commit a081a7f

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

app/src/main/java/com/firebase/uidemo/database/firestore/FirestorePagingActivity.java

+4
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ protected void onLoadingStateChanged(@NonNull LoadingState state) {
9999
case LOADED:
100100
mProgressBar.setVisibility(View.GONE);
101101
break;
102+
case FINISHED:
103+
mProgressBar.setVisibility(View.GONE);
104+
showToast("Reached end of data set,");
105+
break;
102106
case ERROR:
103107
showToast("An error occurred.");
104108
retry();

firestore/src/main/java/com/firebase/ui/firestore/paging/FirestoreDataSource.java

+7
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,13 @@ private abstract class OnLoadSuccessListener implements OnSuccessListener<QueryS
180180
public void onSuccess(QuerySnapshot snapshot) {
181181
setResult(snapshot);
182182
mLoadingState.postValue(LoadingState.LOADED);
183+
184+
// Post the 'FINISHED' state when no more pages will be loaded. The data source
185+
// callbacks interpret and empty result list as a signal to cancel any future loads
186+
if (snapshot.getDocuments().isEmpty()) {
187+
mLoadingState.postValue(LoadingState.FINISHED);
188+
}
189+
183190
mRetryRunnable = null;
184191
}
185192

firestore/src/main/java/com/firebase/ui/firestore/paging/LoadingState.java

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ public enum LoadingState {
1919
*/
2020
LOADED,
2121

22+
/**
23+
* The last page loaded had zero documents, and therefore no further pages will be loaded.
24+
*/
25+
FINISHED,
26+
2227
/**
2328
* The most recent load encountered an error.
2429
*/

0 commit comments

Comments
 (0)