Advertisement
Guest User

Untitled

a guest
May 25th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. private void updatePlayerVoteCount(String whichHalf, String player_id, String player_name) {
  2. mVoteCountReference.child(whichHalf).child(NODE_PLAYER).child(player_id).addListenerForSingleValueEvent(new ValueEventListener() {
  3. @Override
  4. public void onDataChange(DataSnapshot dataSnapshot) {
  5. Vote playersVotes = null;
  6. if (dataSnapshot != null && dataSnapshot.exists()) {
  7. playersVotes = dataSnapshot.getValue(Vote.class);
  8. if (playersVotes != null && playersVotes.getVotes() > 0) {
  9. long votes = playersVotes.getVotes();
  10. votes++;
  11. playersVotes.setVotes(votes);
  12. } else {
  13. playersVotes = new Vote(1, player_id, player_name);
  14. }
  15. } else {
  16. playersVotes = new Vote(1, player_id, player_name);
  17. }
  18. mVoteCountReference.child(whichHalf).child(NODE_PLAYER).child(player_id).setValue(playersVotes);
  19. }
  20.  
  21. @Override
  22. public void onCancelled(DatabaseError databaseError) {
  23. Log.e(TAG, "updatePlayerVoteCount() - error - " + databaseError.getMessage());
  24. }
  25. });
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement