0

After reading firestore doccumentation and some article I found out this library 'android.arch.paging:runtime:1.0.0-alphal4-1' for pagination. it works good but now my problem is that i want to pass two queries in my pagination.

I tried some stuff but it doesn't not work.

That's my code :

Query query = firestore.collection(CallString.USER_BET)
            .whereEqualTo("id_user_one", firebaseAuth.getCurrentUser().getUid())
            .orderBy("time_player_one", Query.Direction.DESCENDING);

Query query1 = firestore.collection(CallString.USER_BET)
        .whereEqualTo("id_user_two", firebaseAuth.getCurrentUser().getUid())
        .orderBy("time_player_one", Query.Direction.DESCENDING);

I retrieve the two queries and i set it to task to merge the two query

Task t1 = query.get();
Task t2= query1.get();

Task combinedTask= Tasks.whenAllSuccess(t1,t2).addOnSuccessListener(new OnSuccessListener<List<Object>>() {
    @Override
    public void onSuccess(@NonNull List<Object> objects) {



        PagedList.Config config= new PagedList.Config.Builder()
                .setInitialLoadSizeHint(3)
                .setEnablePlaceholders(false)
                .setPageSize(3)
                .setPrefetchDistance(3)
                .build();

           

I set the object to setQuery(). I also try to convert the object back to query its seem to be impossible

FirestorePagingOptions<ModelBet> options1 =new FirestorePagingOptions.Builder<ModelBet>()
        .setQuery(objects, config, new SnapshotParser<ModelBet>() {
            @NonNull
            @Override
            public ModelBet parseSnapshot(@NonNull DocumentSnapshot snapshot) {
                ModelBet modelBet =snapshot.toObject(ModelBet.class);
                String itemId=snapshot.getId();
                modelBet.setId_post_bet(itemId);
                return modelBet;
            }
        }).setLifecycleOwner(getActivity()).build();

pagingAdapter=new FirestorePagingAdapter<ModelBet, ViewholderMyBet>(options1){

    @NonNull
    @Override
    public ViewholderMyBet onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view =LayoutInflater.from(parent.getContext()).inflate(R.layout.content_bet,parent,false);
        return new ViewholderMyBet(view);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewholderMyBet holder, int position, @NonNull ModelBet model) {

        RecyclerAdapterMyBet recyclerAdapterMyBet=new RecyclerAdapterMyBet();
        recyclerAdapterMyBet.actionAdapterMyBet(model,holder,pagingAdapter,getContext(),myActivity);
    }

    @Override
    protected void onLoadingStateChanged(@NonNull LoadingState state) {
        super.onLoadingStateChanged(state);

        switch (state) {

            case LOADED:
            case FINISHED:
                swipeRefreshLayout.setRefreshing(false);
                break;

            case LOADING_INITIAL:

            case LOADING_MORE:
                swipeRefreshLayout.setRefreshing(true);
                break;

            case ERROR:
                swipeRefreshLayout.setRefreshing(true);
                Toast.makeText(getContext(), "Oups! "+getString(R.string.oop_error_souvenue), Toast.LENGTH_LONG).show();
                break;
        }
    }

    @Override
    protected void onError(@NonNull Exception e) {
        super.onError(e);
    }
};

 LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
            

linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
            recyclerView.setLayoutManager(linearLayoutManager);
                recyclerView.setAdapter(pagingAdapter);
                recyclerView.setItemViewCacheSize(20);
                recyclerView.setDrawingCacheEnabled(true);
                recyclerView.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
                recyclerView.setHasFixedSize(true);
                swipeRefreshLayout.setRefreshing(true);
  • 1
    If you want to use the Paging v.3 library, then I think that this article, [How to paginate Firestore using Paging 3 on Android?](https://medium.com/firebase-tips-tricks/how-to-paginate-firestore-using-paging-3-on-android-c485acb0a2df) will help. If you understand Kotlin, and you want to know how Jetpack Compose works, this article, [How to implement pagination in Firestore using Jetpack Compose?](https://medium.com/firebase-tips-tricks/how-to-implement-pagination-in-firestore-using-jetpack-compose-76b4c0b5acd5) might also help. – Alex Mamo Feb 13 '22 at 09:41
  • Kotlin and me is like water and oil. But i will check it out. Thanks very much – freeday same Feb 13 '22 at 11:06

0 Answers0