From c86cfb11bbcc28543d079a15634d73b398e79a49 Mon Sep 17 00:00:00 2001 From: jcesarmobile Date: Thu, 30 Apr 2020 20:18:55 +0200 Subject: [PATCH] fix(android): call error on prompt cancel (#2855) --- .../src/main/java/com/getcapacitor/Dialogs.java | 7 ++++++- .../main/java/com/getcapacitor/plugin/Camera.java | 5 +++++ .../ui/ModalsBottomSheetDialogFragment.java | 14 ++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/android/capacitor/src/main/java/com/getcapacitor/Dialogs.java b/android/capacitor/src/main/java/com/getcapacitor/Dialogs.java index 273f19223..c2eae58a5 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/Dialogs.java +++ b/android/capacitor/src/main/java/com/getcapacitor/Dialogs.java @@ -26,6 +26,10 @@ public interface OnSelectListener { void onSelect(int index); } + public interface OnCancelListener { + void onCancel(); + } + /** * Show a simple alert with a message and default values for * title and ok button @@ -197,7 +201,7 @@ public void onCancel(DialogInterface dialog) { public static void actions(final AppCompatActivity activity, final Object[] options, - final Dialogs.OnSelectListener listener) { + final Dialogs.OnSelectListener listener, final Dialogs.OnCancelListener cancelListener) { JSArray optionsArray; try { @@ -215,6 +219,7 @@ public void onSelected(int index) { fragment.dismiss(); } }); + fragment.setOnCancelListener(cancelListener); fragment.show(activity.getSupportFragmentManager(), "capacitorModalsActionSheet"); } } diff --git a/android/capacitor/src/main/java/com/getcapacitor/plugin/Camera.java b/android/capacitor/src/main/java/com/getcapacitor/plugin/Camera.java index cbe2926f3..eb75d1502 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/plugin/Camera.java +++ b/android/capacitor/src/main/java/com/getcapacitor/plugin/Camera.java @@ -125,6 +125,11 @@ public void onSelect(int index) { openCamera(call); } } + }, new Dialogs.OnCancelListener() { + @Override + public void onCancel() { + call.error("User cancelled photos app"); + } }); } diff --git a/android/capacitor/src/main/java/com/getcapacitor/ui/ModalsBottomSheetDialogFragment.java b/android/capacitor/src/main/java/com/getcapacitor/ui/ModalsBottomSheetDialogFragment.java index 15bb23303..32e0aeaa4 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/ui/ModalsBottomSheetDialogFragment.java +++ b/android/capacitor/src/main/java/com/getcapacitor/ui/ModalsBottomSheetDialogFragment.java @@ -2,6 +2,7 @@ import android.annotation.SuppressLint; import android.app.Dialog; +import android.content.DialogInterface; import android.graphics.Color; import android.util.Log; import android.view.View; @@ -12,6 +13,7 @@ import androidx.annotation.NonNull; import androidx.coordinatorlayout.widget.CoordinatorLayout; +import com.getcapacitor.Dialogs; import com.getcapacitor.JSArray; import com.getcapacitor.JSObject; import com.getcapacitor.LogUtils; @@ -28,10 +30,18 @@ public interface OnSelectedListener { void onSelected(int index); } + @Override + public void onCancel(DialogInterface dialog) + { + super.onCancel(dialog); + this.cancelListener.onCancel(); + } + private String title; private JSArray options; private OnSelectedListener listener; + private Dialogs.OnCancelListener cancelListener; public void setTitle(String title) { this.title = title; @@ -44,6 +54,10 @@ public void setOnSelectedListener(OnSelectedListener listener) { this.listener = listener; } + public void setOnCancelListener(Dialogs.OnCancelListener listener) { + this.cancelListener = listener; + } + private BottomSheetBehavior.BottomSheetCallback mBottomSheetBehaviorCallback = new BottomSheetBehavior.BottomSheetCallback() { @Override