fix(search): Disable zero state if history is disabled

This commit is contained in:
SuperDragonXD
2025-12-21 21:05:10 +08:00
parent 2309ac69b4
commit b5f44f175f

View File

@@ -91,44 +91,36 @@ class LawnchairLocalSearchAlgorithm(context: Context) : LawnchairSearchAlgorithm
override fun doZeroStateSearch(callback: SearchCallback<BaseAllAppsAdapter.AdapterItem>) { override fun doZeroStateSearch(callback: SearchCallback<BaseAllAppsAdapter.AdapterItem>) {
currentJob?.cancel() currentJob?.cancel()
currentJob = coroutineScope.launch {
val prefs = PreferenceManager.getInstance(context)
val prefs2 = PreferenceManager2.getInstance(context)
val historyEnabled = prefs.searchResulRecentSuggestion.get() val prefs = PreferenceManager.getInstance(context)
val maxHistory = prefs2.maxRecentResultCount.firstBlocking() val historyEnabled = prefs.searchResulRecentSuggestion.get()
val historyResults = if (historyEnabled) { if (!historyEnabled) {
historySearchProvider.getRecentKeywords(context, maxHistory) callback.clearSearchResult()
} else { } else {
emptyList() currentJob = coroutineScope.launch {
} val prefs2 = PreferenceManager2.getInstance(context)
val maxHistory = prefs2.maxRecentResultCount.firstBlocking()
val resultsToTranslate = if (historyResults.isNotEmpty()) { val historyResults = historySearchProvider.getRecentKeywords(context, maxHistory)
historyResults + listOf(SearchResult.Action.SearchSettings)
} else { val resultsToTranslate = if (historyResults.isNotEmpty()) {
listOf( historyResults + listOf(SearchResult.Action.SearchSettings)
if (historyEnabled) { } else {
// State A: No History listOf(
SearchResult.Action.EmptyState( SearchResult.Action.EmptyState(
titleRes = R.string.search_empty_state_title, titleRes = R.string.search_empty_state_title,
subtitleRes = R.string.search_empty_state_no_history_subtitle, subtitleRes = R.string.search_empty_state_no_history_subtitle,
) ),
} else { SearchResult.Action.SearchSettings,
// State B: History Disabled )
SearchResult.Action.EmptyState( }
titleRes = R.string.search_empty_state_title,
subtitleRes = R.string.search_empty_state_history_disabled_subtitle,
)
},
SearchResult.Action.SearchSettings,
)
}
val searchTargets = translateToSearchTargets(resultsToTranslate) val searchTargets = translateToSearchTargets(resultsToTranslate)
val adapterItems = transformSearchResults(searchTargets) val adapterItems = transformSearchResults(searchTargets)
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
callback.onSearchResult("", ArrayList(adapterItems)) callback.onSearchResult("", ArrayList(adapterItems))
}
} }
} }
} }