Last active
May 11, 2017 08:50
-
-
Save yongjhih/138a166473c7635367faba5821e61bc2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
@NonNull | |
@CheckReturnValue | |
public static Maybe<Boolean> confirm( | |
@NonNull final AlertDialog.Builder builder, | |
@StringRes final int positiveTitleRes, | |
@StringRes final int negativeTitleRes | |
) { | |
return Maybe.create(new MaybeOnSubscribe<Boolean>() { | |
@Override | |
public void subscribe(@NonNull final MaybeEmitter<Boolean> emitter) throws Exception { | |
builder.setPositiveButton(positiveTitleRes, new DialogInterface.OnClickListener() { | |
@Override | |
public void onClick(DialogInterface dialog, int which) { | |
if (!emitter.isDisposed()) emitter.onSuccess(true); | |
} | |
}) | |
.setNegativeButton(negativeTitleRes, new DialogInterface.OnClickListener() { | |
@Override | |
public void onClick(DialogInterface dialog, int which) { | |
if (!emitter.isDisposed()) emitter.onSuccess(false); | |
} | |
}) | |
.setOnCancelListener(new DialogInterface.OnCancelListener() { | |
@Override | |
public void onCancel(DialogInterface dialog) { | |
if (!emitter.isDisposed()) emitter.onComplete(); | |
} | |
}); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment