Possibly fix backup restores
This commit is contained in:
parent
ada0703d17
commit
d368064549
@ -302,7 +302,8 @@ class BackupManager(val context: Context, version: Int = CURRENT_VERSION) {
|
|||||||
source.fetchChapterList(manga, throttleManager::throttle)
|
source.fetchChapterList(manga, throttleManager::throttle)
|
||||||
} else {
|
} else {
|
||||||
source.fetchChapterList(manga)
|
source.fetchChapterList(manga)
|
||||||
}.map { syncChaptersWithSource(databaseHelper, it, manga, source) }
|
}
|
||||||
|
.map { syncChaptersWithSource(databaseHelper, it, manga, source) }
|
||||||
.doOnNext { pair ->
|
.doOnNext { pair ->
|
||||||
if (pair.first.isNotEmpty()) {
|
if (pair.first.isNotEmpty()) {
|
||||||
chapters.forEach { it.manga_id = manga.id }
|
chapters.forEach { it.manga_id = manga.id }
|
||||||
|
@ -41,6 +41,7 @@ internal class BackupNotifier(private val context: Context) {
|
|||||||
setContentTitle(context.getString(R.string.creating_backup))
|
setContentTitle(context.getString(R.string.creating_backup))
|
||||||
|
|
||||||
setProgress(0, 0, true)
|
setProgress(0, 0, true)
|
||||||
|
setOnlyAlertOnce(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.show(Notifications.ID_BACKUP_PROGRESS)
|
builder.show(Notifications.ID_BACKUP_PROGRESS)
|
||||||
@ -93,6 +94,7 @@ internal class BackupNotifier(private val context: Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setProgress(maxAmount, progress, false)
|
setProgress(maxAmount, progress, false)
|
||||||
|
setOnlyAlertOnce(true)
|
||||||
|
|
||||||
// Clear old actions if they exist
|
// Clear old actions if they exist
|
||||||
if (mActions.isNotEmpty()) {
|
if (mActions.isNotEmpty()) {
|
||||||
|
@ -40,7 +40,6 @@ import java.io.File
|
|||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
import java.util.concurrent.ExecutorService
|
|
||||||
import kotlinx.coroutines.CoroutineExceptionHandler
|
import kotlinx.coroutines.CoroutineExceptionHandler
|
||||||
import kotlinx.coroutines.GlobalScope
|
import kotlinx.coroutines.GlobalScope
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
@ -103,6 +102,8 @@ class BackupRestoreService : Service() {
|
|||||||
|
|
||||||
private var job: Job? = null
|
private var job: Job? = null
|
||||||
|
|
||||||
|
private val throttleManager = EHentaiThrottleManager()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The progress of a backup restore
|
* The progress of a backup restore
|
||||||
*/
|
*/
|
||||||
@ -113,6 +114,10 @@ class BackupRestoreService : Service() {
|
|||||||
*/
|
*/
|
||||||
private var restoreAmount = 0
|
private var restoreAmount = 0
|
||||||
|
|
||||||
|
private var skippedAmount = 0
|
||||||
|
|
||||||
|
private var totalAmount = 0
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List containing errors
|
* List containing errors
|
||||||
*/
|
*/
|
||||||
@ -125,13 +130,6 @@ class BackupRestoreService : Service() {
|
|||||||
|
|
||||||
private val trackManager: TrackManager by injectLazy()
|
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() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
notifier = BackupNotifier(this)
|
notifier = BackupNotifier(this)
|
||||||
@ -218,7 +216,29 @@ class BackupRestoreService : Service() {
|
|||||||
|
|
||||||
val mangasJson = json.get(MANGAS).asJsonArray
|
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
|
restoreProgress = 0
|
||||||
errors.clear()
|
errors.clear()
|
||||||
|
|
||||||
@ -267,6 +287,10 @@ class BackupRestoreService : Service() {
|
|||||||
?: JsonArray()
|
?: JsonArray()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (job?.isActive != true) {
|
||||||
|
throw Exception(getString(R.string.restoring_backup_canceled))
|
||||||
|
}
|
||||||
|
|
||||||
// EXH -->
|
// EXH -->
|
||||||
val migrated = EXHMigrations.migrateBackupEntry(
|
val migrated = EXHMigrations.migrateBackupEntry(
|
||||||
BackupEntry(
|
BackupEntry(
|
||||||
@ -280,10 +304,6 @@ class BackupRestoreService : Service() {
|
|||||||
val (manga, chapters, categories, history, tracks) = migrated
|
val (manga, chapters, categories, history, tracks) = migrated
|
||||||
// <-- EXH
|
// <-- EXH
|
||||||
|
|
||||||
if (job?.isActive != true) {
|
|
||||||
throw Exception(getString(R.string.restoring_backup_canceled))
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
restoreMangaData(manga, chapters, categories, history, tracks)
|
restoreMangaData(manga, chapters, categories, history, tracks)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user