Instantly share code, notes, and snippets.

Embed
What would you like to do?
protected class SelfChallengeCanceller implements Transaction.Handler {
private final SelfChallengeManager mChallenger;
private SelfChallengeCanceller(SelfChallengeManager challenger) {
Log.d("MatchMaker.Cancel", "Opened cancel request");
mChallenger = challenger;
}
@NonNull
@Override
public Transaction.Result doTransaction(@NonNull MutableData mutableData) {
mChallenger.mChallengeRef.removeEventListener(mChallenger);
final String challengeKey = mChallenger.mChallengeRef.getKey();
for (MutableData challengeNode : mutableData.getChildren()) {
if (challengeNode.getKey().contentEquals(challengeKey)) {
challengeNode.setValue(null);
}
}
return Transaction.success(mutableData);
}
@Override
public void onComplete(@Nullable DatabaseError databaseError, boolean b,
@Nullable DataSnapshot dataSnapshot) {
mChallenger.mChallengeRef = null;
final DatabaseReference gameRecordRef = mChallenger.mGameRecordRef;
if (gameRecordRef != null) {
gameRecordRef.setValue(null);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment