1

If I use android paging library to paginate data from Firestore will the library include updates when items are deleted from Firestore. If document is deleted from firestore will it be deleted from RecyclerView? (Deletion of the document happens if user presses delete button on the view item in recyclerView)

Alen
  • 949
  • 3
  • 17
  • 37
  • If you want to paginate the results from Firestore and get updates in realtime, you can use my answer from the following **[post](https://stackoverflow.com/a/50742175/5246885)** but instead of using a `get() ` call you need to use `addSnapshotListener()`. – Alex Mamo Aug 21 '19 at 07:28
  • the only realtime feature I need is the ability to remove item from the recyclerView, user presses button, I delete the document from firestore, and it is removed from recyclerView, I would also be happy if there would be a way to remove item on button press independently of firestore document delete – Alen Aug 21 '19 at 10:38
  • That's the only you can achieve that ;) As explained in my answer from that post. – Alex Mamo Aug 21 '19 at 10:39
  • @AlexMamo I looked at your answer and managed to implement it in my app and it works great. Only thing I don't like is if I fetch 4 documents, next fetch will happen when I scroll to the bottom of the list (to the 4th item in recyclerView) and then there is like a pause while new 4 documents are fetched so there is not a flow while scrolling. How can I make it so that it starts fetching new 4 documents when I am at the 3rd item in recyclerView so just a little before end of the loaded items I start new fetch so new documents are ready when I am at the bottom of current recyclerView. – Alen Aug 22 '19 at 18:53
  • That's the most convenient way of solving the pagination problem. But here is another way of solving this, as seen in one of my [repos](https://github.com/alexmamo/FirebaseApp/blob/master/app/src/main/java/ro/alexmamo/firebaseapp/main/products/ProductsFragment.java) ;) You can take also a look at this [video](https://www.youtube.com/watch?v=esYPwbGW7YY). – Alex Mamo Aug 23 '19 at 09:25
  • Just gave you a vote up. Thanks again. – Alen Aug 23 '19 at 10:48

1 Answers1

1

Jetpack Paging does not support realtime updates from its underlying data source. Entire pages will be read into memory once, and it will not attempt to wire up any listeners to the underlying data.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • Is there any way to remove loaded items in recyclerView, not by listening to firestore changes. Like in normal recyclerView with List of data, you would call method to remove item from the list and notify recyclerView that data is changed? – Alen Aug 21 '19 at 10:34
  • The documentation suggests you could implement "swipe to refresh": https://developer.android.com/topic/libraries/architecture/paging/data#consider-content-updates – Doug Stevenson Aug 21 '19 at 13:35