From db64779260787861c87da233bcf768f9e8f27926 Mon Sep 17 00:00:00 2001 From: HeCodes2Much Date: Sun, 26 May 2024 09:35:22 +0100 Subject: [PATCH] Fix: Fixed the search in all apps feature. Made it so it will now open opens if searching has found any in the list it will open the first one. --- .../launcher/ui/drawer/DrawFragment.kt | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/github/droidworksstudio/launcher/ui/drawer/DrawFragment.kt b/app/src/main/java/com/github/droidworksstudio/launcher/ui/drawer/DrawFragment.kt index 733a3a7a..67bdb85e 100644 --- a/app/src/main/java/com/github/droidworksstudio/launcher/ui/drawer/DrawFragment.kt +++ b/app/src/main/java/com/github/droidworksstudio/launcher/ui/drawer/DrawFragment.kt @@ -118,9 +118,7 @@ class DrawFragment : Fragment(), val searchQuery = trimmedQuery.substringAfter("!") requireContext().searchCustomSearchEngine(searchQuery) } else { - if (!requireContext().searchOnPlayStore(trimmedQuery)) { - requireContext().openSearch(trimmedQuery) - } + checkAppThenRun(trimmedQuery) return true // Exit the function } } @@ -163,6 +161,29 @@ class DrawFragment : Fragment(), } } + private fun checkAppThenRun(query: String) { + val searchQuery = "%$query%" + @Suppress("DEPRECATION") + viewLifecycleOwner.lifecycle.coroutineScope.launchWhenCreated { + val trimmedQuery = searchQuery.trim() + viewModel.searchAppInfo(trimmedQuery).collect { searchResults -> + val numberOfItemsLeft = searchResults.size + val appResults = searchResults.firstOrNull() + if (numberOfItemsLeft == 0 && !requireContext().searchOnPlayStore( + trimmedQuery + ) + ) { + requireContext().openSearch(trimmedQuery) + } else { + appResults?.let { appInfo -> + observeBioAuthCheck(appInfo) + } + drawAdapter.submitList(searchResults) + } + } + } + } + private fun searchApp(query: String) { val searchQuery = "%$query%" @@ -187,6 +208,7 @@ class DrawFragment : Fragment(), } } + private fun showSelectedApp(appInfo: AppInfo) { binding.searchViewText.setQuery("", false)