diff --git a/app/src/main/java/com/stevesoltys/seedvault/repo/Checker.kt b/app/src/main/java/com/stevesoltys/seedvault/repo/Checker.kt index 374d497a..2ff2c21e 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/repo/Checker.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/repo/Checker.kt @@ -92,11 +92,10 @@ internal class Checker( // only log/show notification after some time has passed (throttling) if (passedTime > lastNotification.get() + 500) { lastNotification.set(passedTime) - val bandwidth = - (newSize / 1024 / (passedTime.toDouble() / 1000)).roundToInt() + val bandwidth = (newSize / (passedTime.toDouble() / 1000)).roundToLong() val thousandth = ((newSize.toDouble() / sampleSize) * 1000).roundToInt() log.debug { "$thousandth‰ - $bandwidth KB/sec - $newSize bytes" } - nm.showCheckNotification("$bandwidth KB/sec", thousandth) + nm.showCheckNotification(bandwidth, thousandth) } } } @@ -104,6 +103,9 @@ internal class Checker( if (sampleSize != size.get()) log.error { "Checked ${size.get()} bytes, but expected $sampleSize" } + val passedTime = System.currentTimeMillis() - startTime + val bandwidth = size.get() / (passedTime.toDouble() / 1000).roundToLong() + nm.onCheckComplete(size.get(), bandwidth) } private fun getBlobSample(snapshots: List, percent: Int): Map { 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 7234a564..8aaf5ec0 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 @@ -18,7 +18,7 @@ import android.app.PendingIntent.FLAG_UPDATE_CURRENT import android.content.Context import android.content.Intent import android.content.pm.PackageManager.NameNotFoundException -import android.text.format.Formatter +import android.text.format.Formatter.formatShortFileSize import android.util.Log import androidx.core.app.NotificationCompat.Action import androidx.core.app.NotificationCompat.Builder @@ -51,7 +51,8 @@ internal const val NOTIFICATION_ID_RESTORE = 5 private const val NOTIFICATION_ID_RESTORE_ERROR = 6 internal const val NOTIFICATION_ID_PRUNING = 7 internal const val NOTIFICATION_ID_CHECKING = 8 -private const val NOTIFICATION_ID_NO_MAIN_KEY_ERROR = 9 +internal const val NOTIFICATION_ID_CHECK_FINISHED = 9 +private const val NOTIFICATION_ID_NO_MAIN_KEY_ERROR = 10 private val TAG = BackupNotificationManager::class.java.simpleName @@ -195,7 +196,7 @@ internal class BackupNotificationManager(private val context: Context) { } fun onBackupSuccess(numBackedUp: Int, total: Int, size: Long) { - val sizeStr = Formatter.formatShortFileSize(context, size) + val sizeStr = formatShortFileSize(context, size) val contentText = context.getString(R.string.notification_success_text, numBackedUp, total, sizeStr) val intent = Intent(context, SettingsActivity::class.java).apply { @@ -340,7 +341,8 @@ internal class BackupNotificationManager(private val context: Context) { foregroundServiceBehavior = FOREGROUND_SERVICE_IMMEDIATE } - fun showCheckNotification(text: String, thousandth: Int) { + fun showCheckNotification(speed: Long, thousandth: Int) { + val text = "${formatShortFileSize(context, speed)}/s" val notification = getCheckNotification() .setContentText(text) .setProgress(1000, thousandth, false) @@ -348,6 +350,21 @@ internal class BackupNotificationManager(private val context: Context) { nm.notify(NOTIFICATION_ID_CHECKING, notification) } + fun onCheckComplete(size: Long, speed: Long) { + val text = context.getString( + R.string.notification_checking_finished_text, + formatShortFileSize(context, size), + "${formatShortFileSize(context, speed)}/s", + ) + val notification = Builder(context, CHANNEL_ID_CHECKING) + .setContentTitle(context.getString(R.string.notification_checking_finished_title)) + .setContentText(text) + .setSmallIcon(R.drawable.ic_cloud_done) + .build() + nm.cancel(NOTIFICATION_ID_CHECKING) + nm.notify(NOTIFICATION_ID_CHECK_FINISHED, notification) + } + @SuppressLint("RestrictedApi") fun onNoMainKeyError() { val intent = Intent(context, SettingsActivity::class.java) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8612f614..ef80eda9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -189,6 +189,8 @@ App backup integrity check Checking app backups… + App backup integrity confirmed + Successfully checked %1$s at an average speed of %2$s.