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

Prevent double Discard Changes dialog on Android back swipe gesture #17907

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Sahil06012002
Copy link

@Sahil06012002 Sahil06012002 commented Jan 31, 2025

Purpose / Description

Instant Card: Double "discard changes" window appears on Android "Back" swipe gesture #17864

Fixes

Approach

To handle the issue effectively, we introduce a flag (isDialogShowing ) to monitor the visibility of the AlertDialog.

By default, the AlertDialog gets dismissed when clicked outside, but the flag (isDialogShowing) remains true. This prevents the dialog from appearing again when needed.

To address this, we modify the showDialog function in the DiscardChangesDialog.kt file to accept an isCancellable parameter. Setting setCancelable(false) ensures that the dialog is not dismissed when clicking outside, allowing us to manage the flag correctly.

This update changes the default behavior of this particular AlertDialog, preventing it from being dismissed when clicking outside the dialog. Seeking guidance on whether this change is acceptable.

This approach ensures that isDialogShowing is updated properly when the dialog is dismissed, preventing unexpected behavior.

How Has This Been Tested?

Tested on Android device and attached screen recording.

Checklist

Please, go through these checks before submitting the PR.

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • [] UI Changes: You have tested your change using the Google Accessibility Scanner

Uploading screen-rec.mp4…

Copy link

welcome bot commented Jan 31, 2025

First PR! 🚀 We sincerely appreciate that you have taken the time to propose a change to AnkiDroid! Please have patience with us as we are all volunteers - we will get to this as soon as possible.

Copy link
Contributor

@criticalAY criticalAY left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heya! Thanks
Check if it can be further simplified

Comment on lines +34 to +42
isCancellable: Boolean = true,
negativeMethod: () -> Unit = {},
positiveMethod: () -> Unit,
) = AlertDialog.Builder(context).show {
setCancelable(isCancellable)
Timber.i("showing 'discard changes' dialog")
message(text = message)
positiveButton(text = positiveButtonText) { positiveMethod() }
negativeButton(text = negativeButtonText)
negativeButton(text = negativeButtonText) { negativeMethod() }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do the same without changing the original code here, I think that the Discard dialog should be kept simple

DiscardChangesDialog.showDialog(this, isCancellable = false, negativeMethod = {
isDialogShowing = false
}) {
isDialogShowing = false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can use dismiss listener

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Instant Card: Double "discard changes" window appears on Android "Back" swipe gesture
2 participants