Make restore a foreground service

This commit is contained in:
arkon
2020-04-22 23:09:24 -04:00
parent 2b27b40142
commit 6de00b1f21
4 changed files with 27 additions and 36 deletions

View File

@@ -269,7 +269,6 @@ class SettingsBackupController : SettingsController() {
.positiveButton(R.string.action_restore) {
val context = applicationContext
if (context != null) {
(targetController as SettingsBackupController).notifier.showRestoreProgress()
BackupRestoreService.start(context, args.getParcelable(KEY_URI)!!)
isRestoreStarted = true
}
@@ -296,12 +295,6 @@ class SettingsBackupController : SettingsController() {
notifier.showBackupError(intent.getStringExtra(BackupConst.EXTRA_ERROR_MESSAGE))
}
BackupConst.ACTION_RESTORE_PROGRESS -> {
val progress = intent.getIntExtra(BackupConst.EXTRA_PROGRESS, 0)
val amount = intent.getIntExtra(BackupConst.EXTRA_AMOUNT, 0)
val content = intent.getStringExtra(BackupConst.EXTRA_CONTENT)
notifier.showRestoreProgress(content, progress, amount)
}
BackupConst.ACTION_RESTORE_COMPLETED -> {
isRestoreStarted = false

View File

@@ -72,8 +72,8 @@ internal class BackupNotifier(private val context: Context) {
notificationBuilder.show(Notifications.ID_BACKUP)
}
fun showRestoreProgress(content: String = "", progress: Int = 0, maxAmount: Int = 100) {
with(notificationBuilder) {
fun showRestoreProgress(content: String = "", progress: Int = 0, maxAmount: Int = 100): NotificationCompat.Builder {
val builder = with(notificationBuilder) {
setContentTitle(context.getString(R.string.restoring_backup))
setContentText(content)
@@ -89,7 +89,9 @@ internal class BackupNotifier(private val context: Context) {
NotificationReceiver.cancelRestorePendingBroadcast(context, Notifications.ID_RESTORE))
}
notificationBuilder.show(Notifications.ID_RESTORE)
builder.show(Notifications.ID_RESTORE)
return builder
}
fun showRestoreError(error: String?) {