From 1667d449677995c0b84554810edda587e482da92 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Mon, 20 May 2024 15:35:38 -0300 Subject: [PATCH] Sort apps that failed to install by name --- .../seedvault/restore/install/ApkRestore.kt | 3 ++- .../seedvault/restore/install/InstallResult.kt | 12 ++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/stevesoltys/seedvault/restore/install/ApkRestore.kt b/app/src/main/java/com/stevesoltys/seedvault/restore/install/ApkRestore.kt index 6fc01437..5bf606a5 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/restore/install/ApkRestore.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/restore/install/ApkRestore.kt @@ -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) diff --git a/app/src/main/java/com/stevesoltys/seedvault/restore/install/InstallResult.kt b/app/src/main/java/com/stevesoltys/seedvault/restore/install/InstallResult.kt index bdfb96f9..0da7b37c 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/restore/install/InstallResult.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/restore/install/InstallResult.kt @@ -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 { @@ -132,9 +132,13 @@ data class ApkInstallResult( internal class FailedFirstComparator : Comparator { 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) + } } }