diff --git a/CHANGELOG.md b/CHANGELOG.md index e3e653d9a0..d91facbc08 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,9 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co - Bangumi search now shows the score and summary of a search result ([@MajorTanya](https://github.com/MajorTanya)) ([#1396](https://github.com/mihonapp/mihon/pull/1396)) - Extension repo URLs are now auto-formatted ([@AntsyLich](https://github.com/AntsyLich), [@MajorTanya](https://github.com/MajorTanya)) +### Other +- Cleanup usage of `NetworkToLocalManga` ([@cuong-tran](https://github.com/cuong-tran)) ([#](https://github.com/mihonapp/mihon/pull/)) + ## [v0.17.0] - 2024-10-26 ### Added - Option to disable reader zoom out ([@Splintorien](https://github.com/Splintorien)) ([#302](https://github.com/mihonapp/mihon/pull/302)) 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 dff062503a..afd212022f 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 @@ -113,9 +113,11 @@ class BrowseSourceScreenModel( getRemoteManga.subscribe(sourceId, listing.query ?: "", listing.filters) }.flow.map { pagingData -> pagingData.map { - networkToLocalManga.await(it.toDomainManga(sourceId)) + val networkManga = it.toDomainManga(sourceId) + networkToLocalManga.await(networkManga) .let { localManga -> getManga.subscribe(localManga.url, localManga.source) } .filterNotNull() + .map { manga -> manga.shouldUseNetworkMangaInfo(networkManga) } .stateIn(ioCoroutineScope) } .filter { !hideInLibraryItems || !it.value.favorite } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/SearchScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/SearchScreenModel.kt index 1cb9ba3ff4..3f1a0839e2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/SearchScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/SearchScreenModel.kt @@ -166,7 +166,9 @@ abstract class SearchScreenModel( } val titles = page.mangas.map { - networkToLocalManga.await(it.toDomainManga(source.id)) + val networkManga = it.toDomainManga(source.id) + networkToLocalManga.await(networkManga) + .shouldUseNetworkMangaInfo(networkManga) } if (isActive) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/deeplink/DeepLinkScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/deeplink/DeepLinkScreenModel.kt index 5bef14675b..031b3c7be8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/deeplink/DeepLinkScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/deeplink/DeepLinkScreenModel.kt @@ -74,8 +74,9 @@ class DeepLinkScreenModel( } private suspend fun getMangaFromSManga(sManga: SManga, sourceId: Long): Manga { - return getMangaByUrlAndSourceId.await(sManga.url, sourceId) - ?: networkToLocalManga.await(sManga.toDomainManga(sourceId)) + val networkManga = sManga.toDomainManga(sourceId) + return networkToLocalManga.await(networkManga) + .shouldUseNetworkMangaInfo(networkManga) } sealed interface State { diff --git a/domain/src/main/java/tachiyomi/domain/manga/interactor/NetworkToLocalManga.kt b/domain/src/main/java/tachiyomi/domain/manga/interactor/NetworkToLocalManga.kt index 5ca3fb647b..d7ced803f1 100644 --- a/domain/src/main/java/tachiyomi/domain/manga/interactor/NetworkToLocalManga.kt +++ b/domain/src/main/java/tachiyomi/domain/manga/interactor/NetworkToLocalManga.kt @@ -14,11 +14,6 @@ class NetworkToLocalManga( val id = insertManga(manga) manga.copy(id = id!!) } - !localManga.favorite -> { - // if the manga isn't a favorite, set its display title from source - // if it later becomes a favorite, updated title will go to db - localManga.copy(title = manga.title) - } else -> { localManga } diff --git a/domain/src/main/java/tachiyomi/domain/manga/model/Manga.kt b/domain/src/main/java/tachiyomi/domain/manga/model/Manga.kt index fb634c1cd0..29c470a4c3 100644 --- a/domain/src/main/java/tachiyomi/domain/manga/model/Manga.kt +++ b/domain/src/main/java/tachiyomi/domain/manga/model/Manga.kt @@ -72,6 +72,15 @@ data class Manga( return chapterFlags and CHAPTER_SORT_DIR_MASK == CHAPTER_SORT_DESC } + fun shouldUseNetworkMangaInfo(networkManga: Manga): Manga = + if (!favorite) { + // if the manga isn't a favorite, set its display title from source + // if it later becomes a favorite, updated title will go to db + copy(title = networkManga.title) + } else { + this + } + companion object { // Generic filter that does not filter anything const val SHOW_ALL = 0x00000000L