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
@@ -7,17 +7,7 @@ object BackupConst {
const val INTENT_FILTER = "SettingsBackupFragment"
const val ACTION_BACKUP_COMPLETED = "$ID.$INTENT_FILTER.ACTION_BACKUP_COMPLETED"
const val ACTION_BACKUP_ERROR = "$ID.$INTENT_FILTER.ACTION_BACKUP_ERROR"
const val ACTION_RESTORE_PROGRESS = "$ID.$INTENT_FILTER.ACTION_RESTORE_PROGRESS"
const val ACTION_RESTORE_COMPLETED = "$ID.$INTENT_FILTER.ACTION_RESTORE_COMPLETED"
const val ACTION_RESTORE_ERROR = "$ID.$INTENT_FILTER.ACTION_RESTORE_ERROR"
const val ACTION = "$ID.$INTENT_FILTER.ACTION"
const val EXTRA_PROGRESS = "$ID.$INTENT_FILTER.EXTRA_PROGRESS"
const val EXTRA_AMOUNT = "$ID.$INTENT_FILTER.EXTRA_AMOUNT"
const val EXTRA_ERRORS = "$ID.$INTENT_FILTER.EXTRA_ERRORS"
const val EXTRA_CONTENT = "$ID.$INTENT_FILTER.EXTRA_CONTENT"
const val EXTRA_ERROR_MESSAGE = "$ID.$INTENT_FILTER.EXTRA_ERROR_MESSAGE"
const val EXTRA_URI = "$ID.$INTENT_FILTER.EXTRA_URI"
const val EXTRA_TIME = "$ID.$INTENT_FILTER.EXTRA_TIME"
const val EXTRA_ERROR_FILE_PATH = "$ID.$INTENT_FILTER.EXTRA_ERROR_FILE_PATH"
const val EXTRA_ERROR_FILE = "$ID.$INTENT_FILTER.EXTRA_ERROR_FILE"
}
@@ -34,7 +34,6 @@ import eu.kanade.tachiyomi.data.track.TrackManager
import eu.kanade.tachiyomi.source.Source
import eu.kanade.tachiyomi.ui.setting.backup.BackupNotifier
import eu.kanade.tachiyomi.util.system.isServiceRunning
import eu.kanade.tachiyomi.util.system.sendLocalBroadcast
import java.io.File
import java.text.SimpleDateFormat
import java.util.Date
@@ -90,11 +89,7 @@ class BackupRestoreService : Service() {
fun stop(context: Context) {
context.stopService(Intent(context, BackupRestoreService::class.java))
val errorIntent = Intent(BackupConst.INTENT_FILTER).apply {
putExtra(BackupConst.ACTION, BackupConst.ACTION_RESTORE_ERROR)
putExtra(BackupConst.EXTRA_ERROR_MESSAGE, context.getString(R.string.restoring_backup_canceled))
}
context.sendLocalBroadcast(errorIntent)
BackupNotifier(context).showRestoreError(context.getString(R.string.restoring_backup_canceled))
}
}
@@ -135,7 +130,7 @@ class BackupRestoreService : Service() {
super.onCreate()
notifier = BackupNotifier(this)
startForeground(Notifications.ID_RESTORE, notifier.showRestoreProgress().build())
startForeground(Notifications.ID_RESTORE_PROGRESS, notifier.showRestoreProgress().build())
wakeLock = (getSystemService(Context.POWER_SERVICE) as PowerManager).newWakeLock(
PowerManager.PARTIAL_WAKE_LOCK, "BackupRestoreService:WakeLock"
@@ -182,11 +177,7 @@ class BackupRestoreService : Service() {
Timber.e(exception)
writeErrorLog()
val errorIntent = Intent(BackupConst.INTENT_FILTER).apply {
putExtra(BackupConst.ACTION, BackupConst.ACTION_RESTORE_ERROR)
putExtra(BackupConst.EXTRA_ERROR_MESSAGE, exception.message)
}
sendLocalBroadcast(errorIntent)
notifier.showRestoreError(exception.message)
stopSelf(startId)
}
@@ -235,14 +226,8 @@ class BackupRestoreService : Service() {
val time = endTime - startTime
val logFile = writeErrorLog()
val completeIntent = Intent(BackupConst.INTENT_FILTER).apply {
putExtra(BackupConst.EXTRA_TIME, time)
putExtra(BackupConst.EXTRA_ERRORS, errors.size)
putExtra(BackupConst.EXTRA_ERROR_FILE_PATH, logFile.parent)
putExtra(BackupConst.EXTRA_ERROR_FILE, logFile.name)
putExtra(BackupConst.ACTION, BackupConst.ACTION_RESTORE_COMPLETED)
}
sendLocalBroadcast(completeIntent)
notifier.showRestoreComplete(time, errors.size, logFile.parent, logFile.name)
}
private fun restoreCategories(categoriesJson: JsonElement) {
@@ -49,8 +49,10 @@ object Notifications {
* Notification channel and ids used by the backup/restore system.
*/
const val CHANNEL_BACKUP_RESTORE = "backup_restore_channel"
const val ID_BACKUP = -501
const val ID_RESTORE = -502
const val ID_BACKUP_PROGRESS = -501
const val ID_BACKUP_COMPLETE = -502
const val ID_RESTORE_PROGRESS = -503
const val ID_RESTORE_COMPLETE = -504
/**
* Creates the notification channels introduced in Android Oreo.