|
@@ -36,12 +36,12 @@ class BackupRestorer(
|
|
|
|
|
|
private val errors = mutableListOf<Pair<Date, String>>()
|
|
|
|
|
|
- suspend fun restoreBackup(uri: Uri): Boolean {
|
|
|
+ suspend fun syncFromBackup(uri: Uri, sync: Boolean): Boolean {
|
|
|
val startTime = System.currentTimeMillis()
|
|
|
restoreProgress = 0
|
|
|
errors.clear()
|
|
|
|
|
|
- if (!performRestore(uri)) {
|
|
|
+ if (!performRestore(uri, sync)) {
|
|
|
return false
|
|
|
}
|
|
|
|
|
@@ -50,7 +50,11 @@ class BackupRestorer(
|
|
|
|
|
|
val logFile = writeErrorLog()
|
|
|
|
|
|
- notifier.showRestoreComplete(time, errors.size, logFile.parent, logFile.name)
|
|
|
+ if (sync) {
|
|
|
+ notifier.showRestoreComplete(time, errors.size, logFile.parent, logFile.name, contentTitle = context.getString(R.string.library_sync_complete))
|
|
|
+ } else {
|
|
|
+ notifier.showRestoreComplete(time, errors.size, logFile.parent, logFile.name)
|
|
|
+ }
|
|
|
return true
|
|
|
}
|
|
|
|
|
@@ -73,7 +77,7 @@ class BackupRestorer(
|
|
|
return File("")
|
|
|
}
|
|
|
|
|
|
- private suspend fun performRestore(uri: Uri): Boolean {
|
|
|
+ private suspend fun performRestore(uri: Uri, sync: Boolean): Boolean {
|
|
|
val backup = BackupUtil.decodeBackup(context, uri)
|
|
|
|
|
|
restoreAmount = backup.backupManga.size + 1 // +1 for categories
|
|
@@ -94,7 +98,7 @@ class BackupRestorer(
|
|
|
return@coroutineScope false
|
|
|
}
|
|
|
|
|
|
- restoreManga(it, backup.backupCategories)
|
|
|
+ restoreManga(it, backup.backupCategories, sync)
|
|
|
}
|
|
|
// TODO: optionally trigger online library + tracker update
|
|
|
true
|
|
@@ -105,10 +109,10 @@ class BackupRestorer(
|
|
|
backupManager.restoreCategories(backupCategories)
|
|
|
|
|
|
restoreProgress += 1
|
|
|
- showRestoreProgress(restoreProgress, restoreAmount, context.getString(R.string.categories))
|
|
|
+ showRestoreProgress(restoreProgress, restoreAmount, context.getString(R.string.categories), context.getString(R.string.restoring_backup))
|
|
|
}
|
|
|
|
|
|
- private suspend fun restoreManga(backupManga: BackupManga, backupCategories: List<BackupCategory>) {
|
|
|
+ private suspend fun restoreManga(backupManga: BackupManga, backupCategories: List<BackupCategory>, sync: Boolean) {
|
|
|
val manga = backupManga.getMangaImpl()
|
|
|
val chapters = backupManga.getChaptersImpl()
|
|
|
val categories = backupManga.categories.map { it.toInt() }
|
|
@@ -134,7 +138,11 @@ class BackupRestorer(
|
|
|
}
|
|
|
|
|
|
restoreProgress += 1
|
|
|
- showRestoreProgress(restoreProgress, restoreAmount, manga.title)
|
|
|
+ if (sync) {
|
|
|
+ showRestoreProgress(restoreProgress, restoreAmount, manga.title, context.getString(R.string.syncing_library))
|
|
|
+ } else {
|
|
|
+ showRestoreProgress(restoreProgress, restoreAmount, manga.title, context.getString(R.string.restoring_backup))
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -182,7 +190,7 @@ class BackupRestorer(
|
|
|
* @param amount total restoreAmount of manga
|
|
|
* @param title title of restored manga
|
|
|
*/
|
|
|
- private fun showRestoreProgress(progress: Int, amount: Int, title: String) {
|
|
|
- notifier.showRestoreProgress(title, progress, amount)
|
|
|
+ private fun showRestoreProgress(progress: Int, amount: Int, title: String, contentTitle: String) {
|
|
|
+ notifier.showRestoreProgress(title, contentTitle, progress, amount)
|
|
|
}
|
|
|
}
|