Possibly fix backup restores

This commit is contained in:
Jobobby04 2020-05-03 22:36:30 -04:00
parent ada0703d17
commit d368064549
3 changed files with 37 additions and 14 deletions

View File

@ -302,7 +302,8 @@ class BackupManager(val context: Context, version: Int = CURRENT_VERSION) {
source.fetchChapterList(manga, throttleManager::throttle)
} else {
source.fetchChapterList(manga)
}.map { syncChaptersWithSource(databaseHelper, it, manga, source) }
}
.map { syncChaptersWithSource(databaseHelper, it, manga, source) }
.doOnNext { pair ->
if (pair.first.isNotEmpty()) {
chapters.forEach { it.manga_id = manga.id }

View File

@ -41,6 +41,7 @@ internal class BackupNotifier(private val context: Context) {
setContentTitle(context.getString(R.string.creating_backup))
setProgress(0, 0, true)
setOnlyAlertOnce(true)
}
builder.show(Notifications.ID_BACKUP_PROGRESS)
@ -93,6 +94,7 @@ internal class BackupNotifier(private val context: Context) {
}
setProgress(maxAmount, progress, false)
setOnlyAlertOnce(true)
// Clear old actions if they exist
if (mActions.isNotEmpty()) {

View File

@ -40,7 +40,6 @@ import java.io.File
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
import java.util.concurrent.ExecutorService
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.Job
@ -103,6 +102,8 @@ class BackupRestoreService : Service() {
private var job: Job? = null
private val throttleManager = EHentaiThrottleManager()
/**
* The progress of a backup restore
*/
@ -113,6 +114,10 @@ class BackupRestoreService : Service() {
*/
private var restoreAmount = 0
private var skippedAmount = 0
private var totalAmount = 0
/**
* List containing errors
*/
@ -125,13 +130,6 @@ class BackupRestoreService : Service() {
private val trackManager: TrackManager by injectLazy()
private lateinit var executor: ExecutorService
private val throttleManager = EHentaiThrottleManager()
/**
* Method called when the service is created. It injects dependencies and acquire the wake lock.
*/
override fun onCreate() {
super.onCreate()
notifier = BackupNotifier(this)
@ -218,7 +216,29 @@ class BackupRestoreService : Service() {
val mangasJson = json.get(MANGAS).asJsonArray
restoreAmount = mangasJson.size() + 1 // +1 for categories
val validManga = mangasJson.filter {
val tmanga = backupManager.parser.fromJson<MangaImpl>(it.asJsonObject.get(MANGA))
// EXH -->
val migrated = EXHMigrations.migrateBackupEntry(
BackupEntry(
tmanga,
backupManager.parser.fromJson<List<ChapterImpl>>(JsonArray()),
backupManager.parser.fromJson<List<String>>(JsonArray()),
backupManager.parser.fromJson<List<DHistory>>(JsonArray()),
backupManager.parser.fromJson<List<TrackImpl>>(JsonArray())
)
)
val (manga, _, _, _, _) = migrated
val sourced = backupManager.sourceManager.get(manga.source) != null
if (!sourced) {
restoreAmount -= 1
}
sourced
}
totalAmount = mangasJson.size()
restoreAmount = validManga.count() + 1 // +1 for categories
skippedAmount = mangasJson.size() - validManga.count()
restoreProgress = 0
errors.clear()
@ -267,6 +287,10 @@ class BackupRestoreService : Service() {
?: JsonArray()
)
if (job?.isActive != true) {
throw Exception(getString(R.string.restoring_backup_canceled))
}
// EXH -->
val migrated = EXHMigrations.migrateBackupEntry(
BackupEntry(
@ -280,10 +304,6 @@ class BackupRestoreService : Service() {
val (manga, chapters, categories, history, tracks) = migrated
// <-- EXH
if (job?.isActive != true) {
throw Exception(getString(R.string.restoring_backup_canceled))
}
try {
restoreMangaData(manga, chapters, categories, history, tracks)
} catch (e: Exception) {