Subscribe to changes to manga in BrowseSourceScreen

Fixes #9235
This commit is contained in:
arkon 2023-03-26 12:06:12 -04:00
parent 35d381144d
commit e932983494

View File

@ -54,6 +54,7 @@ import tachiyomi.domain.chapter.interactor.GetChapterByMangaId
import tachiyomi.domain.chapter.interactor.SetMangaDefaultChapterFlags import tachiyomi.domain.chapter.interactor.SetMangaDefaultChapterFlags
import tachiyomi.domain.library.service.LibraryPreferences import tachiyomi.domain.library.service.LibraryPreferences
import tachiyomi.domain.manga.interactor.GetDuplicateLibraryManga import tachiyomi.domain.manga.interactor.GetDuplicateLibraryManga
import tachiyomi.domain.manga.interactor.GetManga
import tachiyomi.domain.manga.interactor.NetworkToLocalManga import tachiyomi.domain.manga.interactor.NetworkToLocalManga
import tachiyomi.domain.manga.model.Manga import tachiyomi.domain.manga.model.Manga
import tachiyomi.domain.manga.model.toMangaUpdate import tachiyomi.domain.manga.model.toMangaUpdate
@ -78,6 +79,7 @@ class BrowseSourceScreenModel(
private val getChapterByMangaId: GetChapterByMangaId = Injekt.get(), private val getChapterByMangaId: GetChapterByMangaId = Injekt.get(),
private val setMangaCategories: SetMangaCategories = Injekt.get(), private val setMangaCategories: SetMangaCategories = Injekt.get(),
private val setMangaDefaultChapterFlags: SetMangaDefaultChapterFlags = Injekt.get(), private val setMangaDefaultChapterFlags: SetMangaDefaultChapterFlags = Injekt.get(),
private val getManga: GetManga = Injekt.get(),
private val networkToLocalManga: NetworkToLocalManga = Injekt.get(), private val networkToLocalManga: NetworkToLocalManga = Injekt.get(),
private val updateManga: UpdateManga = Injekt.get(), private val updateManga: UpdateManga = Injekt.get(),
private val insertTrack: InsertTrack = Injekt.get(), private val insertTrack: InsertTrack = Injekt.get(),
@ -121,20 +123,21 @@ class BrowseSourceScreenModel(
) { ) {
getRemoteManga.subscribe(sourceId, listing.query ?: "", listing.filters) getRemoteManga.subscribe(sourceId, listing.query ?: "", listing.filters)
}.flow.map { pagingData -> }.flow.map { pagingData ->
pagingData pagingData.map {
.map { withIOContext {
flow { networkToLocalManga.await(it.toDomainManga(sourceId))
val localManga = withIOContext { networkToLocalManga.await(it.toDomainManga(sourceId)) } .let { localManga ->
emit(localManga) getManga.subscribe(localManga.url, localManga.source)
} }
.filterNotNull() .filterNotNull()
.filter { .filter { localManga ->
!sourcePreferences.hideInLibraryItems().get() || !it.favorite !sourcePreferences.hideInLibraryItems().get() || !localManga.favorite
} }
.onEach(::initializeManga) .onEach(::initializeManga)
.stateIn(coroutineScope) .stateIn(coroutineScope)
} }
} }
}
.cachedIn(coroutineScope) .cachedIn(coroutineScope)
} }
.stateIn(coroutineScope, SharingStarted.Lazily, emptyFlow()) .stateIn(coroutineScope, SharingStarted.Lazily, emptyFlow())