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
Open
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 @@ -31,11 +31,14 @@ object DiscardChangesDialog {
positiveButtonText: String = context.getString(R.string.discard),
negativeButtonText: String = CollectionManager.TR.addingKeepEditing(),
message: String = CollectionManager.TR.addingDiscardCurrentInput(),
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() }
Comment on lines +34 to +42
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

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,16 @@ class InstantNoteEditorActivity :
private lateinit var singleTapLayout: LinearLayout
private lateinit var singleTapLayoutTitle: FixedTextView

private var isDialogShowing = false

/** Gets the actual cloze field text value **/
private val clozeFieldText: String?
get() = viewModel.actualClozeFieldText.value

private val dialogBackCallback =
object : OnBackPressedCallback(false) {
override fun handleOnBackPressed() {
if (isDialogShowing) return
showDiscardChangesDialog()
}
}
Expand Down Expand Up @@ -600,7 +603,11 @@ class InstantNoteEditorActivity :
}

private fun showDiscardChangesDialog() {
DiscardChangesDialog.showDialog(this) {
isDialogShowing = true
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

Copy link
Author

Choose a reason for hiding this comment

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

Hi @criticalAY , I've also asked some questions about the issue on Discord. I'll update this PR as soon as I receive some responses regarding the expectations, along with your suggestions.
Thanks for taking time to review this.

Timber.i("InstantNoteEditorActivity:: OK button pressed to confirm discard changes")
finish()
}
Expand Down