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,36 +91,27 @@ class LawnchairLocalSearchAlgorithm(context: Context) : LawnchairSearchAlgorithm
override fun doZeroStateSearch(callback: SearchCallback<BaseAllAppsAdapter.AdapterItem>) {
currentJob?.cancel()
currentJob = coroutineScope.launch {
val prefs = PreferenceManager.getInstance(context)
val prefs2 = PreferenceManager2.getInstance(context)
val prefs = PreferenceManager.getInstance(context)
val historyEnabled = prefs.searchResulRecentSuggestion.get()
if (!historyEnabled) {
callback.clearSearchResult()
} else {
currentJob = coroutineScope.launch {
val prefs2 = PreferenceManager2.getInstance(context)
val maxHistory = prefs2.maxRecentResultCount.firstBlocking()
val historyResults = if (historyEnabled) {
historySearchProvider.getRecentKeywords(context, maxHistory)
} else {
emptyList()
}
val historyResults = historySearchProvider.getRecentKeywords(context, maxHistory)
val resultsToTranslate = if (historyResults.isNotEmpty()) {
historyResults + listOf(SearchResult.Action.SearchSettings)
} else {
listOf(
if (historyEnabled) {
// State A: No History
SearchResult.Action.EmptyState(
titleRes = R.string.search_empty_state_title,
subtitleRes = R.string.search_empty_state_no_history_subtitle,
)
} else {
// 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,
)
}
@@ -132,6 +123,7 @@ class LawnchairLocalSearchAlgorithm(context: Context) : LawnchairSearchAlgorithm
}
}
}
}
override fun cancel(interruptActiveRequests: Boolean) {
currentJob?.cancel()