diff --git a/app/src/main/java/com/stevesoltys/seedvault/ui/notification/BackupNotificationManager.kt b/app/src/main/java/com/stevesoltys/seedvault/ui/notification/BackupNotificationManager.kt index 9a97b488..0a8bc09d 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/ui/notification/BackupNotificationManager.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/ui/notification/BackupNotificationManager.kt @@ -133,7 +133,7 @@ internal class BackupNotificationManager(private val context: Context) { */ fun onBackupStarted(expectedPackages: Int) { updateBackupNotification( - infoText = "", // This passes quickly, no need to show something here + appName = "", // This passes quickly, no need to show something here transferred = 0, expected = expectedPackages ) @@ -146,25 +146,21 @@ internal class BackupNotificationManager(private val context: Context) { */ fun onBackupUpdate(app: CharSequence, transferred: Int, total: Int) { updateBackupNotification( - infoText = app, + appName = app, transferred = min(transferred, total), expected = total ) } private fun updateBackupNotification( - infoText: CharSequence, + appName: CharSequence, transferred: Int, expected: Int, ) { - @Suppress("MagicNumber") - val percentage = (transferred.toFloat() / expected) * 100 - val percentageStr = "%.0f%%".format(percentage) - Log.i(TAG, "$transferred/$expected - $percentageStr - $infoText") val notification = Builder(context, CHANNEL_ID_OBSERVER).apply { setSmallIcon(R.drawable.ic_cloud_upload) setContentTitle(context.getString(R.string.notification_title)) - setContentText(percentageStr) + setContentText(appName) setOngoing(true) setShowWhen(false) setWhen(System.currentTimeMillis()) diff --git a/app/src/main/java/com/stevesoltys/seedvault/ui/notification/NotificationBackupObserver.kt b/app/src/main/java/com/stevesoltys/seedvault/ui/notification/NotificationBackupObserver.kt index d253970a..ff298207 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/ui/notification/NotificationBackupObserver.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/ui/notification/NotificationBackupObserver.kt @@ -26,6 +26,7 @@ internal class NotificationBackupObserver( private val metadataManager: MetadataManager by inject() private var currentPackage: String? = null private var numPackages: Int = 0 + private var pmCounted: Boolean = false init { // Inform the notification manager that a backup has started @@ -93,13 +94,22 @@ internal class NotificationBackupObserver( ) currentPackage = packageName val appName = getAppName(packageName) - val app = if (appName != packageName) { - "${getAppName(packageName)} ($packageName)" + val name = if (appName != packageName) { + appName } else { - packageName + context.getString(R.string.backup_section_system) } - numPackages += 1 - nm.onBackupUpdate(app, numPackages, requestedPackages) + // prevent double counting of @pm@ which gets backed up with each requested chunk + if (packageName == MAGIC_PACKAGE_MANAGER) { + if (!pmCounted) { + numPackages += 1 + pmCounted = true + } + } else { + numPackages += 1 + } + Log.i(TAG, "$numPackages/$requestedPackages - $appName ($packageName)") + nm.onBackupUpdate(name, numPackages, requestedPackages) } private fun getAppName(packageId: String): CharSequence = getAppName(context, packageId)