Move some restore notification logic into service

This commit is contained in:
arkon
2020-04-25 18:59:12 -04:00
parent 96c55db7ca
commit 9d22a9e664
5 changed files with 25 additions and 50 deletions

View File

@@ -301,16 +301,6 @@ class SettingsBackupController : SettingsController() {
notifier.showBackupError(intent.getStringExtra(BackupConst.EXTRA_ERROR_MESSAGE))
}
BackupConst.ACTION_RESTORE_COMPLETED -> {
val time = intent.getLongExtra(BackupConst.EXTRA_TIME, 0)
val errorCount = intent.getIntExtra(BackupConst.EXTRA_ERRORS, 0)
val path = intent.getStringExtra(BackupConst.EXTRA_ERROR_FILE_PATH)
val file = intent.getStringExtra(BackupConst.EXTRA_ERROR_FILE)
notifier.showRestoreComplete(time, errorCount, path, file)
}
BackupConst.ACTION_RESTORE_ERROR -> {
notifier.showRestoreError(intent.getStringExtra(BackupConst.EXTRA_ERROR_MESSAGE))
}
}
}
}

View File

@@ -34,10 +34,12 @@ internal class BackupNotifier(private val context: Context) {
setOngoing(true)
}
notificationBuilder.show(Notifications.ID_BACKUP)
notificationBuilder.show(Notifications.ID_BACKUP_PROGRESS)
}
fun showBackupError(error: String?) {
context.notificationManager.cancel(Notifications.ID_BACKUP_PROGRESS)
with(notificationBuilder) {
setContentTitle(context.getString(R.string.creating_backup_error))
setContentText(error)
@@ -47,10 +49,12 @@ internal class BackupNotifier(private val context: Context) {
setOngoing(false)
}
notificationBuilder.show(Notifications.ID_BACKUP)
notificationBuilder.show(Notifications.ID_BACKUP_COMPLETE)
}
fun showBackupComplete(unifile: UniFile) {
context.notificationManager.cancel(Notifications.ID_BACKUP_PROGRESS)
with(notificationBuilder) {
setContentTitle(context.getString(R.string.backup_created))
@@ -70,11 +74,11 @@ internal class BackupNotifier(private val context: Context) {
addAction(
R.drawable.ic_share_24dp,
context.getString(R.string.action_share),
NotificationReceiver.shareBackupPendingBroadcast(context, unifile.uri, Notifications.ID_BACKUP)
NotificationReceiver.shareBackupPendingBroadcast(context, unifile.uri, Notifications.ID_BACKUP_COMPLETE)
)
}
notificationBuilder.show(Notifications.ID_BACKUP)
notificationBuilder.show(Notifications.ID_BACKUP_COMPLETE)
}
fun showRestoreProgress(content: String = "", progress: Int = 0, maxAmount: Int = 100): NotificationCompat.Builder {
@@ -93,16 +97,18 @@ internal class BackupNotifier(private val context: Context) {
addAction(
R.drawable.ic_close_24dp,
context.getString(R.string.action_stop),
NotificationReceiver.cancelRestorePendingBroadcast(context, Notifications.ID_RESTORE)
NotificationReceiver.cancelRestorePendingBroadcast(context, Notifications.ID_RESTORE_PROGRESS)
)
}
builder.show(Notifications.ID_RESTORE)
builder.show(Notifications.ID_RESTORE_PROGRESS)
return builder
}
fun showRestoreError(error: String?) {
context.notificationManager.cancel(Notifications.ID_RESTORE_PROGRESS)
with(notificationBuilder) {
setContentTitle(context.getString(R.string.restoring_backup_error))
setContentText(error)
@@ -112,10 +118,12 @@ internal class BackupNotifier(private val context: Context) {
setOngoing(false)
}
notificationBuilder.show(Notifications.ID_RESTORE)
notificationBuilder.show(Notifications.ID_RESTORE_COMPLETE)
}
fun showRestoreComplete(time: Long, errorCount: Int, path: String?, file: String?) {
context.notificationManager.cancel(Notifications.ID_RESTORE_PROGRESS)
val timeString = context.getString(
R.string.restore_duration,
TimeUnit.MILLISECONDS.toMinutes(time),
@@ -152,6 +160,6 @@ internal class BackupNotifier(private val context: Context) {
}
}
notificationBuilder.show(Notifications.ID_RESTORE)
notificationBuilder.show(Notifications.ID_RESTORE_COMPLETE)
}
}