From 4db9a90da2f67e7f4698b11431b8f99f9d66a47e Mon Sep 17 00:00:00 2001 From: arkon Date: Fri, 1 Jan 2021 19:08:12 -0500 Subject: [PATCH] Replace usages of fetchMangaDetails with 1.x getMangaDetails API --- .../data/backup/full/FullBackupManager.kt | 19 ++++---- .../data/backup/legacy/LegacyBackupManager.kt | 19 ++++---- .../data/library/LibraryUpdateService.kt | 45 ++++++++++--------- .../globalsearch/GlobalSearchPresenter.kt | 17 ++++--- .../tachiyomi/ui/manga/MangaPresenter.kt | 20 +++++---- 5 files changed, 69 insertions(+), 51 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupManager.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupManager.kt index 8052e96c09..8b243327e3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupManager.kt @@ -26,7 +26,10 @@ import eu.kanade.tachiyomi.data.database.models.History import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.MangaCategory import eu.kanade.tachiyomi.data.database.models.Track +import eu.kanade.tachiyomi.data.database.models.toMangaInfo import eu.kanade.tachiyomi.source.Source +import eu.kanade.tachiyomi.source.model.toSManga +import eu.kanade.tachiyomi.util.lang.runAsObservable import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.protobuf.ProtoBuf import okio.buffer @@ -190,14 +193,14 @@ class FullBackupManager(context: Context) : AbstractBackupManager(context) { */ fun restoreMangaFetchObservable(source: Source?, manga: Manga, online: Boolean): Observable { return if (online && source != null) { - source.fetchMangaDetails(manga) - .map { networkManga -> - manga.copyFrom(networkManga) - manga.favorite = manga.favorite - manga.initialized = true - manga.id = insertManga(manga) - manga - } + return runAsObservable({ + val networkManga = source.getMangaDetails(manga.toMangaInfo()) + manga.copyFrom(networkManga.toSManga()) + manga.favorite = manga.favorite + manga.initialized = true + manga.id = insertManga(manga) + manga + }) } else { Observable.just(manga) .map { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/legacy/LegacyBackupManager.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/legacy/LegacyBackupManager.kt index 9107d6d398..53dc47ba0c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/legacy/LegacyBackupManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/legacy/LegacyBackupManager.kt @@ -44,8 +44,11 @@ import eu.kanade.tachiyomi.data.database.models.MangaCategory import eu.kanade.tachiyomi.data.database.models.MangaImpl import eu.kanade.tachiyomi.data.database.models.Track import eu.kanade.tachiyomi.data.database.models.TrackImpl +import eu.kanade.tachiyomi.data.database.models.toMangaInfo import eu.kanade.tachiyomi.source.LocalSource import eu.kanade.tachiyomi.source.Source +import eu.kanade.tachiyomi.source.model.toSManga +import eu.kanade.tachiyomi.util.lang.runAsObservable import rx.Observable import timber.log.Timber import kotlin.math.max @@ -256,14 +259,14 @@ class LegacyBackupManager(context: Context, version: Int = CURRENT_VERSION) : Ab * @return [Observable] that contains manga */ fun restoreMangaFetchObservable(source: Source, manga: Manga): Observable { - return source.fetchMangaDetails(manga) - .map { networkManga -> - manga.copyFrom(networkManga) - manga.favorite = true - manga.initialized = true - manga.id = insertManga(manga) - manga - } + return runAsObservable({ + val networkManga = source.getMangaDetails(manga.toMangaInfo()) + manga.copyFrom(networkManga.toSManga()) + manga.favorite = true + manga.initialized = true + manga.id = insertManga(manga) + manga + }) } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt index 5632f62b1a..4697991701 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt @@ -13,6 +13,7 @@ import eu.kanade.tachiyomi.data.database.models.Category import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.LibraryManga import eu.kanade.tachiyomi.data.database.models.Manga +import eu.kanade.tachiyomi.data.database.models.toMangaInfo import eu.kanade.tachiyomi.data.download.DownloadManager import eu.kanade.tachiyomi.data.download.DownloadService import eu.kanade.tachiyomi.data.library.LibraryUpdateRanker.rankingScheme @@ -22,8 +23,10 @@ import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.model.SManga +import eu.kanade.tachiyomi.source.model.toSManga import eu.kanade.tachiyomi.util.chapter.NoChaptersException import eu.kanade.tachiyomi.util.chapter.syncChaptersWithSource +import eu.kanade.tachiyomi.util.lang.runAsObservable import eu.kanade.tachiyomi.util.prepUpdateCover import eu.kanade.tachiyomi.util.shouldDownloadNewChapters import eu.kanade.tachiyomi.util.storage.getUriCompat @@ -339,19 +342,20 @@ class LibraryUpdateService( // Update manga details metadata in the background if (preferences.autoUpdateMetadata()) { - source.fetchMangaDetails(manga) - .map { updatedManga -> - // Avoid "losing" existing cover - if (!updatedManga.thumbnail_url.isNullOrEmpty()) { - manga.prepUpdateCover(coverCache, updatedManga, false) - } else { - updatedManga.thumbnail_url = manga.thumbnail_url - } - - manga.copyFrom(updatedManga) - db.insertManga(manga).executeAsBlocking() - manga + runAsObservable({ + val updatedManga = source.getMangaDetails(manga.toMangaInfo()) + val sManga = updatedManga.toSManga() + // Avoid "losing" existing cover + if (!sManga.thumbnail_url.isNullOrEmpty()) { + manga.prepUpdateCover(coverCache, sManga, false) + } else { + sManga.thumbnail_url = manga.thumbnail_url } + + manga.copyFrom(sManga) + db.insertManga(manga).executeAsBlocking() + manga + }) .onErrorResumeNext { Observable.just(manga) } .subscribeOn(Schedulers.io()) .subscribe() @@ -372,15 +376,16 @@ class LibraryUpdateService( val source = sourceManager.get(manga.source) ?: return@flatMap Observable.empty() - source.fetchMangaDetails(manga) - .map { networkManga -> - manga.prepUpdateCover(coverCache, networkManga, true) - networkManga.thumbnail_url?.let { - manga.thumbnail_url = it - db.insertManga(manga).executeAsBlocking() - } - manga + runAsObservable({ + val networkManga = source.getMangaDetails(manga.toMangaInfo()) + val sManga = networkManga.toSManga() + manga.prepUpdateCover(coverCache, sManga, true) + sManga.thumbnail_url?.let { + manga.thumbnail_url = it + db.insertManga(manga).executeAsBlocking() } + manga + }) .onErrorReturn { manga } } .doOnCompleted { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchPresenter.kt index c369075210..a93b78c113 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchPresenter.kt @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.browse.source.globalsearch import android.os.Bundle import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.models.Manga +import eu.kanade.tachiyomi.data.database.models.toMangaInfo import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.extension.ExtensionManager import eu.kanade.tachiyomi.source.CatalogueSource @@ -11,8 +12,10 @@ import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.model.FilterList import eu.kanade.tachiyomi.source.model.MangasPage import eu.kanade.tachiyomi.source.model.SManga +import eu.kanade.tachiyomi.source.model.toSManga import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourcePresenter +import eu.kanade.tachiyomi.util.lang.runAsObservable import rx.Observable import rx.Subscription import rx.android.schedulers.AndroidSchedulers @@ -247,13 +250,13 @@ open class GlobalSearchPresenter( * @return an observable of the manga to initialize */ private fun getMangaDetailsObservable(manga: Manga, source: Source): Observable { - return source.fetchMangaDetails(manga) - .flatMap { networkManga -> - manga.copyFrom(networkManga) - manga.initialized = true - db.insertManga(manga).executeAsBlocking() - Observable.just(manga) - } + return runAsObservable({ + val networkManga = source.getMangaDetails(manga.toMangaInfo()) + manga.copyFrom(networkManga.toSManga()) + manga.initialized = true + db.insertManga(manga).executeAsBlocking() + manga + }) .onErrorResumeNext { Observable.just(manga) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt index 9aa2311177..2556fe565b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt @@ -10,12 +10,14 @@ import eu.kanade.tachiyomi.data.database.models.Category import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.MangaCategory +import eu.kanade.tachiyomi.data.database.models.toMangaInfo import eu.kanade.tachiyomi.data.download.DownloadManager import eu.kanade.tachiyomi.data.download.model.Download import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.source.LocalSource import eu.kanade.tachiyomi.source.Source +import eu.kanade.tachiyomi.source.model.toSManga import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter import eu.kanade.tachiyomi.ui.manga.chapter.ChapterItem import eu.kanade.tachiyomi.util.chapter.ChapterSettingsHelper @@ -24,6 +26,7 @@ import eu.kanade.tachiyomi.util.isLocal import eu.kanade.tachiyomi.util.lang.await import eu.kanade.tachiyomi.util.lang.isNullOrUnsubscribed import eu.kanade.tachiyomi.util.lang.launchIO +import eu.kanade.tachiyomi.util.lang.runAsObservable import eu.kanade.tachiyomi.util.prepUpdateCover import eu.kanade.tachiyomi.util.removeCovers import eu.kanade.tachiyomi.util.shouldDownloadNewChapters @@ -157,14 +160,15 @@ class MangaPresenter( */ fun fetchMangaFromSource(manualFetch: Boolean = false) { if (!fetchMangaSubscription.isNullOrUnsubscribed()) return - fetchMangaSubscription = Observable.defer { source.fetchMangaDetails(manga) } - .map { networkManga -> - manga.prepUpdateCover(coverCache, networkManga, manualFetch) - manga.copyFrom(networkManga) - manga.initialized = true - db.insertManga(manga).executeAsBlocking() - manga - } + fetchMangaSubscription = runAsObservable({ + val networkManga = source.getMangaDetails(manga.toMangaInfo()) + val sManga = networkManga.toSManga() + manga.prepUpdateCover(coverCache, sManga, manualFetch) + manga.copyFrom(sManga) + manga.initialized = true + db.insertManga(manga).executeAsBlocking() + manga + }) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribeFirst(