Skip to content

Commit

Permalink
Merge pull request #63 from cyclexuxu/likecounter
Browse files Browse the repository at this point in the history
two db conflicts
  • Loading branch information
cyclexuxu authored Dec 8, 2020
2 parents 02aee21 + 42fc556 commit 5f5054c
Showing 1 changed file with 33 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,30 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int positi
viewHolderClass.ibLike.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
viewHolderClass.ibLike.setImageResource(R.drawable.ic_action_like);
Log.d(TAG, "Click the heart!");
Log.d(TAG, "Click the heart! Friend is " + friend);
textClick = true;
//viewHolderClass.ibLike.setImageResource(R.drawable.ic_action_like);
likeRef.child("likeClicked").setValue(true);
final String today = new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime());


itemRank.setLikesReceived(itemRank.getLikesReceived() + 1);

//viewHolderClass.ibLike.setImageResource(R.drawable.ic_action_like);


users.child(itemRank.getUsername()).child("Likes").child(today).setValue(itemRank.getLikesReceived());

likeRef.child("likesReceived").setValue(itemRank.getLikesReceived());
likeRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
if(textClick) {
viewHolderClass.ibLike.setImageResource(R.drawable.ic_action_like);
Log.d(TAG, "Click the heart!");
Log.d(TAG, "Click the heart! Friend is " + friend);
//viewHolderClass.ibLike.setImageResource(R.drawable.ic_action_like);
likeRef.child("likeClicked").setValue(true);
final String today = new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime());
itemRank.setLikesReceived(itemRank.getLikesReceived() + 1);
//viewHolderClass.ibLike.setImageResource(R.drawable.ic_action_like);
// users.child(itemRank.getUsername()).child("Likes").child(today).setValue(itemRank.getLikesReceived());
likeRef.child("likesReceived").setValue(itemRank.getLikesReceived());
textClick = false;
}
}

@Override
public void onCancelled(@NonNull DatabaseError error) {

}
});

}
});
Expand Down Expand Up @@ -111,7 +118,16 @@ public void checkLikeStatus(ItemRank itemRank) {
isClickedRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {

Boolean isLikedClicked = (Boolean) snapshot.getValue();
if (isLikedClicked) {
ibLike.setImageResource(R.drawable.ic_action_like);
tvLikes.setText(String.valueOf(itemRank.getLikesReceived()));
// isClickedRef.child(String.valueOf(itemRank.getRankId())).child("likesReceived").setValue(itemRank.getLikesReceived());
// isClickedRef.child(String.valueOf(itemRank.getRankId())).child("likeClicked").setValue(true);
} else {
ibLike.setImageResource(R.drawable.ic_action_dislike);
}
// Log.d(LOG, String.valueOf(isLikedClicked) + "~~~~~~~~~~~~~~");
}

@Override
Expand Down

0 comments on commit 5f5054c

Please sign in to comment.