From 8a8441c875441b4e635cf2d5200369871035f9ac Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Wed, 17 Apr 2019 18:20:53 +0200 Subject: [PATCH] Added failure callback to fingerprint dialog --- .../view/dialogs/FingerprintAuthDialog.java | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/view/dialogs/FingerprintAuthDialog.java b/app/src/main/java/com/topjohnwu/magisk/view/dialogs/FingerprintAuthDialog.java index d9f7642e2..eaf71b846 100644 --- a/app/src/main/java/com/topjohnwu/magisk/view/dialogs/FingerprintAuthDialog.java +++ b/app/src/main/java/com/topjohnwu/magisk/view/dialogs/FingerprintAuthDialog.java @@ -16,15 +16,18 @@ import com.topjohnwu.magisk.utils.FingerprintHelper; import com.topjohnwu.magisk.utils.Utils; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; @TargetApi(Build.VERSION_CODES.M) public class FingerprintAuthDialog extends CustomAlertDialog { - private Runnable callback; + private final Runnable callback; + @Nullable + private Runnable failureCallback; private DialogFingerprintHelper helper; - public FingerprintAuthDialog(@NonNull Activity activity, Runnable onSuccess) { + public FingerprintAuthDialog(@NonNull Activity activity, @NonNull Runnable onSuccess) { super(activity); callback = onSuccess; Drawable fingerprint = activity.getResources().getDrawable(R.drawable.ic_fingerprint); @@ -37,13 +40,28 @@ public class FingerprintAuthDialog extends CustomAlertDialog { vh.messageView.setCompoundDrawablePadding(Utils.dpInPx(20)); vh.messageView.setGravity(Gravity.CENTER); setMessage(R.string.auth_fingerprint); - setNegativeButton(R.string.close, (d, w) -> helper.cancel()); - setOnCancelListener(d -> helper.cancel()); + setNegativeButton(R.string.close, (d, w) -> { + helper.cancel(); + if (failureCallback != null) { + failureCallback.run(); + } + }); + setOnCancelListener(d -> { + helper.cancel(); + if (failureCallback != null) { + failureCallback.run(); + } + }); try { helper = new DialogFingerprintHelper(); } catch (Exception ignored) {} } + public FingerprintAuthDialog(@NonNull Activity activity, @NonNull Runnable onSuccess, @NonNull Runnable onFailure) { + this(activity, onSuccess); + failureCallback = onFailure; + } + @Override public AlertDialog show() { create();