diff --git a/CHANGELOG.md b/CHANGELOG.md index 00aaa806d..b7ccf7585 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed +- Fixed contacts edits being silently discarded when using navigation arrow ([#360]) ## [1.2.4] - 2025-07-31 ### Changed @@ -79,6 +81,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [#281]: https://github.com/FossifyOrg/Contacts/issues/281 [#289]: https://github.com/FossifyOrg/Contacts/issues/289 [#339]: https://github.com/FossifyOrg/Contacts/issues/339 +[#360]: https://github.com/FossifyOrg/Contacts/issues/360 [Unreleased]: https://github.com/FossifyOrg/Contacts/compare/1.2.4...HEAD [1.2.4]: https://github.com/FossifyOrg/Contacts/compare/1.2.3...1.2.4 diff --git a/app/src/main/kotlin/org/fossify/contacts/activities/EditContactActivity.kt b/app/src/main/kotlin/org/fossify/contacts/activities/EditContactActivity.kt index 849f32734..ba4deb294 100644 --- a/app/src/main/kotlin/org/fossify/contacts/activities/EditContactActivity.kt +++ b/app/src/main/kotlin/org/fossify/contacts/activities/EditContactActivity.kt @@ -297,23 +297,29 @@ class EditContactActivity : ContactActivity() { } override fun onBackPressed() { + maybeShowUnsavedChangesDialog { + super.onBackPressed() + } + } + + private fun maybeShowUnsavedChangesDialog(discard: () -> Unit) { if (System.currentTimeMillis() - mLastSavePromptTS > SAVE_DISCARD_PROMPT_INTERVAL && hasContactChanged()) { mLastSavePromptTS = System.currentTimeMillis() ConfirmationAdvancedDialog( - this, - "", - org.fossify.commons.R.string.save_before_closing, - org.fossify.commons.R.string.save, - org.fossify.commons.R.string.discard + activity = this, + message = "", + messageId = org.fossify.commons.R.string.save_before_closing, + positive = org.fossify.commons.R.string.save, + negative = org.fossify.commons.R.string.discard ) { if (it) { saveContact() } else { - super.onBackPressed() + discard() } } } else { - super.onBackPressed() + discard() } } @@ -360,8 +366,10 @@ class EditContactActivity : ContactActivity() { } binding.contactToolbar.setNavigationOnClickListener { - hideKeyboard() - finish() + maybeShowUnsavedChangesDialog { + hideKeyboard() + finish() + } } }