diff --git a/CHANGELOG b/CHANGELOG index 675388c74..970fc7563 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -6,6 +6,7 @@ KeePassDX(3.3.0) * Merge from file and save as copy #1221 #1204 #840 * Fix custom data #1236 * Fix education hints #1192 + * Fix save and app instance in selection mode * New UI and fix styles * Add "Simple" and "Reply" themes diff --git a/app/src/main/java/com/kunzisoft/keepass/activities/GroupActivity.kt b/app/src/main/java/com/kunzisoft/keepass/activities/GroupActivity.kt index 37c7f6d2e..9ba2c2780 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/GroupActivity.kt +++ b/app/src/main/java/com/kunzisoft/keepass/activities/GroupActivity.kt @@ -838,29 +838,13 @@ class GroupActivity : DatabaseLockActivity(), finish() }, { searchInfo -> - // Recheck search, only to fix #783 because workflow allows to open multiple search elements - SearchHelper.checkAutoSearchInfo(this, - database, - searchInfo, - { openedDatabase, _ -> - // Item in search, don't save - entrySelectedForKeyboardSelection(openedDatabase, entryVersioned) - }, - { - // Item not found, save it if required - if (!database.isReadOnly - && searchInfo != null - && PreferencesUtil.isKeyboardSaveSearchInfoEnable(this@GroupActivity) - ) { - updateEntryWithSearchInfo(database, entryVersioned, searchInfo) - } - entrySelectedForKeyboardSelection(database, entryVersioned) - }, - { - // Normally not append - finish() - } - ) + if (!database.isReadOnly + && searchInfo != null + && PreferencesUtil.isKeyboardSaveSearchInfoEnable(this@GroupActivity) + ) { + updateEntryWithSearchInfo(database, entryVersioned, searchInfo) + } + entrySelectedForKeyboardSelection(database, entryVersioned) }, { searchInfo, _ -> if (!database.isReadOnly @@ -942,14 +926,16 @@ class GroupActivity : DatabaseLockActivity(), searchInfo: SearchInfo ) { val newEntry = Entry(entry) - newEntry.setEntryInfo(database, newEntry.getEntryInfo( + val entryInfo = newEntry.getEntryInfo( database, raw = true, removeTemplateConfiguration = false - ).apply { - saveSearchInfo(database, searchInfo) - }) - updateEntry(entry, newEntry) + ) + val modification = entryInfo.saveSearchInfo(database, searchInfo) + newEntry.setEntryInfo(database, entryInfo) + if (modification) { + updateEntry(entry, newEntry) + } } override fun onDateSet(datePicker: DatePicker?, year: Int, month: Int, day: Int) { diff --git a/app/src/main/java/com/kunzisoft/keepass/activities/legacy/DatabaseModeActivity.kt b/app/src/main/java/com/kunzisoft/keepass/activities/legacy/DatabaseModeActivity.kt index a3bf6a724..1297c8af0 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/legacy/DatabaseModeActivity.kt +++ b/app/src/main/java/com/kunzisoft/keepass/activities/legacy/DatabaseModeActivity.kt @@ -1,6 +1,8 @@ package com.kunzisoft.keepass.activities.legacy import android.os.Bundle +import android.os.Handler +import android.os.Looper import android.view.View import android.widget.Toast import com.kunzisoft.keepass.R @@ -11,6 +13,7 @@ import com.kunzisoft.keepass.model.SearchInfo import com.kunzisoft.keepass.settings.PreferencesUtil import com.kunzisoft.keepass.view.SpecialModeView + /** * Activity to manage database special mode (ie: selection mode) */ @@ -63,8 +66,7 @@ abstract class DatabaseModeActivity : DatabaseActivity() { EntrySelectionHelper.removeModesFromIntent(intent) EntrySelectionHelper.removeInfoFromIntent(intent) if (mSpecialMode != SpecialMode.DEFAULT) { - // To move the app in background - moveTaskToBack(true) + backToTheMainAppAndFinish() } } } @@ -77,8 +79,7 @@ abstract class DatabaseModeActivity : DatabaseActivity() { EntrySelectionHelper.removeModesFromIntent(intent) EntrySelectionHelper.removeInfoFromIntent(intent) if (mSpecialMode != SpecialMode.DEFAULT) { - // To move the app in background - moveTaskToBack(true) + backToTheMainAppAndFinish() } } } @@ -88,11 +89,19 @@ abstract class DatabaseModeActivity : DatabaseActivity() { // To get the app caller, only for IntentSender super.onBackPressed() } else { - // To move the app in background - moveTaskToBack(true) + backToTheMainAppAndFinish() } } + private fun backToTheMainAppAndFinish() { + // To move the app in background and return to the main app + moveTaskToBack(true) + // To remove this instance in the OS app selector + Handler(Looper.getMainLooper()).postDelayed({ + finish() + }, 2000) + } + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) diff --git a/app/src/main/java/com/kunzisoft/keepass/model/EntryInfo.kt b/app/src/main/java/com/kunzisoft/keepass/model/EntryInfo.kt index 8a7fb3e11..538f6b122 100644 --- a/app/src/main/java/com/kunzisoft/keepass/model/EntryInfo.kt +++ b/app/src/main/java/com/kunzisoft/keepass/model/EntryInfo.kt @@ -109,7 +109,9 @@ class EntryInfo : NodeInfo { return customFields.lastOrNull { it.name == label }?.protectedValue?.toString() ?: "" } - private fun addUniqueField(field: Field, number: Int = 0) { + // Return true if modified + private fun addUniqueField(field: Field, number: Int = 0): Boolean { + var modification = false var sameName = false var sameValue = false val suffix = if (number > 0) "_$number" else "" @@ -117,20 +119,28 @@ class EntryInfo : NodeInfo { // Not write the same data again if (currentField.protectedValue.stringValue == field.protectedValue.stringValue) { sameValue = true - return + return false } // Same name but new value, create a new suffix if (currentField.name == field.name + suffix) { sameName = true - addUniqueField(field, number + 1) - return + if (addUniqueField(field, number + 1)) + modification = true + return true } } - if (!sameName && !sameValue) + if (!sameName && !sameValue) { (customFields as ArrayList).add(Field(field.name + suffix, field.protectedValue)) + modification = true + } + return modification } - fun saveSearchInfo(database: Database?, searchInfo: SearchInfo) { + /** + * Add searchInfo to current EntryInfo, return true if new data, false if no modification + */ + fun saveSearchInfo(database: Database?, searchInfo: SearchInfo): Boolean { + var modification = false searchInfo.otpString?.let { otpString -> // Replace the OTP field OtpEntryFields.parseOTPUri(otpString)?.let { otpElement -> @@ -145,6 +155,7 @@ class EntryInfo : NodeInfo { mutableCustomFields.remove(otpField) } mutableCustomFields.add(otpField) + modification = true } } ?: searchInfo.webDomain?.let { webDomain -> // If unable to save web domain in custom field or URL not populated, save in URL @@ -153,23 +164,27 @@ class EntryInfo : NodeInfo { val webDomainToStore = "$webScheme://$webDomain" if (database?.allowEntryCustomFields() != true || url.isEmpty()) { url = webDomainToStore + modification = true } else if (url != webDomainToStore) { // Save web domain in custom field - addUniqueField(Field(WEB_DOMAIN_FIELD_NAME, + if (addUniqueField(Field(WEB_DOMAIN_FIELD_NAME, ProtectedString(false, webDomainToStore)), 1 // Start to one because URL is a standard field name - ) + )) + modification = true } } ?: run { // Save application id in custom field if (database?.allowEntryCustomFields() == true) { searchInfo.applicationId?.let { applicationId -> - addUniqueField(Field(APPLICATION_ID_FIELD_NAME, + if (addUniqueField(Field(APPLICATION_ID_FIELD_NAME, ProtectedString(false, applicationId)) - ) + )) + modification = true } } } + return modification } fun saveRegisterInfo(database: Database?, registerInfo: RegisterInfo) { diff --git a/fastlane/metadata/android/en-US/changelogs/101.txt b/fastlane/metadata/android/en-US/changelogs/101.txt index a7450e3f3..192d95997 100644 --- a/fastlane/metadata/android/en-US/changelogs/101.txt +++ b/fastlane/metadata/android/en-US/changelogs/101.txt @@ -5,5 +5,6 @@ * Merge from file and save as copy #1221 #1204 #840 * Fix custom data #1236 * Fix education hints #1192 + * Fix save and app instance in selection mode * New UI and fix styles * Add "Simple" and "Reply" themes \ No newline at end of file diff --git a/fastlane/metadata/android/fr-FR/changelogs/101.txt b/fastlane/metadata/android/fr-FR/changelogs/101.txt index 3bea8b5da..b44ed280b 100644 --- a/fastlane/metadata/android/fr-FR/changelogs/101.txt +++ b/fastlane/metadata/android/fr-FR/changelogs/101.txt @@ -5,5 +5,6 @@ * Fusion depuis un fichier et sauvegarde de copie #1221 #1204 #840 * Correction des données customisées #1236 * Correction de écrans d'éducation #1192 + * Correction de la sauvegarde en mode sélection * Nouvelle interface utilisateur et correction des styles * Ajout des thèmes "Simple" et "Réponse" \ No newline at end of file