Skip to content

Commit

Permalink
Cleanup usage of NetworkToLocalManga
Browse files Browse the repository at this point in the history
  • Loading branch information
cuong-tran committed Nov 2, 2024
1 parent 79e711e commit 3aac1f3
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
9 changes: 9 additions & 0 deletions domain/src/main/java/tachiyomi/domain/manga/model/Manga.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3aac1f3

Please sign in to comment.