Change search result order for all other categories
This commit is contained in:
+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
|
||||
|
||||
Reference in New Issue
Block a user