From 1fe3787186267f976c490c93c59daeb12d22e3d5 Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Mon, 19 Oct 2020 14:24:12 +0200 Subject: [PATCH] Fix keyboard selection --- .../keepass/activities/GroupActivity.kt | 10 +++-- .../keepass/magikeyboard/MagikIME.kt | 1 - .../com/kunzisoft/keepass/model/EntryInfo.kt | 40 +++++++++---------- 3 files changed, 26 insertions(+), 25 deletions(-) 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 15e3b86f8..a52ff243b 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/GroupActivity.kt +++ b/app/src/main/java/com/kunzisoft/keepass/activities/GroupActivity.kt @@ -576,14 +576,18 @@ class GroupActivity : LockingActivity(), EntryActivity.launch(this@GroupActivity, entryVersioned, mReadOnly) }, { searchInfo -> - if (!mReadOnly && PreferencesUtil.isKeyboardSaveSearchInfoEnable(this@GroupActivity)) { + if (!mReadOnly + && searchInfo != null + && PreferencesUtil.isKeyboardSaveSearchInfoEnable(this@GroupActivity)) { updateEntryWithSearchInfo(entryVersioned, searchInfo) } else { entrySelectedForKeyboardSelection(entryVersioned) } }, { searchInfo, _ -> - if (!mReadOnly && PreferencesUtil.isAutofillSaveSearchInfoEnable(this@GroupActivity)) { + if (!mReadOnly + && searchInfo != null + && PreferencesUtil.isAutofillSaveSearchInfoEnable(this@GroupActivity)) { updateEntryWithSearchInfo(entryVersioned, searchInfo) } else { entrySelectedForAutofillSelection(entryVersioned) @@ -629,7 +633,7 @@ class GroupActivity : LockingActivity(), onValidateSpecialMode() } - private fun updateEntryWithSearchInfo(entry: Entry, searchInfo: SearchInfo?) { + private fun updateEntryWithSearchInfo(entry: Entry, searchInfo: SearchInfo) { val newEntry = Entry(entry) newEntry.setEntryInfo(mDatabase, newEntry.getEntryInfo(mDatabase).apply { saveSearchInfo(mDatabase, searchInfo) diff --git a/app/src/main/java/com/kunzisoft/keepass/magikeyboard/MagikIME.kt b/app/src/main/java/com/kunzisoft/keepass/magikeyboard/MagikIME.kt index e639e2621..0af4a798a 100644 --- a/app/src/main/java/com/kunzisoft/keepass/magikeyboard/MagikIME.kt +++ b/app/src/main/java/com/kunzisoft/keepass/magikeyboard/MagikIME.kt @@ -184,7 +184,6 @@ class MagikIME : InputMethodService(), KeyboardView.OnKeyboardActionListener { } } - @Suppress("DEPRECATION") private fun switchToPreviousKeyboard() { var imeManager: InputMethodManager? = null try { 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 409c3dffc..4bcfc1aa5 100644 --- a/app/src/main/java/com/kunzisoft/keepass/model/EntryInfo.kt +++ b/app/src/main/java/com/kunzisoft/keepass/model/EntryInfo.kt @@ -123,29 +123,27 @@ class EntryInfo : Parcelable { (customFields as ArrayList).add(Field(field.name + suffix, field.protectedValue)) } - fun saveSearchInfo(database: Database?, searchInfo: SearchInfo?) { - searchInfo?.let { mSearchInfo -> - mSearchInfo.webDomain?.let { webDomain -> - // If unable to save web domain in custom field or URL not populated, save in URL - if (database?.allowEntryCustomFields() != true || url.isEmpty()) { - val retrievedScheme = mSearchInfo.webScheme - val scheme = if (retrievedScheme.isNullOrEmpty()) "http" else retrievedScheme - url = "$scheme://$webDomain" - } else { - // Save web domain in custom field - addUniqueField(Field(WEB_DOMAIN_FIELD_NAME, - ProtectedString(false, webDomain)) + fun saveSearchInfo(database: Database?, searchInfo: SearchInfo) { + searchInfo.webDomain?.let { webDomain -> + // If unable to save web domain in custom field or URL not populated, save in URL + if (database?.allowEntryCustomFields() != true || url.isEmpty()) { + val retrievedScheme = searchInfo.webScheme + val scheme = if (retrievedScheme.isNullOrEmpty()) "http" else retrievedScheme + url = "$scheme://$webDomain" + } else { + // Save web domain in custom field + addUniqueField(Field(WEB_DOMAIN_FIELD_NAME, + ProtectedString(false, webDomain)) + ) + } + } ?: run { + // Save application id in custom field + if (database?.allowEntryCustomFields() == true) { + searchInfo.applicationId?.let { applicationId -> + addUniqueField(Field(APPLICATION_ID_FIELD_NAME, + ProtectedString(false, applicationId)) ) } - } ?: run { - // Save application id in custom field - if (database?.allowEntryCustomFields() == true) { - mSearchInfo.applicationId?.let { applicationId -> - addUniqueField(Field(APPLICATION_ID_FIELD_NAME, - ProtectedString(false, applicationId)) - ) - } - } } } }