Prevent multiple concurrent backups/restores

This commit is contained in:
arkon
2020-04-21 21:34:22 -04:00
parent f2a7f8efda
commit fc2c465bac
5 changed files with 49 additions and 24 deletions

View File

@@ -5,11 +5,11 @@ import eu.kanade.tachiyomi.BuildConfig.APPLICATION_ID as ID
object BackupConst {
const val INTENT_FILTER = "SettingsBackupFragment"
const val ACTION_BACKUP_COMPLETED_DIALOG = "$ID.$INTENT_FILTER.ACTION_BACKUP_COMPLETED_DIALOG"
const val ACTION_SET_PROGRESS_DIALOG = "$ID.$INTENT_FILTER.ACTION_SET_PROGRESS_DIALOG"
const val ACTION_ERROR_BACKUP_DIALOG = "$ID.$INTENT_FILTER.ACTION_ERROR_BACKUP_DIALOG"
const val ACTION_ERROR_RESTORE_DIALOG = "$ID.$INTENT_FILTER.ACTION_ERROR_RESTORE_DIALOG"
const val ACTION_RESTORE_COMPLETED_DIALOG = "$ID.$INTENT_FILTER.ACTION_RESTORE_COMPLETED_DIALOG"
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"

View File

@@ -179,7 +179,7 @@ class BackupManager(val context: Context, version: Int = CURRENT_VERSION) {
// Show completed dialog
val intent = Intent(BackupConst.INTENT_FILTER).apply {
putExtra(BackupConst.ACTION, BackupConst.ACTION_BACKUP_COMPLETED_DIALOG)
putExtra(BackupConst.ACTION, BackupConst.ACTION_BACKUP_COMPLETED)
putExtra(BackupConst.EXTRA_URI, file.uri.toString())
}
context.sendLocalBroadcast(intent)
@@ -189,7 +189,7 @@ class BackupManager(val context: Context, version: Int = CURRENT_VERSION) {
if (!isJob) {
// Show error dialog
val intent = Intent(BackupConst.INTENT_FILTER).apply {
putExtra(BackupConst.ACTION, BackupConst.ACTION_ERROR_BACKUP_DIALOG)
putExtra(BackupConst.ACTION, BackupConst.ACTION_BACKUP_ERROR)
putExtra(BackupConst.EXTRA_ERROR_MESSAGE, e.message)
}
context.sendLocalBroadcast(intent)

View File

@@ -251,7 +251,7 @@ class BackupRestoreService : Service() {
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_DIALOG)
putExtra(BackupConst.ACTION, BackupConst.ACTION_RESTORE_COMPLETED)
}
sendLocalBroadcast(completeIntent)
}
@@ -259,7 +259,7 @@ class BackupRestoreService : Service() {
Timber.e(error)
writeErrorLog()
val errorIntent = Intent(BackupConst.INTENT_FILTER).apply {
putExtra(BackupConst.ACTION, BackupConst.ACTION_ERROR_RESTORE_DIALOG)
putExtra(BackupConst.ACTION, BackupConst.ACTION_RESTORE_ERROR)
putExtra(BackupConst.EXTRA_ERROR_MESSAGE, error.message)
}
sendLocalBroadcast(errorIntent)
@@ -463,7 +463,7 @@ class BackupRestoreService : Service() {
putExtra(BackupConst.EXTRA_AMOUNT, amount)
putExtra(BackupConst.EXTRA_CONTENT, content)
putExtra(BackupConst.EXTRA_ERRORS, errors)
putExtra(BackupConst.ACTION, BackupConst.ACTION_SET_PROGRESS_DIALOG)
putExtra(BackupConst.ACTION, BackupConst.ACTION_RESTORE_PROGRESS)
}
sendLocalBroadcast(intent)
}