From e157aeb0355ec07954eb433985ba169387483716 Mon Sep 17 00:00:00 2001 From: Naveen Singh Date: Mon, 1 Sep 2025 23:32:44 +0530 Subject: [PATCH 1/2] fix: prevent silent discard of contact edits Refs: https://github.com/FossifyOrg/Contacts/issues/360 --- CHANGELOG.md | 3 +++ .../activities/EditContactActivity.kt | 25 ++++++++++++------- 2 files changed, 19 insertions(+), 9 deletions(-) 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..cfcf493dc 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,9 @@ class EditContactActivity : ContactActivity() { } binding.contactToolbar.setNavigationOnClickListener { - hideKeyboard() - finish() + maybeShowUnsavedChangesDialog { + finish() + } } } From 7442e52b4ca2deb2a263894a42d95226f2f5e023 Mon Sep 17 00:00:00 2001 From: Naveen Singh Date: Mon, 1 Sep 2025 23:44:48 +0530 Subject: [PATCH 2/2] fix: restore `hideKeyboard()` call It must have been there for a reason --- .../org/fossify/contacts/activities/EditContactActivity.kt | 1 + 1 file changed, 1 insertion(+) 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 cfcf493dc..ba4deb294 100644 --- a/app/src/main/kotlin/org/fossify/contacts/activities/EditContactActivity.kt +++ b/app/src/main/kotlin/org/fossify/contacts/activities/EditContactActivity.kt @@ -367,6 +367,7 @@ class EditContactActivity : ContactActivity() { binding.contactToolbar.setNavigationOnClickListener { maybeShowUnsavedChangesDialog { + hideKeyboard() finish() } }