Created
March 12, 2017 08:47
-
-
Save anonymous/5a42cf6d79ec75f93680734ec5dcd264 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DatabaseReference countRef = databaseReference.child("users").child(uid); | |
countRef.runTransaction(new Transaction.Handler() { | |
@Override | |
public Transaction.Result doTransaction(MutableData mutableData) { | |
User u = mutableData.getValue(User.class); | |
if (u == null) { | |
Log.e("NULL","N"); | |
return Transaction.success(mutableData); | |
} | |
if (u.followers.containsKey(currentUser.getUid())) { | |
Log.e("complete","contains"); | |
u.follower_count = u.follower_count - 1; | |
u.followers.remove(currentUser.getUid()); | |
} else { | |
Log.e("complete","!contains"); | |
u.follower_count = u.follower_count + 1; | |
u.followers.put(currentUser.getUid(), true); | |
} | |
mutableData.setValue(u); | |
return Transaction.success(mutableData); | |
} | |
@Override | |
public void onComplete(DatabaseError databaseError, boolean b, | |
DataSnapshot dataSnapshot) { | |
// Transaction completed | |
Log.e("complete","casc"); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public String uid; | |
public String email; | |
public String name; | |
public String surname; | |
public String interests; | |
public String avatar_url; | |
public long following_count; | |
public long follower_count; | |
public Map<String, Boolean> followers = new HashMap<>(); | |
public Map<String, Boolean> following = new HashMap<>(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment