From 89a20be7ef54ab7f85929b3af6c0a01fbc03a1f5 Mon Sep 17 00:00:00 2001 From: Jobobby04 Date: Sun, 8 Nov 2020 15:02:26 -0500 Subject: [PATCH] Fix E-H Sync favorites getting stuck --- app/src/main/java/exh/GalleryAdder.kt | 8 ++++---- .../main/java/exh/favorites/FavoritesSyncHelper.kt | 13 +++++++------ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/exh/GalleryAdder.kt b/app/src/main/java/exh/GalleryAdder.kt index 702493239..db6131ba9 100755 --- a/app/src/main/java/exh/GalleryAdder.kt +++ b/app/src/main/java/exh/GalleryAdder.kt @@ -10,9 +10,9 @@ import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.online.UrlImportableSource import eu.kanade.tachiyomi.source.online.all.EHentai import eu.kanade.tachiyomi.util.chapter.syncChaptersWithSource -import eu.kanade.tachiyomi.util.lang.await import eu.kanade.tachiyomi.util.lang.awaitSingle import exh.source.getMainSource +import exh.util.executeOnIO import uy.kohesive.injekt.injectLazy class GalleryAdder { @@ -85,7 +85,7 @@ class GalleryAdder { } ?: return GalleryAddEvent.Fail.UnknownType(url, context) // Use manga in DB if possible, otherwise, make a new manga - val manga = db.getManga(cleanedUrl, source.id).await() + val manga = db.getManga(cleanedUrl, source.id).executeOnIO() ?: Manga.create(source.id).apply { this.url = cleanedUrl title = realUrl @@ -94,7 +94,7 @@ class GalleryAdder { // Insert created manga if not in DB before fetching details // This allows us to keep the metadata when fetching details if (manga.id == null) { - db.insertManga(manga).await().insertedId()?.let { + db.insertManga(manga).executeOnIO().insertedId()?.let { manga.id = it } } @@ -109,7 +109,7 @@ class GalleryAdder { manga.date_added = System.currentTimeMillis() } - db.insertManga(manga).await() + db.insertManga(manga).executeOnIO() // Fetch and copy chapters try { diff --git a/app/src/main/java/exh/favorites/FavoritesSyncHelper.kt b/app/src/main/java/exh/favorites/FavoritesSyncHelper.kt index 01e35bd0c..e44dd86d2 100644 --- a/app/src/main/java/exh/favorites/FavoritesSyncHelper.kt +++ b/app/src/main/java/exh/favorites/FavoritesSyncHelper.kt @@ -23,6 +23,7 @@ import exh.GalleryAddEvent import exh.GalleryAdder import exh.eh.EHentaiThrottleManager import exh.eh.EHentaiUpdateWorker +import exh.util.executeOnIO import exh.util.ignore import exh.util.trans import exh.util.wifiManager @@ -194,7 +195,7 @@ class FavoritesSyncHelper(val context: Context) { } private suspend fun applyRemoteCategories(categories: List) { - val localCategories = db.getCategories().await() + val localCategories = db.getCategories().executeOnIO() val newLocalCategories = localCategories.toMutableList() @@ -232,7 +233,7 @@ class FavoritesSyncHelper(val context: Context) { // Only insert categories if changed if (changed) { - db.insertCategories(newLocalCategories).await() + db.insertCategories(newLocalCategories).executeOnIO() } } @@ -343,12 +344,12 @@ class FavoritesSyncHelper(val context: Context) { db.getManga(url, EXH_SOURCE_ID), db.getManga(url, EH_SOURCE_ID) ).forEach { - val manga = it.await() + val manga = it.executeOnIO() if (manga?.favorite == true) { manga.favorite = false manga.date_added = 0 - db.updateMangaFavorite(manga).await() + db.updateMangaFavorite(manga).executeOnIO() removedManga += manga } } @@ -356,11 +357,11 @@ class FavoritesSyncHelper(val context: Context) { // Can't do too many DB OPs in one go removedManga.chunked(10).forEach { - db.deleteOldMangasCategories(it).await() + db.deleteOldMangasCategories(it).executeAsBlocking() } val insertedMangaCategories = mutableListOf>() - val categories = db.getCategories().await() + val categories = db.getCategories().executeOnIO() // Apply additions throttleManager.resetThrottle()