Cleanup usage of NetworkToLocalManga

This commit is contained in:
Cuong-Tran 2024-11-02 23:58:35 +07:00
parent 79e711efc2
commit 3aac1f3281
No known key found for this signature in database
GPG key ID: 733AA7624B9315C2
6 changed files with 21 additions and 9 deletions

View file

@ -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))

View file

@ -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 }

View file

@ -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) {

View file

@ -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 {

View file

@ -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
}

View file

@ -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