Don't throw exception to stop restore job
This commit is contained in:
parent
97aed045e6
commit
e4ea5d0344
1 changed files with 6 additions and 3 deletions
|
@ -175,7 +175,9 @@ class BackupRestoreService : Service() {
|
|||
stopSelf(startId)
|
||||
}
|
||||
job = GlobalScope.launch(handler) {
|
||||
restoreBackup(uri)
|
||||
if (!restoreBackup(uri)) {
|
||||
notifier.showRestoreError(getString(R.string.restoring_backup_canceled))
|
||||
}
|
||||
}
|
||||
job?.invokeOnCompletion {
|
||||
stopSelf(startId)
|
||||
|
@ -189,7 +191,7 @@ class BackupRestoreService : Service() {
|
|||
*
|
||||
* @param uri backup file to restore
|
||||
*/
|
||||
private fun restoreBackup(uri: Uri) {
|
||||
private fun restoreBackup(uri: Uri): Boolean {
|
||||
val startTime = System.currentTimeMillis()
|
||||
|
||||
val reader = JsonReader(contentResolver.openInputStream(uri)!!.bufferedReader())
|
||||
|
@ -213,7 +215,7 @@ class BackupRestoreService : Service() {
|
|||
// Restore individual manga
|
||||
mangasJson.forEach {
|
||||
if (job?.isActive != true) {
|
||||
throw Exception(getString(R.string.restoring_backup_canceled))
|
||||
return false
|
||||
}
|
||||
|
||||
restoreManga(it.asJsonObject)
|
||||
|
@ -225,6 +227,7 @@ class BackupRestoreService : Service() {
|
|||
val logFile = writeErrorLog()
|
||||
|
||||
notifier.showRestoreComplete(time, errors.size, logFile.parent, logFile.name)
|
||||
return true
|
||||
}
|
||||
|
||||
private fun restoreCategories(categoriesJson: JsonElement) {
|
||||
|
|
Reference in a new issue