parent
d2cdbbc7c4
commit
b6f6c0c584
@ -44,6 +44,8 @@ dependencies {
|
||||
|
||||
implementation(libs.commons.text)
|
||||
|
||||
implementation(libs.tinypinyin)
|
||||
|
||||
implementation(project(":search"))
|
||||
implementation(project(":base"))
|
||||
implementation(project(":preferences"))
|
||||
|
||||
@ -11,6 +11,7 @@ import android.os.Process
|
||||
import android.os.UserHandle
|
||||
import android.os.UserManager
|
||||
import android.util.Log
|
||||
import com.github.promeg.pinyinhelper.Pinyin
|
||||
import de.mm20.launcher2.hiddenitems.HiddenItemsRepository
|
||||
import de.mm20.launcher2.search.data.AppInstallation
|
||||
import de.mm20.launcher2.search.data.Application
|
||||
@ -189,18 +190,17 @@ internal class AppRepositoryImpl(
|
||||
override fun search(query: String): Flow<List<Application>> = channelFlow {
|
||||
|
||||
merge(installedApps, hiddenItems, installations).collectLatest {
|
||||
withContext(Dispatchers.IO) {
|
||||
val fuzzyScore = FuzzyScore(Locale.getDefault())
|
||||
withContext(Dispatchers.Default) {
|
||||
val appResults = mutableListOf<Application>()
|
||||
if (query.isEmpty()) {
|
||||
appResults.addAll(installedApps.value)
|
||||
appResults.addAll(installations.value)
|
||||
} else {
|
||||
appResults.addAll(installedApps.value.filter {
|
||||
fuzzyScore.fuzzyScore(it.label, query) >= query.length * 1.5
|
||||
matches(it.label, query)
|
||||
})
|
||||
appResults.addAll(installations.value.filter {
|
||||
fuzzyScore.fuzzyScore(it.label, query) >= query.length * 1.5
|
||||
matches(it.label, query)
|
||||
})
|
||||
}
|
||||
|
||||
@ -216,6 +216,17 @@ internal class AppRepositoryImpl(
|
||||
}
|
||||
}
|
||||
|
||||
private fun matches(label: String, query: String): Boolean {
|
||||
val labelLatin = romanize(label)
|
||||
val fuzzyScore = FuzzyScore(Locale.getDefault())
|
||||
return fuzzyScore.fuzzyScore(label, query) >= query.length * 1.5 ||
|
||||
fuzzyScore.fuzzyScore(labelLatin, query) >= query.length * 1.5
|
||||
}
|
||||
|
||||
private fun romanize(label: String): String {
|
||||
return Pinyin.toPinyin(label, "").lowercase(Locale.getDefault())
|
||||
}
|
||||
|
||||
private fun getActivityByComponentName(componentName: ComponentName?): Application? {
|
||||
componentName ?: return null
|
||||
val intent = Intent().setComponent(componentName)
|
||||
|
||||
@ -194,4 +194,11 @@ val OpenSourceLicenses = arrayOf(
|
||||
licenseText = R.raw.license_apache_2,
|
||||
url = "https://commons.apache.org/proper/commons-text/"
|
||||
),
|
||||
OpenSourceLibrary(
|
||||
name = "TinyPinyin",
|
||||
description = "A fast, low-memory Chinese character-to-pinyin library for Java and Android.",
|
||||
licenseName = R.string.apache_license_name,
|
||||
licenseText = R.raw.license_apache_2,
|
||||
url = "https://github.com/promeG/TinyPinyin"
|
||||
),
|
||||
)
|
||||
@ -375,6 +375,10 @@ dependencyResolutionManagement {
|
||||
alias("koin.androidxcompose")
|
||||
.to("io.insert-koin", "koin-androidx-compose")
|
||||
.versionRef("koin")
|
||||
|
||||
alias("tinypinyin")
|
||||
.to("com.github.promeg", "tinypinyin")
|
||||
.version("2.0.2")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user