From 81af97df77666ff5f43abc7c46a7caffe9c91a02 Mon Sep 17 00:00:00 2001 From: Alexandr Kozlinskiy Date: Sat, 18 Mar 2023 14:42:44 +0100 Subject: [PATCH] BrowseSource: do networkToLocal and initializeManga inside flow (#9217) * do networkToLocal and initializeManga inside flow * remove BrowseSourceScreenModel.GetManga --- .../source/browse/BrowseSourceScreenModel.kt | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceScreenModel.kt index a7d3b35fdc..03f4eec897 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceScreenModel.kt @@ -31,8 +31,10 @@ import eu.kanade.tachiyomi.util.removeCovers import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.emptyFlow +import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.filterNotNull import kotlinx.coroutines.flow.firstOrNull +import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.stateIn @@ -52,7 +54,6 @@ import tachiyomi.domain.chapter.interactor.GetChapterByMangaId import tachiyomi.domain.chapter.interactor.SetMangaDefaultChapterFlags import tachiyomi.domain.library.service.LibraryPreferences import tachiyomi.domain.manga.interactor.GetDuplicateLibraryManga -import tachiyomi.domain.manga.interactor.GetManga import tachiyomi.domain.manga.interactor.NetworkToLocalManga import tachiyomi.domain.manga.model.Manga import tachiyomi.domain.manga.model.toMangaUpdate @@ -72,7 +73,6 @@ class BrowseSourceScreenModel( private val libraryPreferences: LibraryPreferences = Injekt.get(), private val coverCache: CoverCache = Injekt.get(), private val getRemoteManga: GetRemoteManga = Injekt.get(), - private val getManga: GetManga = Injekt.get(), private val getDuplicateLibraryManga: GetDuplicateLibraryManga = Injekt.get(), private val getCategories: GetCategories = Injekt.get(), private val getChapterByMangaId: GetChapterByMangaId = Injekt.get(), @@ -122,11 +122,15 @@ class BrowseSourceScreenModel( getRemoteManga.subscribe(sourceId, listing.query ?: "", listing.filters) }.flow.map { pagingData -> pagingData - .map { withIOContext { networkToLocalManga.await(it.toDomainManga(sourceId)) } } - .filter { !sourcePreferences.hideInLibraryItems().get() || !it.favorite } .map { - getManga.subscribe(it.url, it.source) + flow { + val localManga = withIOContext { networkToLocalManga.await(it.toDomainManga(sourceId)) } + emit(localManga) + } .filterNotNull() + .filter { + !sourcePreferences.hideInLibraryItems().get() || !it.favorite + } .onEach(::initializeManga) .stateIn(coroutineScope) }