Add a "discard change" warning

This commit is contained in:
Benoit Marty 2020-10-22 15:07:07 +02:00 committed by Benoit Marty
parent 7a37db84d8
commit 5c62f29c6f
2 changed files with 26 additions and 1 deletions

View file

@ -35,6 +35,7 @@ import im.vector.app.core.extensions.cleanup
import im.vector.app.core.extensions.configureWith
import im.vector.app.core.extensions.exhaustive
import im.vector.app.core.intent.getFilenameFromUri
import im.vector.app.core.platform.OnBackPressed
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.core.utils.toast
import im.vector.app.features.home.AvatarRenderer
@ -60,6 +61,7 @@ class RoomSettingsFragment @Inject constructor(
) :
VectorBaseFragment(),
RoomSettingsController.Callback,
OnBackPressed,
GalleryOrCameraDialogHelper.Listener {
private val viewModel: RoomSettingsViewModel by fragmentViewModel()
@ -226,5 +228,26 @@ class RoomSettingsFragment @Inject constructor(
}
}
// TODO BMA Handle Back with unsaved data
private var ignoreChanges = false
override fun onBackPressed(toolbarButton: Boolean): Boolean {
if (ignoreChanges) return false
return withState(viewModel) {
return@withState if (it.showSaveAction) {
AlertDialog.Builder(requireContext())
.setTitle(R.string.dialog_title_warning)
.setMessage(R.string.warning_unsaved_change)
.setPositiveButton(R.string.warning_unsaved_change_discard) { _, _ ->
ignoreChanges = true
vectorBaseActivity.onBackPressed()
}
.setNegativeButton(R.string.cancel, null)
.show()
true
} else {
false
}
}
}
}

View file

@ -2628,4 +2628,6 @@
<!-- Universal link -->
<string name="universal_link_malformed">The link was malformed</string>
<string name="warning_unsaved_change">There are unsaved changes. Discard the changes?</string>
<string name="warning_unsaved_change_discard">Discard changes</string>
</resources>