From cac80daa714a8dc3906954b514cd6e3baa140aa1 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 30 Oct 2022 17:40:17 -0400 Subject: [PATCH] Set source properly when creating manga entries Fixes #8333 --- .../manga/interactor/NetworkToLocalManga.kt | 10 +++++----- .../java/eu/kanade/domain/manga/model/Manga.kt | 3 ++- .../kanade/tachiyomi/source/SourceManager.kt | 18 ++++++------------ .../source/browse/BrowseSourcePresenter.kt | 2 +- .../globalsearch/GlobalSearchPresenter.kt | 2 +- 5 files changed, 15 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/eu/kanade/domain/manga/interactor/NetworkToLocalManga.kt b/app/src/main/java/eu/kanade/domain/manga/interactor/NetworkToLocalManga.kt index d6ef9f2140..99f06f88fe 100644 --- a/app/src/main/java/eu/kanade/domain/manga/interactor/NetworkToLocalManga.kt +++ b/app/src/main/java/eu/kanade/domain/manga/interactor/NetworkToLocalManga.kt @@ -7,11 +7,11 @@ class NetworkToLocalManga( private val mangaRepository: MangaRepository, ) { - suspend fun await(manga: Manga, sourceId: Long): Manga { - val localManga = getManga(manga.url, sourceId) + suspend fun await(manga: Manga): Manga { + val localManga = getManga(manga.url, manga.source) return when { localManga == null -> { - val id = insertManga(manga, sourceId) + val id = insertManga(manga) manga.copy(id = id!!) } !localManga.favorite -> { @@ -29,7 +29,7 @@ class NetworkToLocalManga( return mangaRepository.getMangaByUrlAndSourceId(url, sourceId) } - private suspend fun insertManga(manga: Manga, sourceId: Long): Long? { - return mangaRepository.insert(manga.copy(source = sourceId)) + private suspend fun insertManga(manga: Manga): Long? { + return mangaRepository.insert(manga) } } diff --git a/app/src/main/java/eu/kanade/domain/manga/model/Manga.kt b/app/src/main/java/eu/kanade/domain/manga/model/Manga.kt index 57b38f4a7a..a5e935599a 100644 --- a/app/src/main/java/eu/kanade/domain/manga/model/Manga.kt +++ b/app/src/main/java/eu/kanade/domain/manga/model/Manga.kt @@ -232,7 +232,7 @@ fun Manga.toMangaUpdate(): MangaUpdate { ) } -fun SManga.toDomainManga(): Manga { +fun SManga.toDomainManga(sourceId: Long): Manga { return Manga.create().copy( url = url, title = title, @@ -244,6 +244,7 @@ fun SManga.toDomainManga(): Manga { thumbnailUrl = thumbnail_url, updateStrategy = update_strategy, initialized = initialized, + source = sourceId, ) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/SourceManager.kt b/app/src/main/java/eu/kanade/tachiyomi/source/SourceManager.kt index dfe3a7f3a4..3ad7ebb17a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/SourceManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/SourceManager.kt @@ -32,13 +32,7 @@ class SourceManager( private val scope = CoroutineScope(Job() + Dispatchers.IO) - private var sourcesMap = ConcurrentHashMap() - set(value) { - field = value - sourcesMapFlow.value = field - } - - private val sourcesMapFlow = MutableStateFlow(sourcesMap) + private val sourcesMapFlow = MutableStateFlow(ConcurrentHashMap()) private val stubSourcesMap = ConcurrentHashMap() @@ -56,7 +50,7 @@ class SourceManager( registerStubSource(it.toSourceData()) } } - sourcesMap = mutableMap + sourcesMapFlow.value = mutableMap } } @@ -72,18 +66,18 @@ class SourceManager( } fun get(sourceKey: Long): Source? { - return sourcesMap[sourceKey] + return sourcesMapFlow.value[sourceKey] } fun getOrStub(sourceKey: Long): Source { - return sourcesMap[sourceKey] ?: stubSourcesMap.getOrPut(sourceKey) { + return sourcesMapFlow.value[sourceKey] ?: stubSourcesMap.getOrPut(sourceKey) { runBlocking { createStubSource(sourceKey) } } } - fun getOnlineSources() = sourcesMap.values.filterIsInstance() + fun getOnlineSources() = sourcesMapFlow.value.values.filterIsInstance() - fun getCatalogueSources() = sourcesMap.values.filterIsInstance() + fun getCatalogueSources() = sourcesMapFlow.value.values.filterIsInstance() fun getStubSources(): List { val onlineSourceIds = getOnlineSources().map { it.id } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourcePresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourcePresenter.kt index bbcfba63b4..9ed2bbf9fd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourcePresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourcePresenter.kt @@ -131,7 +131,7 @@ open class BrowseSourcePresenter( .map { it.map { sManga -> withIOContext { - networkToLocalManga.await(sManga.toDomainManga(), sourceId) + networkToLocalManga.await(sManga.toDomainManga(sourceId)) } } } 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 3aee01d46f..6f8c11da23 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 @@ -260,6 +260,6 @@ open class GlobalSearchPresenter( * @return a manga from the database. */ protected open suspend fun networkToLocalManga(sManga: SManga, sourceId: Long): DomainManga { - return networkToLocalManga.await(sManga.toDomainManga(), sourceId) + return networkToLocalManga.await(sManga.toDomainManga(sourceId)) } }