From e1885f84ec6b7a273eb79e14215f7f2b31f894c2 Mon Sep 17 00:00:00 2001 From: parneet-guraya Date: Wed, 25 Dec 2024 20:35:56 +0530 Subject: [PATCH] add cancel button Signed-off-by: parneet-guraya --- .../helper/FolderDeletionHelper.kt | 1 + .../ui/selector/CustomSelectorActivity.kt | 2 ++ .../RecentSearchesFragment.java | 2 ++ .../nrw/commons/feedback/FeedbackDialog.kt | 1 + .../media/MediaDetailPagerFragment.java | 1 + .../commons/navtab/MoreBottomSheetFragment.kt | 5 ++- .../MoreBottomSheetLoggedOutFragment.kt | 1 + .../fragments/CommonPlaceClickActions.kt | 2 ++ .../fragments/NearbyParentFragment.java | 2 ++ .../fr/free/nrw/commons/quiz/QuizActivity.kt | 1 + .../nrw/commons/settings/SettingsFragment.kt | 15 +++----- .../nrw/commons/upload/UploadActivity.java | 1 + .../upload/UploadMediaDetailAdapter.java | 4 +++ .../commons/upload/depicts/DepictsFragment.kt | 1 + app/src/main/res/layout/dialog_feedback.xml | 35 ++++++++++++++----- .../res/layout/dialog_select_language.xml | 17 ++++++--- 16 files changed, 67 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/customselector/helper/FolderDeletionHelper.kt b/app/src/main/java/fr/free/nrw/commons/customselector/helper/FolderDeletionHelper.kt index 39454c68d5..9a949b1cf3 100644 --- a/app/src/main/java/fr/free/nrw/commons/customselector/helper/FolderDeletionHelper.kt +++ b/app/src/main/java/fr/free/nrw/commons/customselector/helper/FolderDeletionHelper.kt @@ -42,6 +42,7 @@ object FolderDeletionHelper { AlertDialog.Builder(context) .setTitle(context.getString(R.string.custom_selector_confirm_deletion_title)) + .setCancelable(false) .setMessage( context.getString( R.string.custom_selector_confirm_deletion_message, diff --git a/app/src/main/java/fr/free/nrw/commons/customselector/ui/selector/CustomSelectorActivity.kt b/app/src/main/java/fr/free/nrw/commons/customselector/ui/selector/CustomSelectorActivity.kt index d6be68ff15..52b615175e 100644 --- a/app/src/main/java/fr/free/nrw/commons/customselector/ui/selector/CustomSelectorActivity.kt +++ b/app/src/main/java/fr/free/nrw/commons/customselector/ui/selector/CustomSelectorActivity.kt @@ -268,6 +268,7 @@ class CustomSelectorActivity : */ private fun showWelcomeDialog() { val dialog = Dialog(this) + dialog.setCancelable(false) dialog.requestWindowFeature(Window.FEATURE_NO_TITLE) dialog.setContentView(R.layout.custom_selector_info_dialog) (dialog.findViewById(R.id.btn_ok) as Button).setOnClickListener { dialog.dismiss() } @@ -683,6 +684,7 @@ class CustomSelectorActivity : */ private fun displayUploadLimitWarning() { val dialog = Dialog(this) + dialog.setCancelable(false) dialog.requestWindowFeature(Window.FEATURE_NO_TITLE) dialog.setContentView(R.layout.custom_selector_limit_dialog) (dialog.findViewById(R.id.btn_dismiss_limit_warning) as Button).setOnClickListener { dialog.dismiss() } diff --git a/app/src/main/java/fr/free/nrw/commons/explore/recentsearches/RecentSearchesFragment.java b/app/src/main/java/fr/free/nrw/commons/explore/recentsearches/RecentSearchesFragment.java index 0db1e55395..588f3a25fd 100644 --- a/app/src/main/java/fr/free/nrw/commons/explore/recentsearches/RecentSearchesFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/explore/recentsearches/RecentSearchesFragment.java @@ -67,6 +67,7 @@ private void showDeleteRecentAlertDialog(@NonNull final Context context) { .setPositiveButton(android.R.string.yes, (dialog, which) -> setDeleteRecentPositiveButton(context, dialog)) .setNegativeButton(android.R.string.no, null) + .setCancelable(false) .create() .show(); } @@ -94,6 +95,7 @@ private void showDeleteAlertDialog(@NonNull final Context context, final int pos .setPositiveButton(getString(R.string.delete).toUpperCase(Locale.ROOT), ((dialog, which) -> setDeletePositiveButton(context, dialog, position))) .setNegativeButton(android.R.string.cancel, null) + .setCancelable(false) .create() .show(); } diff --git a/app/src/main/java/fr/free/nrw/commons/feedback/FeedbackDialog.kt b/app/src/main/java/fr/free/nrw/commons/feedback/FeedbackDialog.kt index e3e3bf9587..6d68fb66db 100644 --- a/app/src/main/java/fr/free/nrw/commons/feedback/FeedbackDialog.kt +++ b/app/src/main/java/fr/free/nrw/commons/feedback/FeedbackDialog.kt @@ -46,6 +46,7 @@ class FeedbackDialog( // 'SOFT_INPUT_ADJUST_RESIZE: Int' is deprecated. Deprecated in Java @Suppress("DEPRECATION") window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) + binding.btnCancel.setOnClickListener { dismiss() } binding.btnSubmitFeedback.setOnClickListener { try { submitFeedback() diff --git a/app/src/main/java/fr/free/nrw/commons/media/MediaDetailPagerFragment.java b/app/src/main/java/fr/free/nrw/commons/media/MediaDetailPagerFragment.java index 0de29a3bff..545e96624e 100644 --- a/app/src/main/java/fr/free/nrw/commons/media/MediaDetailPagerFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/media/MediaDetailPagerFragment.java @@ -291,6 +291,7 @@ private void showReportDialog(final Media media) { builder.setItems(R.array.report_violation_options, (dialog, which) -> { sendReportEmail(media, values[which]); }); + builder.setNegativeButton(R.string.cancel, (dialog, which) -> {}); builder.setCancelable(false); builder.show(); } diff --git a/app/src/main/java/fr/free/nrw/commons/navtab/MoreBottomSheetFragment.kt b/app/src/main/java/fr/free/nrw/commons/navtab/MoreBottomSheetFragment.kt index a79df3e15f..3f7a196fe6 100644 --- a/app/src/main/java/fr/free/nrw/commons/navtab/MoreBottomSheetFragment.kt +++ b/app/src/main/java/fr/free/nrw/commons/navtab/MoreBottomSheetFragment.kt @@ -161,7 +161,10 @@ class MoreBottomSheetFragment : BottomSheetDialogFragment() { override fun onFeedbackSubmit(feedback: Feedback) { uploadFeedback(feedback) } - }).show() + }).apply { + setCancelable(false) + show() + } } /** diff --git a/app/src/main/java/fr/free/nrw/commons/navtab/MoreBottomSheetLoggedOutFragment.kt b/app/src/main/java/fr/free/nrw/commons/navtab/MoreBottomSheetLoggedOutFragment.kt index 96baf9e5ea..769f524b3a 100644 --- a/app/src/main/java/fr/free/nrw/commons/navtab/MoreBottomSheetLoggedOutFragment.kt +++ b/app/src/main/java/fr/free/nrw/commons/navtab/MoreBottomSheetLoggedOutFragment.kt @@ -94,6 +94,7 @@ class MoreBottomSheetLoggedOutFragment : BottomSheetDialogFragment() { .setMessage(R.string.feedback_sharing_data_alert) .setCancelable(false) .setPositiveButton(R.string.ok) { _, _ -> sendFeedback() } + .setNegativeButton(R.string.cancel){_,_ -> } .show() } diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/fragments/CommonPlaceClickActions.kt b/app/src/main/java/fr/free/nrw/commons/nearby/fragments/CommonPlaceClickActions.kt index a4d6b14b7d..202f2c3057 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/fragments/CommonPlaceClickActions.kt +++ b/app/src/main/java/fr/free/nrw/commons/nearby/fragments/CommonPlaceClickActions.kt @@ -128,6 +128,8 @@ class CommonPlaceClickActions AlertDialog .Builder(activity) .setMessage(R.string.login_alert_message) + .setCancelable(false) + .setNegativeButton(R.string.cancel){_,_ -> } .setPositiveButton(R.string.login) { dialog, which -> setPositiveButton() }.show() diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java b/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java index 1c7280d215..c0c718d57a 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java @@ -1614,6 +1614,8 @@ public void displayLoginSkippedWarning() { // prompt the user to login new Builder(getContext()) .setMessage(R.string.login_alert_message) + .setCancelable(false) + .setNegativeButton(R.string.cancel, (dialog, which) -> {}) .setPositiveButton(R.string.login, (dialog, which) -> { // logout of the app BaseLogoutListener logoutListener = new BaseLogoutListener(getActivity()); diff --git a/app/src/main/java/fr/free/nrw/commons/quiz/QuizActivity.kt b/app/src/main/java/fr/free/nrw/commons/quiz/QuizActivity.kt index e60d4685a3..e65b819e5a 100644 --- a/app/src/main/java/fr/free/nrw/commons/quiz/QuizActivity.kt +++ b/app/src/main/java/fr/free/nrw/commons/quiz/QuizActivity.kt @@ -139,6 +139,7 @@ class QuizActivity : AppCompatActivity() { .setTitle(title) .setMessage(message) .setCancelable(false) + .setNegativeButton(R.string.cancel){_,_ -> } .setPositiveButton(R.string.continue_message) { dialog, _ -> questionIndex++ if (questionIndex == quiz.size) { diff --git a/app/src/main/java/fr/free/nrw/commons/settings/SettingsFragment.kt b/app/src/main/java/fr/free/nrw/commons/settings/SettingsFragment.kt index ee47f4a366..36528a919e 100644 --- a/app/src/main/java/fr/free/nrw/commons/settings/SettingsFragment.kt +++ b/app/src/main/java/fr/free/nrw/commons/settings/SettingsFragment.kt @@ -14,6 +14,7 @@ import android.text.TextWatcher import android.view.KeyEvent import android.view.View import android.widget.AdapterView +import android.widget.Button import android.widget.EditText import android.widget.ListView import android.widget.TextView @@ -333,24 +334,16 @@ class SettingsFragment : PreferenceFragmentCompat() { val dialog = Dialog(requireActivity()) dialog.setContentView(R.layout.dialog_select_language) - dialog.setCancelable(true)// Allow dialog to close with the back button + dialog.setCancelable(false) dialog.window?.setLayout( (resources.displayMetrics.widthPixels * 0.90).toInt(), (resources.displayMetrics.heightPixels * 0.90).toInt() ) - // Handle back button explicitly to dismiss the dialog - dialog.setOnKeyListener { _, keyCode, event -> - if (keyCode == KeyEvent.KEYCODE_BACK && event.action == KeyEvent.ACTION_UP) { - dialog.dismiss() // Close the dialog when the back button is pressed - true - } else { - false - } - } dialog.show() val editText: EditText = dialog.findViewById(R.id.search_language) val listView: ListView = dialog.findViewById(R.id.language_list) + val cancelButton = dialog.findViewById