Skip to content

Commit c749cf4

Browse files
committed
Finish retry piping
Change-Id: I6095b5df433c155c993100031b2633ee1670fb2d
1 parent 5391e97 commit c749cf4

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import android.support.annotation.NonNull;
1010
import android.support.annotation.Nullable;
1111
import android.support.v7.widget.RecyclerView;
12+
import android.util.Log;
1213

1314
import com.firebase.ui.firestore.SnapshotParser;
1415
import com.google.firebase.firestore.DocumentSnapshot;
@@ -22,6 +23,8 @@ public abstract class FirestorePagingAdapter<T, VH extends RecyclerView.ViewHold
2223
extends PagedListAdapter<DocumentSnapshot, VH>
2324
implements LifecycleObserver {
2425

26+
private static final String TAG = "FirestorePagingAdapter";
27+
2528
private final SnapshotParser<T> mParser;
2629
private final PagingData mData;
2730

@@ -60,6 +63,20 @@ public FirestorePagingAdapter(@NonNull FirestorePagingOptions<T> options) {
6063
}
6164
}
6265

66+
/**
67+
* If {@link #onLoadingStateChanged(LoadingState)} indicates error state, call this method
68+
* to attempt to retry the most recent failure.
69+
*/
70+
public void retry() {
71+
FirestoreDataSource source = mData.getDataSource().getValue();
72+
if (source == null) {
73+
Log.w(TAG, "Called retry() when FirestoreDataSource is null!");
74+
return;
75+
}
76+
77+
source.retry();
78+
}
79+
6380
@OnLifecycleEvent(Lifecycle.Event.ON_START)
6481
public void startListening() {
6582
mData.getSnapshots().observeForever(mDataObserver);

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class PagingData {
1717

1818
private final LiveData<PagedList<DocumentSnapshot>> mSnapshots;
1919
private final LiveData<LoadingState> mLoadingState;
20+
private final LiveData<FirestoreDataSource> mDataSource;
2021

2122
public PagingData(@NonNull LiveData<PagedList<DocumentSnapshot>> snapshots) {
2223
mSnapshots = snapshots;
@@ -29,6 +30,14 @@ public LiveData<LoadingState> apply(PagedList<DocumentSnapshot> input) {
2930
return dataSource.getLoadingState();
3031
}
3132
});
33+
34+
mDataSource = Transformations.map(mSnapshots,
35+
new Function<PagedList<DocumentSnapshot>, FirestoreDataSource>() {
36+
@Override
37+
public FirestoreDataSource apply(PagedList<DocumentSnapshot> input) {
38+
return (FirestoreDataSource) input.getDataSource();
39+
}
40+
});
3241
}
3342

3443
public LiveData<PagedList<DocumentSnapshot>> getSnapshots() {
@@ -39,4 +48,6 @@ public LiveData<LoadingState> getLoadingState() {
3948
return mLoadingState;
4049
}
4150

51+
public LiveData<FirestoreDataSource> getDataSource() { return mDataSource; }
52+
4253
}

0 commit comments

Comments
 (0)