I'm confused here and really at the end on the line, I have set up a like function in my project. if a user presses the like button once, the like counter update from 0 to 1(liked) and the like imageButton(change color) updates successful. if pressed twice the counter updates from 1 to 0(unlike) successful.
The problem is when a different user also press the like button to like the same post, the like counter does not update from 1 to 2. Please help. I hope this is clear. Below is the code.
viewHolder.mLikebtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mProcessLike = true; mDatabaseLikeCount = FirebaseDatabase.getInstance().getReference().child("Notes").child(post_key).child("likecount"); mDatabaseLikeCount.keepSynced(true); mDatabaseLike.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { if (mProcessLike) { if (dataSnapshot.child(post_key).hasChild(auth.getCurrentUser().getUid())) { Log.i("D Diary", "User has already Liked. So it can be considered as Unliked."); mDatabaseLike.child(post_key).child(auth.getCurrentUser().getUid()).removeValue(); mDatabaseLikeCount.setValue(likeCount = likeCount - 1 ); mProcessLike = false; } else { Log.i("D Diary", "User Liked"); mDatabaseLike.child(post_key).child(auth.getCurrentUser().getUid()).setValue(auth.getCurrentUser().getDisplayName()); mDatabaseLikeCount.setValue(likeCount = likeCount + 1 ); Log.i(dataSnapshot.getKey(), dataSnapshot.getChildrenCount() + "Count"); mProcessLike = false; } } } @Override public void onCancelled(DatabaseError databaseError) { } }); } });