Skip to content

Commit

Permalink
Fix: Fixed the search in all apps feature.
Browse files Browse the repository at this point in the history
Made it so it will now open opens if searching has found any in the list it will open the first one.
  • Loading branch information
CreativeCodeCat committed May 26, 2024
1 parent 355a7cd commit db64779
Showing 1 changed file with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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%"
Expand All @@ -187,6 +208,7 @@ class DrawFragment : Fragment(),
}
}


private fun showSelectedApp(appInfo: AppInfo) {
binding.searchViewText.setQuery("", false)

Expand Down

0 comments on commit db64779

Please sign in to comment.