Search improvement

This commit is contained in:
J-Jamet
2020-05-23 12:59:05 +02:00
parent 34bf8f9d1f
commit 7bd1aedada
3 changed files with 22 additions and 28 deletions

View File

@@ -72,13 +72,13 @@ class EntrySelectionLauncherActivity : AppCompatActivity() {
{ items -> { items ->
// Items found // Items found
if (searchShareForMagikeyboard) { if (searchShareForMagikeyboard) {
if (items.size > 1) { if (items.size == 1) {
// Select the one we want
GroupActivity.launchForEntrySelectionResult(this, searchInfo)
} else {
// Automatically populate keyboard // Automatically populate keyboard
val entryPopulate = items[0] val entryPopulate = items[0]
populateKeyboardAndMoveAppToBackground(this, entryPopulate, intent) populateKeyboardAndMoveAppToBackground(this, entryPopulate, intent)
} else {
// Select the one we want
GroupActivity.launchForEntrySelectionResult(this, searchInfo)
} }
} else { } else {
GroupActivity.launch(this, searchInfo) GroupActivity.launch(this, searchInfo)

View File

@@ -290,7 +290,8 @@ class GroupActivity : LockingActivity(),
setIntent(intentNotNull) setIntent(intentNotNull)
mCurrentGroupIsASearch = if (Intent.ACTION_SEARCH == intentNotNull.action) { mCurrentGroupIsASearch = if (Intent.ACTION_SEARCH == intentNotNull.action) {
// only one instance of search in backstack // only one instance of search in backstack
openSearchGroup(retrieveCurrentGroup(intentNotNull, null)) deletePreviousSearchGroup()
openGroup(retrieveCurrentGroup(intentNotNull, null), true)
true true
} else { } else {
false false
@@ -314,7 +315,7 @@ class GroupActivity : LockingActivity(),
return false return false
} }
private fun openSearchGroup(group: Group?) { private fun deletePreviousSearchGroup() {
// Delete the previous search fragment // Delete the previous search fragment
try { try {
val searchFragment = supportFragmentManager.findFragmentByTag(SEARCH_FRAGMENT_TAG) val searchFragment = supportFragmentManager.findFragmentByTag(SEARCH_FRAGMENT_TAG)
@@ -327,11 +328,6 @@ class GroupActivity : LockingActivity(),
} catch (exception: Exception) { } catch (exception: Exception) {
Log.e(TAG, "unable to remove previous search fragment", exception) Log.e(TAG, "unable to remove previous search fragment", exception)
} }
openGroup(group, true)
}
private fun openChildGroup(group: Group) {
openGroup(group, false)
} }
private fun openGroup(group: Group?, isASearch: Boolean) { private fun openGroup(group: Group?, isASearch: Boolean) {
@@ -379,8 +375,9 @@ class GroupActivity : LockingActivity(),
} }
private fun refreshSearchGroup() { private fun refreshSearchGroup() {
deletePreviousSearchGroup()
if (mCurrentGroupIsASearch) if (mCurrentGroupIsASearch)
openSearchGroup(retrieveCurrentGroup(intent, null)) openGroup(retrieveCurrentGroup(intent, null), true)
} }
private fun retrieveCurrentGroup(intent: Intent, savedInstanceState: Bundle?): Group? { private fun retrieveCurrentGroup(intent: Intent, savedInstanceState: Bundle?): Group? {
@@ -505,7 +502,8 @@ class GroupActivity : LockingActivity(),
override fun onNodeClick(node: Node) { override fun onNodeClick(node: Node) {
when (node.type) { when (node.type) {
Type.GROUP -> try { Type.GROUP -> try {
openChildGroup(node as Group) // Open child group
openGroup(node as Group, false)
} catch (e: ClassCastException) { } catch (e: ClassCastException) {
Log.e(TAG, "Node can't be cast in Group") Log.e(TAG, "Node can't be cast in Group")
} }
@@ -978,6 +976,9 @@ class GroupActivity : LockingActivity(),
lockAndExit() lockAndExit()
super.onBackPressed() super.onBackPressed()
} else { } else {
deletePreviousSearchGroup()
// To restore standard mode
EntrySelectionHelper.removeEntrySelectionModeFromIntent(intent)
moveTaskToBack(true) moveTaskToBack(true)
} }
} }
@@ -1010,12 +1011,9 @@ class GroupActivity : LockingActivity(),
if (group != null) { if (group != null) {
intent.putExtra(GROUP_ID_KEY, group.nodeId) intent.putExtra(GROUP_ID_KEY, group.nodeId)
} }
// Directly get ACTION_SEARCH from search info (quick), only in selection mode // Directly pass Search info, decoded later in onCreate (to fix manual selection)
if (searchInfo != null) { searchInfo?.let {
intent.action = Intent.ACTION_SEARCH intent.putExtra(KEY_SEARCH_INFO, it)
val searchQuery = searchInfo.webDomain ?: searchInfo.applicationId
intent.removeExtra(KEY_SEARCH_INFO)
intent.putExtra(SearchManager.QUERY, searchQuery)
} }
ReadOnlyHelper.putReadOnlyInIntent(intent, readOnly) ReadOnlyHelper.putReadOnlyInIntent(intent, readOnly)
intentBuildLauncher.invoke(intent) intentBuildLauncher.invoke(intent)
@@ -1049,11 +1047,7 @@ class GroupActivity : LockingActivity(),
fun launch(context: Context, fun launch(context: Context,
searchInfo: SearchInfo? = null, searchInfo: SearchInfo? = null,
readOnly: Boolean = PreferencesUtil.enableReadOnlyDatabase(context)) { readOnly: Boolean = PreferencesUtil.enableReadOnlyDatabase(context)) {
checkTimeAndBuildIntent(context, null, null, readOnly) { intent -> checkTimeAndBuildIntent(context, null, searchInfo, readOnly) { intent ->
// Directly pass Search info, decoded later in onCreate (to fix manual selection)
searchInfo?.let {
intent.putExtra(KEY_SEARCH_INFO, it)
}
context.startActivity(intent) context.startActivity(intent)
} }
} }

View File

@@ -278,13 +278,13 @@ open class PasswordActivity : StylishActivity() {
searchInfo, searchInfo,
{ items -> { items ->
// Response is build // Response is build
if (items.size > 1) { if (items.size == 1) {
// Select the one we want
GroupActivity.launchForEntrySelectionResult(this, searchInfo)
} else {
populateKeyboardAndMoveAppToBackground(this@PasswordActivity, populateKeyboardAndMoveAppToBackground(this@PasswordActivity,
items[0], items[0],
intent) intent)
} else {
// Select the one we want
GroupActivity.launchForEntrySelectionResult(this, searchInfo)
} }
}, },
{ {