I am working on app similar to LinkedIn and here I have some users already added to Firebase Database. Also every user can post or upload some content as well. Now am looking for a technique or code snippet that allows me to list the posts only to those who follow others. "For example: if am following you I'll be able to see your uploaded content in feeds or home screen". For listing out the posts am using Firebase Recycler Adapter and RecyclerView.

Below is my code for listing the posts:

@Override
public void onStart() {
    super.onStart();
    mAuth.addAuthStateListener(mAuthStateListener);

    FirebaseUser user = mAuth.getCurrentUser();

    final String userID = user.getUid();

    Query query = myRef;

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

    FBRA = new FirebaseRecyclerAdapter<PostInfo, PostViewHolder>(options) {
        @Override
        protected void onBindViewHolder(@NonNull final PostViewHolder holder, int position, @NonNull PostInfo model) {

                holder.setPostUser(model.getPostUser());

                holder.setPostImage(model.getPostImage(), getActivity());

                holder.setPostDesc(model.getPostDesc());

                holder.setPostLikes(model.getPostLikes());

                holder.likeBtn.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        holder.likeBtn.setImageResource(R.drawable.new_like_22);

                        holder.mLike.setTextColor(Color.parseColor("#1F7FB1"));

                    }
                });
        }

        @NonNull
        @Override
        public PostViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int i) {

            View view = LayoutInflater.from(getActivity()).inflate(R.layout.post_card, parent, false);

            return new PostViewHolder(view);

        }
    };

    mPostList.setAdapter(FBRA);

    FBRA.startListening();

}

Here are the Database screenshots:

Below is a user who has accepted my request which means I follow him now:

enter image description here

These are user posts:

enter image description here

I also thought of using orderByChild().equals("theFollower"), could not figured it out. How can achieve it? How only limited users i.e, only followers can see my posts?

Thanks a lot!

0 Answers