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 d6ef9f214..99f06f88f 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 57b38f4a7..a5e935599 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 dfe3a7f3a..3ad7ebb17 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 bbcfba63b..9ed2bbf9f 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 3aee01d46..6f8c11da2 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)) } }