Change search result order for all other categories
This commit is contained in:
@@ -264,14 +264,6 @@ internal class AppRepositoryImpl(
|
||||
}
|
||||
}
|
||||
|
||||
private fun matches(label: String, query: String): Boolean {
|
||||
val normalizedLabel = label.normalize()
|
||||
val normalizedQuery = query.normalize()
|
||||
if (normalizedLabel.contains(normalizedQuery)) return true
|
||||
val fuzzyScore = FuzzyScore(Locale.getDefault())
|
||||
return fuzzyScore.fuzzyScore(normalizedLabel, normalizedQuery) >= query.length * 1.5
|
||||
}
|
||||
|
||||
private fun getActivityByComponentName(componentName: ComponentName?): LauncherApp? {
|
||||
componentName ?: return null
|
||||
val intent = Intent().setComponent(componentName)
|
||||
|
||||
@@ -41,7 +41,7 @@ internal data class LauncherApp(
|
||||
override val isSuspended: Boolean = false,
|
||||
internal val userSerialNumber: Long,
|
||||
override val labelOverride: String? = null,
|
||||
override val score: ResultScore = ResultScore.Zero,
|
||||
override val score: ResultScore = ResultScore.Unspecified,
|
||||
) : Application {
|
||||
|
||||
override val componentName: ComponentName
|
||||
@@ -50,7 +50,7 @@ internal data class LauncherApp(
|
||||
override val label: String = launcherActivityInfo.label.toString()
|
||||
|
||||
|
||||
constructor(context: Context, launcherActivityInfo: LauncherActivityInfo, score: ResultScore = ResultScore.Zero) : this(
|
||||
constructor(context: Context, launcherActivityInfo: LauncherActivityInfo, score: ResultScore = ResultScore.Unspecified) : this(
|
||||
launcherActivityInfo,
|
||||
versionName = getPackageVersionName(context, launcherActivityInfo.applicationInfo.packageName),
|
||||
isSuspended = launcherActivityInfo.applicationInfo.flags and ApplicationInfo.FLAG_SUSPENDED != 0,
|
||||
|
||||
+13
-14
@@ -14,6 +14,7 @@ import de.mm20.launcher2.permissions.PermissionGroup
|
||||
import de.mm20.launcher2.permissions.PermissionsManager
|
||||
import de.mm20.launcher2.preferences.search.ShortcutSearchSettings
|
||||
import de.mm20.launcher2.search.AppShortcut
|
||||
import de.mm20.launcher2.search.ResultScore
|
||||
import de.mm20.launcher2.search.SearchableRepository
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
@@ -141,22 +142,20 @@ internal class AppShortcutRepositoryImpl(
|
||||
LauncherApps.ShortcutQuery.FLAG_MATCH_PINNED_BY_ANY_LAUNCHER
|
||||
)
|
||||
val shortcuts = launcherApps.getShortcuts(shortcutQuery, Process.myUserHandle())
|
||||
?.filter {
|
||||
if (it.longLabel != null) {
|
||||
return@filter matches(it.longLabel.toString(), query)
|
||||
}
|
||||
if (it.shortLabel != null) {
|
||||
return@filter matches(it.shortLabel.toString(), query)
|
||||
}
|
||||
return@filter false
|
||||
?.mapNotNull {
|
||||
val score = ResultScore(
|
||||
query = query,
|
||||
primaryFields = listOfNotNull(it.longLabel?.toString(), it.shortLabel?.toString())
|
||||
)
|
||||
if (score.score < 0.8f) return@mapNotNull null
|
||||
LauncherShortcut(
|
||||
context,
|
||||
it,
|
||||
score
|
||||
)
|
||||
} ?: emptyList()
|
||||
|
||||
shortcuts.mapNotNull {
|
||||
LauncherShortcut(
|
||||
context,
|
||||
it
|
||||
)
|
||||
}.toImmutableList()
|
||||
shortcuts.toImmutableList()
|
||||
|
||||
} else {
|
||||
persistentListOf()
|
||||
|
||||
@@ -19,6 +19,7 @@ import de.mm20.launcher2.icons.*
|
||||
import de.mm20.launcher2.ktx.getSerialNumber
|
||||
import de.mm20.launcher2.ktx.isAtLeastApiLevel
|
||||
import de.mm20.launcher2.search.AppShortcut
|
||||
import de.mm20.launcher2.search.ResultScore
|
||||
import de.mm20.launcher2.search.SearchableSerializer
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
@@ -32,6 +33,7 @@ internal data class LauncherShortcut(
|
||||
override val appName: String?,
|
||||
internal val userSerialNumber: Long,
|
||||
override val labelOverride: String? = null,
|
||||
override val score: ResultScore = ResultScore.Unspecified,
|
||||
) : AppShortcut {
|
||||
|
||||
override val domain: String = Domain
|
||||
@@ -47,6 +49,7 @@ internal data class LauncherShortcut(
|
||||
constructor(
|
||||
context: Context,
|
||||
launcherShortcut: ShortcutInfo,
|
||||
score: ResultScore = ResultScore.Unspecified,
|
||||
): this(
|
||||
launcherShortcut = launcherShortcut,
|
||||
appName = try {
|
||||
@@ -55,7 +58,8 @@ internal data class LauncherShortcut(
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
null
|
||||
},
|
||||
userSerialNumber = launcherShortcut.userHandle.getSerialNumber(context)
|
||||
userSerialNumber = launcherShortcut.userHandle.getSerialNumber(context),
|
||||
score = score,
|
||||
)
|
||||
|
||||
override val label: String
|
||||
|
||||
@@ -87,7 +87,7 @@ class PluginFileProvider(
|
||||
uri = cursor[FileColumns.ContentUri]?.let { Uri.parse(it) } ?: continue,
|
||||
thumbnailUri = cursor[FileColumns.ThumbnailUri]?.let { Uri.parse(it) },
|
||||
storageStrategy = config.storageStrategy,
|
||||
isDirectory = cursor[FileColumns.IsDirectory] ?: false,
|
||||
isDirectory = cursor[FileColumns.IsDirectory] == true,
|
||||
authority = pluginAuthority,
|
||||
timestamp = timestamp,
|
||||
updatedSelf = {
|
||||
|
||||
Reference in New Issue
Block a user