@@ -415,6 +415,7 @@ class PreferenceManager2 private constructor(private val context: Context) : Pre
|
||||
val matchHotseatQsbStyle = preference(
|
||||
key = booleanPreferencesKey(name = "use_drawer_search_icon"),
|
||||
defaultValue = false,
|
||||
onSet = { reloadHelper.recreate() },
|
||||
)
|
||||
|
||||
val webSuggestionProvider = preference(
|
||||
|
||||
@@ -53,8 +53,6 @@ class LawnchairAppSearchAlgorithm(context: Context) : LawnchairSearchAlgorithm(c
|
||||
}
|
||||
}
|
||||
|
||||
private val searchUtils = SearchUtils(maxResultsCount, hiddenApps, hiddenAppsInSearch)
|
||||
|
||||
override fun doSearch(query: String, callback: SearchCallback<BaseAllAppsAdapter.AdapterItem>) {
|
||||
appState.model.enqueueModelUpdateTask(object : BaseModelUpdateTask() {
|
||||
override fun execute(app: LauncherAppState, dataModel: BgDataModel, apps: AllAppsList) {
|
||||
@@ -77,9 +75,9 @@ class LawnchairAppSearchAlgorithm(context: Context) : LawnchairSearchAlgorithm(c
|
||||
query: String,
|
||||
): ArrayList<BaseAllAppsAdapter.AdapterItem> {
|
||||
val appResults = if (enableFuzzySearch) {
|
||||
searchUtils.fuzzySearch(apps, query)
|
||||
SearchUtils.fuzzySearch(apps, query, maxResultsCount, hiddenApps, hiddenAppsInSearch)
|
||||
} else {
|
||||
searchUtils.normalSearch(apps, query)
|
||||
SearchUtils.normalSearch(apps, query, maxResultsCount, hiddenApps, hiddenAppsInSearch)
|
||||
}
|
||||
|
||||
val searchTargets = mutableListOf<SearchTargetCompat>()
|
||||
@@ -89,7 +87,7 @@ class LawnchairAppSearchAlgorithm(context: Context) : LawnchairSearchAlgorithm(c
|
||||
|
||||
if (appResults.size == 1 && context.isDefaultLauncher()) {
|
||||
val singleAppResult = appResults.firstOrNull()
|
||||
val shortcuts = singleAppResult?.let { searchUtils.getShortcuts(it, context) }
|
||||
val shortcuts = singleAppResult?.let { SearchUtils.getShortcuts(it, context) }
|
||||
if (shortcuts != null) {
|
||||
if (shortcuts.isNotEmpty()) {
|
||||
searchTargets.add(searchTargetFactory.createHeaderTarget(SPACE))
|
||||
|
||||
@@ -122,8 +122,6 @@ class LawnchairLocalSearchAlgorithm(context: Context) : LawnchairSearchAlgorithm
|
||||
}
|
||||
}
|
||||
|
||||
private val searchUtils = SearchUtils(maxAppResultsCount, hiddenApps, hiddenAppsInSearch)
|
||||
|
||||
override fun doSearch(query: String, callback: SearchCallback<BaseAllAppsAdapter.AdapterItem>) {
|
||||
appState.model.enqueueModelUpdateTask(object : BaseModelUpdateTask() {
|
||||
override fun execute(app: LauncherAppState, dataModel: BgDataModel, apps: AllAppsList) {
|
||||
@@ -151,10 +149,12 @@ class LawnchairLocalSearchAlgorithm(context: Context) : LawnchairSearchAlgorithm
|
||||
var appIndex = 0
|
||||
|
||||
launch {
|
||||
getAppSearchResults(apps, query).collect { appResults ->
|
||||
allResults.addAll(appResults)
|
||||
appIndex = appResults.size
|
||||
send(allResults.toList())
|
||||
if (searchApps) {
|
||||
getAppSearchResults(apps, query).collect { appResults ->
|
||||
allResults.addAll(appResults)
|
||||
appIndex = appResults.size
|
||||
send(allResults.toList())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ class LawnchairLocalSearchAlgorithm(context: Context) : LawnchairSearchAlgorithm
|
||||
|
||||
if (appResults.size == 1 && context.isDefaultLauncher()) {
|
||||
val singleAppResult = appResults.firstOrNull()
|
||||
val shortcuts = singleAppResult?.let { searchUtils.getShortcuts(it, context) }
|
||||
val shortcuts = singleAppResult?.let { SearchUtils.getShortcuts(it, context) }
|
||||
if (shortcuts != null) {
|
||||
if (shortcuts.isNotEmpty()) {
|
||||
searchTargets.add(searchTargetFactory.createHeaderTarget(SPACE))
|
||||
@@ -307,9 +307,9 @@ class LawnchairLocalSearchAlgorithm(context: Context) : LawnchairSearchAlgorithm
|
||||
apps: MutableList<AppInfo>,
|
||||
query: String,
|
||||
) = if (enableFuzzySearch) {
|
||||
searchUtils.fuzzySearch(apps, query)
|
||||
SearchUtils.fuzzySearch(apps, query, maxAppResultsCount, hiddenApps, hiddenAppsInSearch)
|
||||
} else {
|
||||
searchUtils.normalSearch(apps, query)
|
||||
SearchUtils.normalSearch(apps, query, maxAppResultsCount, hiddenApps, hiddenAppsInSearch)
|
||||
}
|
||||
|
||||
private suspend fun performDeviceLocalSearch(query: String, prefs: PreferenceManager): MutableList<SearchResult> =
|
||||
|
||||
@@ -12,12 +12,8 @@ import java.util.Locale
|
||||
import me.xdrop.fuzzywuzzy.FuzzySearch
|
||||
import me.xdrop.fuzzywuzzy.algorithms.WeightedRatio
|
||||
|
||||
class SearchUtils(
|
||||
private val maxResultsCount: Int,
|
||||
private val hiddenApps: Set<String>,
|
||||
private val hiddenAppsInSearch: String,
|
||||
) {
|
||||
fun normalSearch(apps: List<AppInfo>, query: String): List<AppInfo> {
|
||||
object SearchUtils {
|
||||
fun normalSearch(apps: List<AppInfo>, query: String, maxResultsCount: Int, hiddenApps: Set<String>, hiddenAppsInSearch: String): List<AppInfo> {
|
||||
// Do an intersection of the words in the query and each title, and filter out all the
|
||||
// apps that don't match all of the words in the query.
|
||||
val queryTextLower = query.lowercase(Locale.getDefault())
|
||||
@@ -29,7 +25,7 @@ class SearchUtils(
|
||||
.toList()
|
||||
}
|
||||
|
||||
fun fuzzySearch(apps: List<AppInfo>, query: String): List<AppInfo> {
|
||||
fun fuzzySearch(apps: List<AppInfo>, query: String, maxResultsCount: Int, hiddenApps: Set<String>, hiddenAppsInSearch: String): List<AppInfo> {
|
||||
val queryTextLower = query.lowercase(Locale.getDefault())
|
||||
val filteredApps = apps.asSequence()
|
||||
.filterHiddenApps(queryTextLower, hiddenApps, hiddenAppsInSearch)
|
||||
|
||||
+41
-15
@@ -83,23 +83,54 @@ fun SearchSuggestionPreference(
|
||||
description: String? = null,
|
||||
permissionRationale: String? = null,
|
||||
content: @Composable (() -> Unit)? = null,
|
||||
) {
|
||||
SearchSuggestionPreference(
|
||||
checked = adapter.state.value,
|
||||
onCheckedChange = adapter::onChange,
|
||||
enabled = isGranted,
|
||||
maxCountAdapter = maxCountAdapter,
|
||||
maxCountRange = maxCountRange,
|
||||
label = label,
|
||||
maxCountLabel = maxCountLabel,
|
||||
onRequestPermission = onRequestPermission,
|
||||
isGranted = isGranted,
|
||||
description = description,
|
||||
permissionRationale = permissionRationale,
|
||||
content = content,
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun SearchSuggestionPreference(
|
||||
checked: Boolean,
|
||||
onCheckedChange: (Boolean) -> Unit,
|
||||
enabled: Boolean,
|
||||
maxCountAdapter: PreferenceAdapter<Int>,
|
||||
maxCountRange: ClosedRange<Int>,
|
||||
label: String,
|
||||
maxCountLabel: String,
|
||||
onRequestPermission: (() -> Unit)?,
|
||||
isGranted: Boolean = true,
|
||||
description: String? = null,
|
||||
permissionRationale: String? = null,
|
||||
content: @Composable (() -> Unit)? = null,
|
||||
) {
|
||||
val bottomSheetHandler = bottomSheetHandler
|
||||
|
||||
SearchSuggestionsSwitchPreference(
|
||||
label = label,
|
||||
description = description,
|
||||
checked = adapter.state.value,
|
||||
onCheckedChange = adapter::onChange,
|
||||
enabled = isGranted,
|
||||
preventSwitchChange = !isGranted,
|
||||
checked = checked,
|
||||
onCheckedChange = onCheckedChange,
|
||||
enabled = enabled,
|
||||
onClick = {
|
||||
bottomSheetHandler.show {
|
||||
BottomSheetContent(
|
||||
onHide = { bottomSheetHandler.hide() },
|
||||
isPermissionGranted = isGranted,
|
||||
adapterValue = adapter.state.value,
|
||||
adapterOnChange = adapter::onChange,
|
||||
adapterValue = checked,
|
||||
adapterEnabled = enabled,
|
||||
adapterOnChange = onCheckedChange,
|
||||
label = label,
|
||||
maxCountLabel = maxCountLabel,
|
||||
maxCountAdapter = maxCountAdapter,
|
||||
@@ -107,7 +138,6 @@ fun SearchSuggestionPreference(
|
||||
content = content,
|
||||
onRequestPermission = onRequestPermission,
|
||||
permissionRationale = permissionRationale,
|
||||
preventSwitchChange = !isGranted,
|
||||
)
|
||||
}
|
||||
},
|
||||
@@ -118,6 +148,7 @@ fun SearchSuggestionPreference(
|
||||
private fun BottomSheetContent(
|
||||
adapterValue: Boolean,
|
||||
adapterOnChange: (Boolean) -> Unit,
|
||||
adapterEnabled: Boolean,
|
||||
label: String,
|
||||
maxCountLabel: String,
|
||||
maxCountAdapter: PreferenceAdapter<Int>,
|
||||
@@ -126,7 +157,6 @@ private fun BottomSheetContent(
|
||||
onHide: () -> Unit,
|
||||
onRequestPermission: (() -> Unit)?,
|
||||
permissionRationale: String?,
|
||||
preventSwitchChange: Boolean,
|
||||
content: @Composable (() -> Unit)?,
|
||||
) {
|
||||
ModalBottomSheetContent(
|
||||
@@ -140,12 +170,10 @@ private fun BottomSheetContent(
|
||||
MainSwitchPreference(
|
||||
checked = adapterValue,
|
||||
onCheckedChange = {
|
||||
if (!preventSwitchChange) {
|
||||
adapterOnChange(it)
|
||||
}
|
||||
adapterOnChange(it)
|
||||
},
|
||||
label = label,
|
||||
enabled = if (preventSwitchChange) false else isPermissionGranted,
|
||||
enabled = adapterEnabled,
|
||||
) {
|
||||
Column(modifier = Modifier.padding(horizontal = 16.dp)) {
|
||||
SliderPreference(
|
||||
@@ -196,7 +224,6 @@ private fun SearchSuggestionsSwitchPreference(
|
||||
label: String,
|
||||
checked: Boolean,
|
||||
onCheckedChange: (Boolean) -> Unit,
|
||||
preventSwitchChange: Boolean,
|
||||
onClick: () -> Unit,
|
||||
enabled: Boolean,
|
||||
description: String? = null,
|
||||
@@ -225,7 +252,7 @@ private fun SearchSuggestionsSwitchPreference(
|
||||
.height(24.dp),
|
||||
checked = checked,
|
||||
onCheckedChange = { onCheckedChange(it) },
|
||||
enabled = if (preventSwitchChange) false else enabled,
|
||||
enabled = enabled,
|
||||
)
|
||||
},
|
||||
applyPaddings = false,
|
||||
@@ -241,7 +268,6 @@ private fun SearchSuggestionsSwitchPreferencePreview() {
|
||||
checked = true,
|
||||
onClick = { /*TODO*/ },
|
||||
onCheckedChange = {},
|
||||
preventSwitchChange = false,
|
||||
enabled = true,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -77,9 +77,14 @@ fun SearchPreferences() {
|
||||
PreferenceGroup(heading = stringResource(id = R.string.show_search_result_types)) {
|
||||
val searchAlgorithm = preferenceManager2().searchAlgorithm.getAdapter().state.value
|
||||
if (searchAlgorithm != LawnchairSearchAlgorithm.ASI_SEARCH) {
|
||||
@OptIn(ExperimentalPermissionsApi::class)
|
||||
val canDisable = searchAlgorithm != LawnchairSearchAlgorithm.APP_SEARCH
|
||||
val adapter = prefs.searchResultApps.getAdapter()
|
||||
|
||||
SearchSuggestionPreference(
|
||||
adapter = prefs.searchResultApps.getAdapter(),
|
||||
checked = if (canDisable) adapter.state.value else true,
|
||||
onCheckedChange = if (canDisable) adapter::onChange else ({}),
|
||||
enabled = true,
|
||||
onRequestPermission = {},
|
||||
maxCountAdapter = prefs2.maxAppSearchResultCount.getAdapter(),
|
||||
maxCountRange = 3..15,
|
||||
label = stringResource(R.string.search_pref_result_apps_and_shortcuts_title),
|
||||
|
||||
Reference in New Issue
Block a user