Skip to content

Commit

Permalink
Dialogs: Don't show OK button at dialogs that require specific select…
Browse files Browse the repository at this point in the history
…ion, by @gsantner closes #1699, closes #1700

* Hide OK button at multiple dialogs
* Therefore fix crash by pressing OK button with undefined action
* Fix crash when pressing keyboard next in the same case where OK button is undefined
  • Loading branch information
gsantner committed May 21, 2022
1 parent 197490f commit b4ae32b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public static void showSpecialKeyDialog(Activity activity, Callback.a1<String> c
dopt.dialogHeightDp = 530;
dopt.titleText = R.string.special_key;
dopt.isSearchEnabled = false;
dopt.okButtonText = 0;
SearchOrCustomTextDialog.showMultiChoiceDialogWithSearchFilterUI(activity, dopt);
}

Expand All @@ -94,6 +95,7 @@ public static void showAttachSomethingDialog(final Activity activity, final Call
dopt.data = availableData;
dopt.iconsForData = availableDataToIconMap;
dopt.isSearchEnabled = false;
dopt.okButtonText = 0;
dopt.titleText = 0;
dopt.dialogWidthDp = WindowManager.LayoutParams.WRAP_CONTENT;
dopt.gravity = Gravity.BOTTOM | Gravity.END;
Expand Down Expand Up @@ -216,6 +218,7 @@ public static void showSttSortDialogue(Activity activity, final Callback.a2<Stri
dopt.dialogWidthDp = WindowManager.LayoutParams.WRAP_CONTENT;
dopt.dialogHeightDp = 530;
dopt.gravity = Gravity.BOTTOM | Gravity.END;
dopt.okButtonText = 0;

dopt.titleText = R.string.sort_tasks_by_selected_order;
dopt.messageText = "";
Expand Down Expand Up @@ -477,6 +480,7 @@ public static void showColorSelectionModeDialog(Activity activity, Callback.a1<I
dopt.data = new ArrayList<>(Arrays.asList(hexcode, fg, bg));
dopt.titleText = R.string.color;
dopt.isSearchEnabled = false;
dopt.okButtonText = 0;
dopt.messageText = activity.getString(R.string.set_foreground_or_background_color_hexcolor_also_possible);
SearchOrCustomTextDialog.showMultiChoiceDialogWithSearchFilterUI(activity, dopt);
}
Expand Down Expand Up @@ -591,6 +595,7 @@ public static void showPriorityDialog(Activity activity, char selectedPriority,
dopt.data = availableData;
dopt.highlightData = highlightedData;
dopt.titleText = R.string.priority;
dopt.okButtonText = 0;
dopt.messageText = "";
dopt.isSearchEnabled = false;
dopt.dialogWidthDp = WindowManager.LayoutParams.WRAP_CONTENT;
Expand Down Expand Up @@ -669,6 +674,7 @@ public static void showInsertSnippetDialog(final Activity activity, final Callba
dopt.data = data;
dopt.isSearchEnabled = true;
dopt.titleText = R.string.insert_snippet;
dopt.okButtonText = 0;
dopt.messageText = Html.fromHtml("<small><small>" + folder.getAbsolutePath() + "</small></small>");
dopt.callback = (key) -> callback.callback(FileUtils.readTextFileFast(texts.get(key)).first);
SearchOrCustomTextDialog.showMultiChoiceDialogWithSearchFilterUI(activity, dopt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public static void showMultiChoiceDialogWithSearchFilterUI(final Activity activi
// =========================================================================================

// Ok button action
if ((dopt.callback != null) || (dopt.isMultiSelectEnabled)) {
if (((dopt.callback != null) || (dopt.isMultiSelectEnabled)) && dopt.okButtonText != 0) {
dialogBuilder.setPositiveButton(dopt.okButtonText, (dialogInterface, i) -> {
final String searchText = dopt.isSearchEnabled ? searchEditText.getText().toString() : null;
if (dopt.positionCallback != null && !listAdapter._selectedItems.isEmpty()) {
Expand All @@ -284,7 +284,7 @@ public static void showMultiChoiceDialogWithSearchFilterUI(final Activity activi
final AlertDialog dialog = dialogBuilder.create();

searchEditText.setOnKeyListener((keyView, keyCode, keyEvent) -> {
if ((keyEvent.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
if ((keyEvent.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER) && dopt.okButtonText != 0) {
dialog.dismiss();
if (dopt.callback != null && !TextUtils.isEmpty(searchEditText.getText().toString())) {
dopt.callback.callback(searchEditText.getText().toString());
Expand Down

0 comments on commit b4ae32b

Please sign in to comment.