Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

Add discard-changes dialog when back is pressed when editing a credential. #1062

Merged
merged 4 commits into from
Nov 14, 2019

Conversation

jhugman
Copy link
Contributor

@jhugman jhugman commented Nov 12, 2019

Fixes #994.

This PR introduces:

  • infrastructure in the Activity and RoutePresenter to allow the presenter to customize the effect of the back button.
  • check in edit item screen to see if any editing has occurred.
  • bolstering of the edit item store to show the discard-changes-dialog if and only if an edit has been made.

@jhugman jhugman requested a review from a team as a code owner November 12, 2019 14:11
Copy link
Contributor

@eliserichards eliserichards left a comment

Choose a reason for hiding this comment

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

A+ on the tests. This is looking great. I have a few comments/questions which I'd like to discuss before I do more thorough local testing 😄

Comment on lines 17 to 20
data class SaveChanges(val item: ServerPassword) :
ItemDetailAction(TelemetryEventMethod.tap, TelemetryEventObject.update_credential)
data class DiscardChanges(val itemId: String) :
ItemDetailAction(TelemetryEventMethod.tap, TelemetryEventObject.back)
Copy link
Contributor

Choose a reason for hiding this comment

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

Very nice 👍

.distinctUntilChanged()
.filter { !it }
.flatMapIterable {
edited = null
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we setting this to null on edit?

)
.map {
edited?.let { ItemDetailAction.SaveChanges(it) }
?: ItemDetailAction.DiscardChanges(itemId)
Copy link
Contributor

Choose a reason for hiding this comment

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

If we can't save we want it to fail, not ask them if they want to discard their changes. I don't think that's a logical flow for the user to click ✅ and then be prompted to discard.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If there are no changes, then we should just exit. DiscardChanges simply exits.

if (it != credentials) {
DialogAction.DiscardChangesDialog(itemId)
} else {
null
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we fail here too? (if the edited credential is somehow inconsistent with credentials)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This could be written as

// if the user has changed the credentials
if (edited != null && edited != credentials) {
   // display a dialog checking if they want to discard
   DialogAction.DiscardChangesDialog(itemId)
} else {
   // just go ahead and discard/exit.
   ItemDetailAction.DiscardChanges(itemId)
}

} else {
null
}
} ?: ItemDetailAction.DiscardChanges(itemId)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same thought about failing here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There seems to be a confusion on what ItemDetailAction.DiscardChanges means.

I should rename to FinishEditing or comment it.

Comment on lines 173 to 190
override fun onBackPressed(): Boolean {
val itemId = credentials?.id ?: return false
dispatcher.dispatch(checkDismissChanges(itemId))
return true
}
Copy link
Contributor

Choose a reason for hiding this comment

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

👏 🎉

@@ -30,6 +30,7 @@ import mozilla.lockbox.flux.Presenter
import mozilla.lockbox.log
import mozilla.lockbox.store.RouteStore
import mozilla.lockbox.view.DialogFragment
import mozilla.lockbox.view.Fragment as SpecializedFragment
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting 🤔 Why do we want an alias here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm. I thought it might be clearer to use an obviously-not-android-fragment name, here. Since we're not using androidx.*.Fragment, it seems it just adds confusion.

Comment on lines +50 to +51
if (!presenter.onBackPressed()) {
super.onBackPressed()
Copy link
Contributor

Choose a reason for hiding this comment

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

(if I'm understanding this correctly:) if the presenter doesn't have a specific implementation, use super's?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. The activity's implementation will trigger the back button behaviour.

@jhugman jhugman force-pushed the jhugman/994-dismiss-changes-back-button branch from 34a4266 to 485d864 Compare November 13, 2019 16:59
Copy link
Contributor

@eliserichards eliserichards left a comment

Choose a reason for hiding this comment

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

Fantastic. I did some manual tests and it looks 🔝

@jhugman jhugman merged commit 49d0bec into master Nov 14, 2019
@jhugman jhugman deleted the jhugman/994-dismiss-changes-back-button branch November 14, 2019 15:03
eliserichards pushed a commit that referenced this pull request Nov 15, 2019
…tial. (#1062)

* Suppress dismiss changes dialog if no editing has taken place

* Intercept back button pressed, and feed it through to the presenters.

* Tease out stopping editing and saving changes in to the item detail store.

This allows us to intercept the back button, discard changes, and save changes coherently and consistently.

* Address reviewer comments
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The device back button doesn't have the same functionality with the X button in Edit Login Mode
2 participants