Skip to content

Fixes #17864 : Instant card, Double Pop of Discard Dialog Box issue#17871

Closed
MritunjayTiwari14 wants to merge 7 commits intoankidroid:mainfrom
MritunjayTiwari14:fixingDiscardChangesAction
Closed

Fixes #17864 : Instant card, Double Pop of Discard Dialog Box issue#17871
MritunjayTiwari14 wants to merge 7 commits intoankidroid:mainfrom
MritunjayTiwari14:fixingDiscardChangesAction

Conversation

@MritunjayTiwari14
Copy link

Purpose / Description

#17864 : Instant card, Double Pop of Discard Dialog Box issue

Fixes

Approach

using flag

How Has This Been Tested?

simply perform the task

Checklist

Please, go through these checks before submitting the PR.

  • [ x] 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
  • [x ] 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

@MritunjayTiwari14
Copy link
Author

@david-allison I need some guidance on how to fix the swipe gesture with back button which simultaneously pop and closes the discard dialog box without any interaction with the user

@david-allison
Copy link
Member

@MritunjayTiwari14 I'm marked as busy on GitHub and won't be able to help, sorry

@criticalAY criticalAY self-requested a review January 26, 2025 15:18
Comment on lines +103 to +111
// private val dialogBackCallback =
// object : OnBackPressedCallback(false) {
// override fun handleOnBackPressed() {
// showDiscardChangesDialog()
// }
// }

private var isDialogVisible = false

Copy link
Contributor

Choose a reason for hiding this comment

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

Heya! thanks for the contribution

Why this comment?
And how does it solve the issue, did you inspect the root cause?

Copy link
Author

Choose a reason for hiding this comment

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

Hello!, Sorry i forgot to remove it. I kept it as a backup and to analyze it while i wrote the new code with Flag to avoid repeated call to the Function to Display Discard Dialog Box.

@MritunjayTiwari14
Copy link
Author

Can someone Please Review it? @david-allison

@david-allison
Copy link
Member

Is there a simpler way to do this? This feels over complicated and likely to lead to bugs, especially for something which is such a common occurrence

@MritunjayTiwari14
Copy link
Author

Is there a simpler way to do this? This feels over complicated and likely to lead to bugs, especially for something which is such a common occurrence

Alright, looking into it!

Timber.i("InstantNoteEditorActivity:: OK button pressed to confirm discard changes")
finish()
}.setOnDismissListener {
// Used Dismiss Listener to Update the Value of Flag each time the Dialog is Dismissed
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove comment

Copy link
Author

Choose a reason for hiding this comment

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

Alright!

// Used Dismiss Listener to Update the Value of Flag each time the Dialog is Dismissed
isDialogVisible = false
}
isDialogVisible = true // Updating Flag as Dialog is Visible
Copy link
Contributor

Choose a reason for hiding this comment

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

comment?

Copy link
Author

Choose a reason for hiding this comment

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

Okay removing comments!

}
DiscardChangesDialog
.showDialog(this) {
Timber.i("InstantNoteEditorActivity:: OK button pressed to confirm discard changes")
Copy link
Contributor

Choose a reason for hiding this comment

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

Either d or remove it

Copy link
Author

Choose a reason for hiding this comment

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

Okay, i will d it.

Comment on lines +103 to +110
private var isDialogVisible = false // Created a New Flag To Handle Double Pop up of Discard Dialog

private val dialogBackCallback =
object : OnBackPressedCallback(false) {
override fun handleOnBackPressed() {
showDiscardChangesDialog()
if (!isDialogVisible) { // Show Discard Dialog only when it is not Visible to avoid Duplication
showDiscardChangesDialog()
}
Copy link
Contributor

Choose a reason for hiding this comment

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

remove comments

Copy link
Author

Choose a reason for hiding this comment

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

Okay

@criticalAY
Copy link
Contributor

I see there are two PR for the same issue @david-allison I am closing the latter one

@MritunjayTiwari14
Copy link
Author

MritunjayTiwari14 commented Feb 8, 2025

@criticalAY Put the SetCancelable() directly into the Activity File rather than for Whole Alertbuilder Dialog, It should be more optimized as we are changing for this Activity only and will not interfere in other places where the DiscardChangeDialog is being used otherwise.

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.

Quoting David:

Is there a simpler way to do this? This feels over complicated and likely to lead to bugs, especially for something which is such a common occurrence

Please see if we can do better here

@MritunjayTiwari14
Copy link
Author

@criticalAY Please Review, the best right now we can do is to remove the Flag and use isShowing(), other than that i have searched for many forms for hours and mostly say that to handle double back press issue, setCancellable() is a standard method.

@MritunjayTiwari14
Copy link
Author

MritunjayTiwari14 commented Feb 19, 2025

Hello???, Can anyone Please Review this? @david-allison

@david-allison
Copy link
Member

@MritunjayTiwari14 My review comment still stands.

Look into the following code, and modify it such that system swipe gestures are handled as they are by other dialogs.

The problem is the root activity, not the 'discard changes' dialog

private fun View.userClickOutsideDialog(exclude: View) {
setOnTouchListener { _, event ->
if (event.action != MotionEvent.ACTION_DOWN) return@setOnTouchListener false
if (exclude.rawHitTest(event)) {
return@setOnTouchListener false
}
this@InstantNoteEditorActivity.onBackPressedDispatcher.onBackPressed()
false
}
}

@david-allison david-allison added the Needs Author Reply Waiting for a reply from the original author label Feb 19, 2025
@MritunjayTiwari14
Copy link
Author

MritunjayTiwari14 commented Feb 20, 2025

Thank you for Your Direction, i was able to analyze within moments that the onBackPressed() should be called only when the motion event detects an Action.UP not Action.DOWN and that was the reason all these bugs were arising.

@david-allison Please have a review over the code base. I reverted all the changes and updated the code with the simple fix.

@MritunjayTiwari14
Copy link
Author

Can you please check it? @david-allison

@MritunjayTiwari14
Copy link
Author

MritunjayTiwari14 commented Mar 16, 2025

@Arthur-Milchior Can you please have a review on this?

@david-allison
Copy link
Member

At an initial glance, this doesn't seem to take into account my comment:

Look into the following code, and modify it such that system swipe gestures are handled as they are by other dialogs.

@david-allison david-allison added the Needs Author Reply Waiting for a reply from the original author label Jun 3, 2025
@github-actions
Copy link
Contributor

Hello 👋, this PR has had no activity for more than 2 weeks and needs a reply from the author. If you think this is a mistake please comment and ping a maintainer to get this merged ASAP! Thanks for contributing! You have 7 days until this gets closed automatically

@github-actions github-actions bot added the Stale label Jun 17, 2025
@github-actions github-actions bot closed this Jun 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Instant Editor Needs Author Reply Waiting for a reply from the original author Needs Review Stale

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

4 participants