Skip to content

Instantly share code, notes, and snippets.

@SukantPal SukantPal/Matcher.java
Last active Feb 10, 2019

Embed
What would you like to do?
protected class Matcher implements Transaction.Handler {
private Challenge mSelectedChallenge = null;
private final OnFailCallback mFailCallback;
protected Matcher(@Nullable OnFailCallback failCallback) {
mFailCallback = failCallback;
}
@NonNull
@Override
public Transaction.Result doTransaction(@NonNull MutableData mutableData) {
for (MutableData challengeData : mutableData.getChildren()) {
final Challenge postedChallenge = challengeData.getValue(Challenge.class);
if (isChallengeCompat(postedChallenge)) {
mSelectedChallenge = postedChallenge;
challengeData.setValue(null);
return Transaction.success(mutableData);
}
}
Log.d("MatchMaker.Matcher", "Didn't find any matching challenge");
return Transaction.success(mutableData);
}
@Override
public void onComplete(@Nullable DatabaseError databaseError,
boolean b, @Nullable DataSnapshot dataSnapshot) {
if (mSelectedChallenge != null) {
mOpener = mSelectedChallenge.opener;
mGamePath = mSelectedChallenge.gameRef;
Log.d("MatchMaker.Matcher", "Found match, onComplete");
onMatchFound(false);
} else if (mFailCallback != null) {
mFailCallback.onFail();
}
}
}
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.