如何在FirebaseRecyclerAdapter中运行两个查询?

时间:2019-10-04 15:32:54

标签: android firebase android-recyclerview

这是我的第一个功能:

private void loadUserList() {

    Query query = FirebaseDatabase.getInstance().getReference().child(Commonx.USER_INFORMATION);
    FirebaseRecyclerOptions<User> options = new FirebaseRecyclerOptions.Builder<User>()
            .setQuery(query,User.class)
            .build();

    adapter = new FirebaseRecyclerAdapter<User, UserViewHolder>(options) {
        @Override
        protected void onBindViewHolder(@NonNull UserViewHolder userViewHolder, int i, @NonNull final User user) {
                if(user.getEmail().equals(Commonx.loggedUser.getEmail())){

                    userViewHolder.txt_user_email.setText(new StringBuilder(user.getEmail()).append(" (me)"));
                    userViewHolder.itemView.setClickable(false);
                    userViewHolder.txt_user_email.setTypeface(userViewHolder.txt_user_email.getTypeface(), Typeface.ITALIC);

                    if(user.getImage()!=null){
                        Picasso.get().load(Commonx.loggedUser.getImage()).into(userViewHolder.recycler_profile_image);}
                }

                else {



                    if(user.getImage()!=null){
                    Picasso.get().load(user.getImage()).into(userViewHolder.recycler_profile_image);}

                    userViewHolder.txt_user_email.setText(new StringBuilder(user.getEmail()));



                }

                userViewHolder.setiRecycItemListerner(new IRecycItemListerner() {
                    @Override
                    public void onItemClickListener(View view, int position) {

                        showDialogRequest(user);

                    }
                });





        }

        @NonNull
        @Override
        public UserViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

            View itemView = LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.layout_user,parent,false);

        return new UserViewHolder(itemView);
        }
    };
    adapter.startListening();
    recycler_all_user.setAdapter(adapter);
}

这是我的第二个功能:

 private void loadFriendList() {


    Query query = FirebaseDatabase.getInstance()
            .getReference(Commonx.USER_INFORMATION)
            .child(Commonx.loggedUser.getUid())
            .child(Commonx.ACCEPT_LIST);


    FirebaseRecyclerOptions<User> options = new FirebaseRecyclerOptions.Builder<User>()
            .setQuery(query, User.class)
            .build();

    adapter = new FirebaseRecyclerAdapter<User, UserViewHolder>(options) {
        @Override
        protected void onBindViewHolder(@NonNull final UserViewHolder userViewHolder, int i, @NonNull final User user) {
            userViewHolder.txt_user_email.setText(new StringBuilder(user.getEmail()));


            DatabaseReference lmao;


            //Picasso.get().load(Commonx.loggedUser.getImage()).into(userViewHolder.recycler_profile_image);



            userViewHolder.setiRecycItemListerner(new IRecycItemListerner() {
                @Override
                public void onItemClickListener(View view, int position) {

                    //show tracking information

                    Commonx.trackingUser = user;

                    startActivity(new Intent(HomeActivity.this, TrackingActivity.class));


                }
            });


        }


        @NonNull
        @Override
        public UserViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            View itemView = LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.layout_user, parent, false);

            return new UserViewHolder(itemView);
        }
    };


    adapter.startListening();
    recycler_friend_list.setAdapter(adapter);



}

在第一个功能中,我显示了所有用户,在第二个功能中,显示了用户的朋友。但是,我想运行第一个函数查询并通过第二个函数查询对其进行过滤。因为在我的Firebase数据库结构中,USER_INFORMATION包含图像,但朋友列表不包含图像。 最重要的是,我想同时运行两个查询,在第一个函数执行完之后,我想按第二个查询将其过滤掉。

0 个答案:

没有答案