Improve backup notification
This commit is contained in:
parent
fcd4e518a5
commit
49066be31b
2 changed files with 19 additions and 13 deletions
|
@ -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())
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue