0

I am using the below code, which working successfully using the filters. Now I just need to paginate my query before passing it to the adapter. I want to implement FirestorePagingAdapter, but not able to do so as the FirestorePagingOptions object had to be passed to the adapter, but the adapter type is not accepting it, as it is only accepting the Query object and have no idea if I can convert one type to another. Please help me out to paginate, either by using FirestorePagingOptions or some other way

I have commented the line where the pagination should be done.

I am using Firestore Database for the Android Project in RecyclerView With Filters option

public void onFilter(Filters filters) {
        // Construct query basic query
        Query query = mFirestore.collection("posts").orderBy("timestamp", Query.Direction.DESCENDING);

        // Category (equality filter)
        if (filters.hasCategory()) {
            query = query.whereEqualTo("postcategory", filters.getCategory());
        }


        // Limit items
      //  query = query.limit(7);

        // Update the query
        PostsRef = query;

        //Pagination


        adapter.setQuery(query);

        // Set header
        mCurrentSearchView.setText(Html.fromHtml(filters.getSearchDescription(getActivity().getApplicationContext())));

        // Save filters
        mViewModel.setFilters(filters);
    }
  • that guy is explaining pagination nicely https://youtu.be/HQgJvHXsNOQ – Abhinav Chauhan May 11 '20 at 05:59
  • @AbhinavChauhan I have checked this video already, it is using document snapshot to retrieve the data, but I can't do so, as I have to pass the query to the adapter as you can see in the above code to retrieve the data, I am trying to figure out to paginate the query to Pass it to the Adapter something similar to FirestorePagingOptions –  May 11 '20 at 06:08
  • i think to use firebasePaginOptions you have to use firestoreRecyclerAdapter please refer https://github.com/firebase/FirebaseUI-Android/tree/master/firestore/src/main/java/com/firebase/ui/firestore – Abhinav Chauhan May 11 '20 at 06:33
  • **[This](https://stackoverflow.com/questions/50741958/how-to-paginate-firestore-with-android)** is a recommended way in which you can paginate queries by combining query cursors with the limit() method. I also recommend you take a look at this **[video](https://www.youtube.com/watch?v=KdgKvLll07s)** for a better understanding. – Alex Mamo May 11 '20 at 07:56
  • @AlexMamo I have already gone through this recommendation of yours, but where the actual thing begins in your recommendation is here at "query.get().addOnCompleteListener(new OnCompleteListener()", but as you can in my above question I need to pass the query to the adapter which will retrieve the data, How I am supposed to do that? I can't change the adapter configuration as it working fine for the filtering feature in the application. One working thing can't be applied to everything, I hope you understand, my requirement is different as per your recommendation. Please Advise –  May 11 '20 at 08:34
  • @AlexMamo Hey, can you help me how to implement the your suggestion in context to my adapter? –  May 13 '20 at 00:17

0 Answers0