feat: app list sort by pinyin
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
## 0.2.7
|
## 0.2.7
|
||||||
|
|
||||||
- 新增: 日志框隐藏
|
- 新增: 日志框隐藏
|
||||||
|
- 新增: 应用列表按拼音排序
|
||||||
|
|
||||||
## 0.2.6
|
## 0.2.6
|
||||||
|
|
||||||
|
|||||||
@@ -56,8 +56,8 @@ android {
|
|||||||
applicationId = "io.github.miuzarte.scrcpyforandroid"
|
applicationId = "io.github.miuzarte.scrcpyforandroid"
|
||||||
minSdk = 26
|
minSdk = 26
|
||||||
targetSdk = 37
|
targetSdk = 37
|
||||||
versionCode = 22
|
versionCode = 23
|
||||||
versionName = "0.2.6"
|
versionName = "0.2.7"
|
||||||
|
|
||||||
externalNativeBuild {
|
externalNativeBuild {
|
||||||
cmake {
|
cmake {
|
||||||
@@ -151,6 +151,7 @@ dependencies {
|
|||||||
implementation(libs.androidx.compose.runtime)
|
implementation(libs.androidx.compose.runtime)
|
||||||
implementation(libs.androidx.biometric)
|
implementation(libs.androidx.biometric)
|
||||||
implementation(libs.androidx.security.crypto)
|
implementation(libs.androidx.security.crypto)
|
||||||
|
implementation("com.github.promeg:tinypinyin:2.0.3")
|
||||||
|
|
||||||
testImplementation(libs.junit)
|
testImplementation(libs.junit)
|
||||||
androidTestImplementation(platform(libs.androidx.compose.bom))
|
androidTestImplementation(platform(libs.androidx.compose.bom))
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import android.net.Uri
|
|||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.KeyEvent
|
import android.view.KeyEvent
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
|
import com.github.promeg.pinyinhelper.Pinyin
|
||||||
import io.github.miuzarte.scrcpyforandroid.NativeCoreFacade
|
import io.github.miuzarte.scrcpyforandroid.NativeCoreFacade
|
||||||
import io.github.miuzarte.scrcpyforandroid.constants.Defaults
|
import io.github.miuzarte.scrcpyforandroid.constants.Defaults
|
||||||
import io.github.miuzarte.scrcpyforandroid.nativecore.AdbSocketStream
|
import io.github.miuzarte.scrcpyforandroid.nativecore.AdbSocketStream
|
||||||
@@ -42,6 +43,7 @@ import java.io.EOFException
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.InputStreamReader
|
import java.io.InputStreamReader
|
||||||
import java.util.ArrayDeque
|
import java.util.ArrayDeque
|
||||||
|
import java.util.Locale
|
||||||
import kotlin.concurrent.thread
|
import kotlin.concurrent.thread
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
@@ -813,9 +815,55 @@ class Scrcpy(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return apps.toList()
|
return apps.toList().sortedBy { appSortKey(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun appSortKey(app: AppInfo): String {
|
||||||
|
val label = app.label?.takeIf { it.isNotBlank() } ?: app.packageName
|
||||||
|
val tokens = label.map { char ->
|
||||||
|
when {
|
||||||
|
char.code <= 0x7F -> AppSortToken(
|
||||||
|
priority = 0,
|
||||||
|
value = char.lowercaseChar().toString(),
|
||||||
|
)
|
||||||
|
|
||||||
|
Pinyin.isChinese(char) -> AppSortToken(
|
||||||
|
priority = 1,
|
||||||
|
value = Pinyin.toPinyin(char).lowercase(Locale.ROOT),
|
||||||
|
)
|
||||||
|
|
||||||
|
else -> AppSortToken(
|
||||||
|
priority = 2,
|
||||||
|
value = char.lowercaseChar().toString(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val firstToken = tokens.firstOrNull { it.value.any(Char::isLetterOrDigit) }
|
||||||
|
?: tokens.firstOrNull()
|
||||||
|
val firstLetter = firstToken
|
||||||
|
?.value
|
||||||
|
?.firstOrNull(Char::isLetterOrDigit)
|
||||||
|
?: Char.MAX_VALUE
|
||||||
|
|
||||||
|
return buildString {
|
||||||
|
append(firstLetter)
|
||||||
|
append('\u0000')
|
||||||
|
append(firstToken?.priority ?: 2)
|
||||||
|
append('\u0000')
|
||||||
|
tokens.forEach { token ->
|
||||||
|
append(token.value)
|
||||||
|
append('\u0000')
|
||||||
|
}
|
||||||
|
append('\u0001')
|
||||||
|
append(app.packageName.lowercase(Locale.ROOT))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private data class AppSortToken(
|
||||||
|
val priority: Int,
|
||||||
|
val value: String,
|
||||||
|
)
|
||||||
|
|
||||||
private fun parseRecentTasks(output: String): List<RecentTaskInfo> {
|
private fun parseRecentTasks(output: String): List<RecentTaskInfo> {
|
||||||
val packages = LinkedHashSet<String>()
|
val packages = LinkedHashSet<String>()
|
||||||
RECENT_TASK_PACKAGE_REGEX.findAll(output).forEach { match ->
|
RECENT_TASK_PACKAGE_REGEX.findAll(output).forEach { match ->
|
||||||
|
|||||||
@@ -18,6 +18,12 @@ dependencyResolutionManagement {
|
|||||||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||||
repositories {
|
repositories {
|
||||||
google()
|
google()
|
||||||
|
maven {
|
||||||
|
url = uri("https://maven.aliyun.com/repository/public")
|
||||||
|
content {
|
||||||
|
includeGroup("com.github.promeg")
|
||||||
|
}
|
||||||
|
}
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user