Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cancel button to dialogs with no button #6078

Merged
merged 1 commit into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
Expand Down Expand Up @@ -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() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,10 @@ class MoreBottomSheetFragment : BottomSheetDialogFragment() {
override fun onFeedbackSubmit(feedback: Feedback) {
uploadFeedback(feedback)
}
}).show()
}).apply {
setCancelable(false)
show()
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/fr/free/nrw/commons/quiz/QuizActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
15 changes: 5 additions & 10 deletions app/src/main/java/fr/free/nrw/commons/settings/SettingsFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<Button>(R.id.cancel_button)
languageHistoryListView = dialog.findViewById(R.id.language_history_list)
recentLanguagesTextView = dialog.findViewById(R.id.recent_searches)
separator = dialog.findViewById(R.id.separator)
Expand All @@ -359,6 +352,8 @@ class SettingsFragment : PreferenceFragmentCompat() {

listView.adapter = languagesAdapter

cancelButton.setOnClickListener { dialog.dismiss() }

editText.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(charSequence: CharSequence, start: Int, count: Int, after: Int) {
hideRecentLanguagesSection()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,7 @@ private void showAlertDialogForCategories() {
.setView(view)
.setTitle(getString(R.string.multiple_files_depiction_header))
.setMessage(getString(R.string.multiple_files_depiction))
.setCancelable(false)
.setPositiveButton("OK", (dialog, which) -> {
if (checkBox.isChecked()) {
// Save the user's choice to not show the dialog again
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
Expand Down Expand Up @@ -357,13 +358,16 @@ public void onClick(View view) {

EditText editText = dialog.findViewById(R.id.search_language);
ListView listView = dialog.findViewById(R.id.language_list);
final Button cancelButton = dialog.findViewById(R.id.cancel_button);
languageHistoryListView = dialog.findViewById(R.id.language_history_list);
recentLanguagesTextView = dialog.findViewById(R.id.recent_searches);
separator = dialog.findViewById(R.id.separator);
setUpRecentLanguagesSection(recentLanguages);

listView.setAdapter(languagesAdapter);

cancelButton.setOnClickListener(v -> dialog.dismiss());

editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ class DepictsFragment : UploadBaseFragment(), DepictsContract.View {
override fun showProgressDialog() {
progressDialog = ProgressDialog(requireContext())
progressDialog!!.setMessage(getString(R.string.please_wait))
progressDialog!!.setCancelable(false)
progressDialog!!.show()
}

Expand Down
35 changes: 26 additions & 9 deletions app/src/main/res/layout/dialog_feedback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,32 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<Button
android:id="@+id/btn_submit_feedback"
android:textColor="@color/white"
android:layout_marginBottom="@dimen/dimen_10"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/dimen_10"
android:gravity="center"
android:layout_gravity="center"
android:text="@string/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
android:orientation="horizontal">

<Button
android:id="@+id/btn_cancel"
android:textColor="@color/white"
android:layout_gravity="center"
android:layout_weight="1"
android:text="@string/cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<Button
android:id="@+id/btn_submit_feedback"
android:textColor="@color/white"
android:layout_weight="1"
android:layout_gravity="center"
android:text="@string/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</LinearLayout>

</LinearLayout>
</ScrollView>
</ScrollView>
17 changes: 13 additions & 4 deletions app/src/main/res/layout/dialog_select_language.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,18 @@
android:layout_height="0dp"
android:layout_marginTop="8dp"
android:id="@+id/language_list"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toTopOf="@id/cancel_button"
app:layout_constraintTop_toBottomOf="@+id/all_languages" />

</androidx.constraintlayout.widget.ConstraintLayout>

<Button
android:id="@+id/cancel_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cancel"
android:textColor="@color/primaryColor"
android:background="@android:color/transparent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
Loading