Fix autofill auto search

This commit is contained in:
J-Jamet
2020-04-07 21:01:26 +02:00
parent 456bc22138
commit d77635e572
4 changed files with 57 additions and 23 deletions

View File

@@ -33,6 +33,8 @@ import android.widget.RemoteViews
import androidx.annotation.RequiresApi
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.activities.helpers.EntrySelectionHelper
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.search.SearchHelper
import com.kunzisoft.keepass.model.EntryInfo
import com.kunzisoft.keepass.model.SearchInfo
@@ -125,6 +127,32 @@ object AutofillHelper {
}
}
/**
* Utility method to perform actions if item is found or not after an auto search in [database]
*/
fun checkAutoSearchInfo(activity: Activity,
database: Database,
searchInfo: SearchInfo?,
onItemFound: () -> Unit,
onItemNotFound: () -> Unit) {
var searchWithoutUI = false
if (searchInfo != null) {
// If search provide results
database.createVirtualGroupFromSearch(searchInfo, SearchHelper.MAX_SEARCH_ENTRY)?.let { searchGroup ->
if (searchGroup.getNumberOfChildEntries() > 0) {
// Build response with the entry selected
buildResponse(activity,
searchGroup.getChildEntriesInfo(database))
searchWithoutUI = true
onItemFound.invoke()
}
}
}
if (!searchWithoutUI) {
onItemNotFound.invoke()
}
}
/**
* Utility method to start an activity with an Autofill for result
*/