Skip to content

Commit

Permalink
fix(android): call error on prompt cancel (#2855)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored Apr 30, 2020
1 parent 0c09fc8 commit c86cfb1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -215,6 +219,7 @@ public void onSelected(int index) {
fragment.dismiss();
}
});
fragment.setOnCancelListener(cancelListener);
fragment.show(activity.getSupportFragmentManager(), "capacitorModalsActionSheet");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ public void onSelect(int index) {
openCamera(call);
}
}
}, new Dialogs.OnCancelListener() {
@Override
public void onCancel() {
call.error("User cancelled photos app");
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit c86cfb1

Please sign in to comment.