Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
protected class SelfChallengeManager implements Transaction.Handler, ValueEventListener {
protected final Challenge mUploadedChallenge;
protected DatabaseReference mChallengeRef;
protected DatabaseReference mGameRecordRef;
protected SelfChallengeManager() {
mUploadedChallenge = new Challenge(
FirebaseAuth.getInstance().getCurrentUser().getUid(), null);
}
@NonNull
@Override
public Transaction.Result doTransaction(@NonNull MutableData mutableData) {
mGameRecordRef = FirebaseDatabase.getInstance().getReference()
.child(GAMES_RECORD)
.push();
mUploadedChallenge.gameRef =
GAMES_RECORD + "/" + mGameRecordRef.getKey();
mGamePath = mUploadedChallenge.gameRef;
mChallengeRef = mUserRoomRef.push();
mChallengeRef.setValue(mUploadedChallenge);
mChallengeRef.addValueEventListener(this);
return Transaction.success(mutableData);
}
@Override
public void onComplete(@Nullable DatabaseError databaseError, boolean b,
@Nullable DataSnapshot dataSnapshot) {
Log.d("MatchMaker", "Published player challenge");
}
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if (dataSnapshot.getValue() == null) {
mChallengeRef = null;
mGameRecordRef = null;
mSelfChallengeManager = null;
onMatchFound(true);
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Log.d("MatchMaker", "Cancelled: " + databaseError.getMessage());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.