Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Firestore paging adapter #1178

Merged
Merged
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
5109b4c
Super basic infinite scroll
samtstern Feb 21, 2018
cbaaca7
Make it kinda actually work
samtstern Mar 1, 2018
8e08336
Actual bidirectional unloading
samtstern Mar 1, 2018
75240b7
Some cleanup
samtstern Mar 1, 2018
4d68a56
Separate demo
samtstern Mar 1, 2018
6af779c
Some cleanup
samtstern Mar 1, 2018
2a5f554
Make lint pass
samtstern Mar 2, 2018
51c0d95
Basic JavaDoc
samtstern Mar 2, 2018
09f6a6d
Break out Page
samtstern Mar 2, 2018
a7153be
Space before a semicolon? That's a paddlin
samtstern Mar 2, 2018
11668e2
Experimenting with the support Paging Library, comitting just for safety
samtstern Mar 19, 2018
db39ddf
Move to alpha6, remove home-grown bits
samtstern Mar 19, 2018
efc0095
Real adapter and options classes
samtstern Mar 19, 2018
45901b7
Delete Page
samtstern Mar 19, 2018
4a684f3
Merge branch 'version-3.3.1-dev' into firestore-infinite-scroll
samtstern Mar 29, 2018
754f945
alpha7 update
samtstern Mar 29, 2018
1ea8834
Expose Loading State
samtstern Mar 29, 2018
eddcbed
Reduce complexity of factory
samtstern Apr 2, 2018
276f677
Make build pass
samtstern Apr 2, 2018
ea8144c
Address nits
samtstern Apr 4, 2018
75e206a
Paging library went to beta
samtstern Apr 11, 2018
cef8528
More feedback
samtstern Apr 11, 2018
154ecde
Move diff callback to options
samtstern Apr 11, 2018
5391e97
Add retry() in the data source
samtstern Apr 11, 2018
c749cf4
Finish retry piping
samtstern Apr 12, 2018
877fb21
Address review feedback
samtstern Apr 13, 2018
202857d
Add some tests
samtstern Apr 13, 2018
85967cb
Add documentation
samtstern Apr 13, 2018
e199385
Merge branch 'version-3.3.1-dev' into firestore-infinite-scroll
samtstern Apr 13, 2018
bf0ac33
Build fix
samtstern Apr 13, 2018
8bede03
Doc updates (review feedback)
samtstern Apr 16, 2018
a081a7f
Handle final page
samtstern Apr 16, 2018
fb64181
Fix typo
samtstern Apr 16, 2018
00a4818
Merge branch 'version-3.4.0-dev' into firestore-infinite-scroll
samtstern Apr 16, 2018
1e02f0e
Typo fixes
samtstern Apr 16, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Doc updates (review feedback)
Change-Id: Iae9801e965664f987e892968df362186b7c9a8f2
  • Loading branch information
samtstern committed Apr 16, 2018
commit 8bede0363414d6f7bc9c5db6b8cf97633475fa8b
20 changes: 11 additions & 9 deletions firestore/README.md
Original file line number Diff line number Diff line change
@@ -118,10 +118,10 @@ Fear not, FirebaseUI does all of this for you automatically!

FirebaseUI offers two types of RecyclerView adapters for Cloud Firestore:

* `FirestoreRecyclerAdapter` - bind a `Query` to a `RecyclerView` and respond to all real-time
* `FirestoreRecyclerAdapter` — binds a `Query` to a `RecyclerView` and respond to all real-time
events included items being added, removed, moved, or changed. Best used with small result sets
since all results are loaded at once.
* `FirestorePagingAdapter` - bind a `Query` to a `RecyclerView` by loading data in pages. Best
* `FirestorePagingAdapter` — binds a `Query` to a `RecyclerView` by loading data in pages. Best
used with large, static data sets. Real-time events are not respected by this adapter, so it
will not detect new/removed items or changes to items already loaded.

@@ -177,7 +177,7 @@ FirestoreRecyclerAdapter adapter = new FirestoreRecyclerAdapter<Chat, ChatHolder
};
```

Finally attach the adapter to your `RecyclerView` with the `RecyclerView#setAdapter()`.
Finally attach the adapter to your `RecyclerView` with the `RecyclerView#setAdapter()` method.
Don't forget to also set a `LayoutManager`!

#### `FirestoreRecyclerAdapter` lifecycle
@@ -253,7 +253,7 @@ The `FirestorePagingAdapter` is built on top of the [Android Paging Support Libr
Before using the adapter in your application, you must add a dependency on the support library:

```groovy
implementation 'android.arch.paging:runtime:1.0.0-beta1'
implementation 'android.arch.paging:runtime:1.x.x'
```

First, configure the adapter by building `FirestorePagingOptions`. Since the paging adapter
@@ -293,7 +293,7 @@ If you need to customize how your model class is parsed, you can use a custom `S
});
```

Next create the `FirestorePagingAdapter` object. You should already have a `ViewHolder` subclass
Next, create the `FirestorePagingAdapter` object. You should already have a `ViewHolder` subclass
for displaying each item. In this case we will use a custom `ItemViewHolder` class:

```java
@@ -303,7 +303,7 @@ FirestorePagingAdapter<Item, ItemViewHolder> adapter =
@Override
public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
// Create the ItemViewHolder
// ,,,
// ...
}

@Override
@@ -316,7 +316,7 @@ FirestorePagingAdapter<Item, ItemViewHolder> adapter =
};
```

Finally attach the adapter to your `RecyclerView` with the `RecyclerView#setAdapter()`.
Finally attach the adapter to your `RecyclerView` with the `RecyclerView#setAdapter()` method.
Don't forget to also set a `LayoutManager`!

#### `FirestorePagingAdapter` lifecycle
@@ -338,7 +338,9 @@ protected void onStart() {
}
```

Similarly, the `stopListening()` call removes the snapshot listener and all data in the adapter.
Similarly, the `stopListening()` call freezes the data in the `RecyclerView` and prevents any future
loading of data pages.

Call this method when the containing Activity or Fragment stops:

```java
@@ -359,7 +361,7 @@ start and stop listening in `onStart()` and `onStop()`.

#### Paging events

When using the `FirestorePagingAdapter` you may want to perform some action every time data
When using the `FirestorePagingAdapter`, you may want to perform some action every time data
changes or when there is an error. To do this, override the `onLoadingStateChanged()`
method of the adapter:

Original file line number Diff line number Diff line change
@@ -114,7 +114,8 @@ public void startListening() {
}

/**
* Unsubscribe from paging / scrolling events, no more data will be populated.
* Unsubscribe from paging / scrolling events, no more data will be populated, but the existing
* data will remain.
*/
@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
public void stopListening() {