Show app backup check success notification
This commit is contained in:
parent
51a6355205
commit
96f9a8d017
3 changed files with 28 additions and 7 deletions
|
@ -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<Snapshot>, percent: Int): Map<String, Blob> {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -189,6 +189,8 @@
|
|||
|
||||
<string name="notification_checking_channel_title">App backup integrity check</string>
|
||||
<string name="notification_checking_title">Checking app backups…</string>
|
||||
<string name="notification_checking_finished_title">App backup integrity confirmed</string>
|
||||
<string name="notification_checking_finished_text">Successfully checked %1$s at an average speed of %2$s.</string>
|
||||
|
||||
<!-- App Backup and Restore State -->
|
||||
|
||||
|
|
Loading…
Reference in a new issue