Don't throw exception to stop restore job

This commit is contained in:
arkon 2020-05-12 09:11:52 -04:00
parent 97aed045e6
commit e4ea5d0344

View file

@ -175,7 +175,9 @@ class BackupRestoreService : Service() {
stopSelf(startId) stopSelf(startId)
} }
job = GlobalScope.launch(handler) { job = GlobalScope.launch(handler) {
restoreBackup(uri) if (!restoreBackup(uri)) {
notifier.showRestoreError(getString(R.string.restoring_backup_canceled))
}
} }
job?.invokeOnCompletion { job?.invokeOnCompletion {
stopSelf(startId) stopSelf(startId)
@ -189,7 +191,7 @@ class BackupRestoreService : Service() {
* *
* @param uri backup file to restore * @param uri backup file to restore
*/ */
private fun restoreBackup(uri: Uri) { private fun restoreBackup(uri: Uri): Boolean {
val startTime = System.currentTimeMillis() val startTime = System.currentTimeMillis()
val reader = JsonReader(contentResolver.openInputStream(uri)!!.bufferedReader()) val reader = JsonReader(contentResolver.openInputStream(uri)!!.bufferedReader())
@ -213,7 +215,7 @@ class BackupRestoreService : Service() {
// Restore individual manga // Restore individual manga
mangasJson.forEach { mangasJson.forEach {
if (job?.isActive != true) { if (job?.isActive != true) {
throw Exception(getString(R.string.restoring_backup_canceled)) return false
} }
restoreManga(it.asJsonObject) restoreManga(it.asJsonObject)
@ -225,6 +227,7 @@ class BackupRestoreService : Service() {
val logFile = writeErrorLog() val logFile = writeErrorLog()
notifier.showRestoreComplete(time, errors.size, logFile.parent, logFile.name) notifier.showRestoreComplete(time, errors.size, logFile.parent, logFile.name)
return true
} }
private fun restoreCategories(categoriesJson: JsonElement) { private fun restoreCategories(categoriesJson: JsonElement) {