-
Notifications
You must be signed in to change notification settings - Fork 97
Add discard-changes dialog when back is pressed when editing a credential. #1062
Conversation
There was a problem hiding this 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 😄
data class SaveChanges(val item: ServerPassword) : | ||
ItemDetailAction(TelemetryEventMethod.tap, TelemetryEventObject.update_credential) | ||
data class DiscardChanges(val itemId: String) : | ||
ItemDetailAction(TelemetryEventMethod.tap, TelemetryEventObject.back) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
)
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
override fun onBackPressed(): Boolean { | ||
val itemId = credentials?.id ?: return false | ||
dispatcher.dispatch(checkDismissChanges(itemId)) | ||
return true | ||
} |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
if (!presenter.onBackPressed()) { | ||
super.onBackPressed() |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct.
There was a problem hiding this comment.
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.
…tore. This allows us to intercept the back button, discard changes, and save changes coherently and consistently.
34a4266
to
485d864
Compare
There was a problem hiding this 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 🔝
…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
Fixes #994.
This PR introduces: