Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void updatePlayerVoteCount(String whichHalf, String player_id, String player_name) {
- mVoteCountReference.child(whichHalf).child(NODE_PLAYER).child(player_id).addListenerForSingleValueEvent(new ValueEventListener() {
- @Override
- public void onDataChange(DataSnapshot dataSnapshot) {
- Vote playersVotes = null;
- if (dataSnapshot != null && dataSnapshot.exists()) {
- playersVotes = dataSnapshot.getValue(Vote.class);
- if (playersVotes != null && playersVotes.getVotes() > 0) {
- long votes = playersVotes.getVotes();
- votes++;
- playersVotes.setVotes(votes);
- } else {
- playersVotes = new Vote(1, player_id, player_name);
- }
- } else {
- playersVotes = new Vote(1, player_id, player_name);
- }
- mVoteCountReference.child(whichHalf).child(NODE_PLAYER).child(player_id).setValue(playersVotes);
- }
- @Override
- public void onCancelled(DatabaseError databaseError) {
- Log.e(TAG, "updatePlayerVoteCount() - error - " + databaseError.getMessage());
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement