From 8502bceef1db6235806788008eec8a04df851dfd Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Thu, 9 Dec 2021 18:38:38 +0100 Subject: [PATCH] Fix search --- .../keepass/activities/GroupActivity.kt | 58 ++++++++----------- 1 file changed, 25 insertions(+), 33 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 6afb48a03..7116d7506 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/GroupActivity.kt +++ b/app/src/main/java/com/kunzisoft/keepass/activities/GroupActivity.kt @@ -335,6 +335,29 @@ class GroupActivity : DatabaseLockActivity(), return rootContainerView } + private fun loadGroup(database: Database?) { + when { + Intent.ACTION_SEARCH == intent.action -> { + finishNodeAction() + val searchString = + intent.getStringExtra(SearchManager.QUERY)?.trim { it <= ' ' } ?: "" + mGroupViewModel.loadGroupFromSearch( + database, + searchString, + PreferencesUtil.omitBackup(this) + ) + } + mCurrentGroupState == null -> { + mRootGroup?.let { rootGroup -> + mGroupViewModel.loadGroup(database, rootGroup, 0) + } + } + else -> { + mGroupViewModel.loadGroup(database, mCurrentGroupState) + } + } + } + override fun onDatabaseRetrieved(database: Database?) { super.onDatabaseRetrieved(database) @@ -344,13 +367,7 @@ class GroupActivity : DatabaseLockActivity(), && database?.isRecycleBinEnabled == true mRootGroup = database?.rootGroup - if (mCurrentGroupState == null) { - mRootGroup?.let { rootGroup -> - mGroupViewModel.loadGroup(database, rootGroup, 0) - } - } else { - mGroupViewModel.loadGroup(database, mCurrentGroupState) - } + loadGroup(database) // Search suggestion database?.let { @@ -463,16 +480,7 @@ class GroupActivity : DatabaseLockActivity(), } // To transform KEY_SEARCH_INFO in ACTION_SEARCH transformSearchInfoIntent(intent) - if (Intent.ACTION_SEARCH == intent.action) { - finishNodeAction() - val searchString = - intent.getStringExtra(SearchManager.QUERY)?.trim { it <= ' ' } ?: "" - mGroupViewModel.loadGroupFromSearch( - mDatabase, - searchString, - PreferencesUtil.omitBackup(this) - ) - } + loadGroup(mDatabase) } } @@ -1081,22 +1089,6 @@ class GroupActivity : DatabaseLockActivity(), } } - @Suppress("DEPRECATION") - override fun startActivityForResult(intent: Intent, requestCode: Int, options: Bundle?) { - /* - * ACTION_SEARCH automatically forces a new task. This occurs when you open a kdb file in - * another app such as Files or GoogleDrive and then Search for an entry. Here we remove the - * FLAG_ACTIVITY_NEW_TASK flag bit allowing search to open it's activity in the current task. - */ - if (Intent.ACTION_SEARCH == intent.action) { - var flags = intent.flags - flags = flags and Intent.FLAG_ACTIVITY_NEW_TASK.inv() - intent.flags = flags - } - - super.startActivityForResult(intent, requestCode, options) - } - private fun removeSearch() { intent.removeExtra(AUTO_SEARCH_KEY) if (Intent.ACTION_SEARCH == intent.action) {