Sort apps that failed to install by name

This commit is contained in:
Torsten Grote 2024-05-20 15:35:38 -03:00
parent 56d8d64261
commit 1667d44967
No known key found for this signature in database
GPG key ID: 3E5F77D92CF891FF
2 changed files with 10 additions and 5 deletions

View file

@ -66,6 +66,7 @@ internal class ApkRestore(
packageName = packageName,
progress = progress,
state = if (isAllowedToInstallApks) QUEUED else FAILED,
name = metadata.name?.toString(),
installerPackageName = metadata.installer
)
}
@ -153,7 +154,7 @@ internal class ApkRestore(
publicSourceDir = cachedApk.absolutePath
}
val icon = appInfo?.loadIcon(pm)
val name = appInfo?.let { pm.getApplicationLabel(it) }
val name = appInfo?.let { pm.getApplicationLabel(it).toString() }
installResult.update(packageName) { result ->
result.copy(state = IN_PROGRESS, name = name, icon = icon)

View file

@ -118,10 +118,10 @@ internal class MutableInstallResult(override val total: Int) : InstallResult {
}
data class ApkInstallResult(
val packageName: CharSequence,
val packageName: String,
val progress: Int,
val state: ApkInstallState,
val name: CharSequence? = null,
val name: String? = null,
val icon: Drawable? = null,
val installerPackageName: CharSequence? = null,
) : Comparable<ApkInstallResult> {
@ -132,9 +132,13 @@ data class ApkInstallResult(
internal class FailedFirstComparator : Comparator<ApkInstallResult> {
override fun compare(a1: ApkInstallResult, a2: ApkInstallResult): Int {
return (if (a1.state == FAILED && a2.state != FAILED) -1
return if (a1.state == FAILED && a2.state != FAILED) -1
else if (a2.state == FAILED && a1.state != FAILED) 1
else a1.compareTo(a2))
else {
val str = a1.name ?: a1.packageName
val otherStr = a2.name ?: a2.packageName
str.compareTo(otherStr, true)
}
}
}