Reuse collator instance
This commit is contained in:
parent
9b252cb5e8
commit
90de026e49
@ -6,7 +6,7 @@ import android.os.Bundle
|
|||||||
import de.mm20.launcher2.icons.LauncherIcon
|
import de.mm20.launcher2.icons.LauncherIcon
|
||||||
import de.mm20.launcher2.icons.StaticLauncherIcon
|
import de.mm20.launcher2.icons.StaticLauncherIcon
|
||||||
import de.mm20.launcher2.ktx.romanize
|
import de.mm20.launcher2.ktx.romanize
|
||||||
import java.text.Collator
|
import de.mm20.launcher2.text.Collator
|
||||||
|
|
||||||
interface SavableSearchable : Searchable, Comparable<SavableSearchable> {
|
interface SavableSearchable : Searchable, Comparable<SavableSearchable> {
|
||||||
val key: String
|
val key: String
|
||||||
@ -37,8 +37,7 @@ interface SavableSearchable : Searchable, Comparable<SavableSearchable> {
|
|||||||
override fun compareTo(other: SavableSearchable): Int {
|
override fun compareTo(other: SavableSearchable): Int {
|
||||||
val label1 = labelOverride ?: label
|
val label1 = labelOverride ?: label
|
||||||
val label2 = other.labelOverride ?: other.label
|
val label2 = other.labelOverride ?: other.label
|
||||||
return Collator.getInstance().apply { strength = Collator.SECONDARY }
|
return Collator.compare(label1.romanize(), label2.romanize())
|
||||||
.compare(label1.romanize(), label2.romanize())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val domain: String
|
val domain: String
|
||||||
|
|||||||
17
core/base/src/main/java/de/mm20/launcher2/text/Collator.kt
Normal file
17
core/base/src/main/java/de/mm20/launcher2/text/Collator.kt
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package de.mm20.launcher2.text
|
||||||
|
|
||||||
|
import android.icu.text.Collator
|
||||||
|
import kotlin.concurrent.getOrSet
|
||||||
|
|
||||||
|
|
||||||
|
private val threadLocalCollator = ThreadLocal.withInitial {
|
||||||
|
android.icu.text.Collator.getInstance().apply {
|
||||||
|
strength = android.icu.text.Collator.SECONDARY
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val Collator = threadLocalCollator.getOrSet {
|
||||||
|
android.icu.text.Collator.getInstance().apply {
|
||||||
|
strength = android.icu.text.Collator.SECONDARY
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -9,9 +9,9 @@ import android.os.Process
|
|||||||
import androidx.core.content.getSystemService
|
import androidx.core.content.getSystemService
|
||||||
import de.mm20.launcher2.ktx.romanize
|
import de.mm20.launcher2.ktx.romanize
|
||||||
import de.mm20.launcher2.search.AppProfile
|
import de.mm20.launcher2.search.AppProfile
|
||||||
|
import de.mm20.launcher2.text.Collator
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.flow
|
import kotlinx.coroutines.flow.flow
|
||||||
import java.text.Collator
|
|
||||||
|
|
||||||
class AppShortcutConfigActivity(
|
class AppShortcutConfigActivity(
|
||||||
private val launcherActivityInfo: LauncherActivityInfo,
|
private val launcherActivityInfo: LauncherActivityInfo,
|
||||||
@ -32,7 +32,6 @@ class AppShortcutConfigActivity(
|
|||||||
|
|
||||||
val label1 = label
|
val label1 = label
|
||||||
val label2 = other.label
|
val label2 = other.label
|
||||||
return Collator.getInstance().apply { strength = Collator.SECONDARY }
|
return Collator.compare(label1.romanize(), label2.romanize())
|
||||||
.compare(label1.romanize(), label2.romanize())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user