From 4e04218353ff28a38784a7ff9c4f7d10408c8afd Mon Sep 17 00:00:00 2001 From: Cuong-Tran Date: Mon, 4 Nov 2024 01:46:34 +0700 Subject: [PATCH 1/3] Always update fresh data from source if manga isn't favorited --- .../ui/deeplink/DeepLinkScreenModel.kt | 5 +---- app/src/main/java/exh/GalleryAdder.kt | 3 +-- .../manga/interactor/NetworkToLocalManga.kt | 18 +++++++++++++++--- 3 files changed, 17 insertions(+), 9 deletions(-) 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..892d4c0f24 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 @@ -15,7 +15,6 @@ import kotlinx.coroutines.flow.update import tachiyomi.core.common.util.lang.launchIO import tachiyomi.domain.chapter.interactor.GetChapterByUrlAndMangaId import tachiyomi.domain.chapter.model.Chapter -import tachiyomi.domain.manga.interactor.GetMangaByUrlAndSourceId import tachiyomi.domain.manga.interactor.NetworkToLocalManga import tachiyomi.domain.manga.model.Manga import tachiyomi.domain.source.service.SourceManager @@ -27,7 +26,6 @@ class DeepLinkScreenModel( private val sourceManager: SourceManager = Injekt.get(), private val networkToLocalManga: NetworkToLocalManga = Injekt.get(), private val getChapterByUrlAndMangaId: GetChapterByUrlAndMangaId = Injekt.get(), - private val getMangaByUrlAndSourceId: GetMangaByUrlAndSourceId = Injekt.get(), private val syncChaptersWithSource: SyncChaptersWithSource = Injekt.get(), ) : StateScreenModel(State.Loading) { @@ -74,8 +72,7 @@ class DeepLinkScreenModel( } private suspend fun getMangaFromSManga(sManga: SManga, sourceId: Long): Manga { - return getMangaByUrlAndSourceId.await(sManga.url, sourceId) - ?: networkToLocalManga.await(sManga.toDomainManga(sourceId)) + return networkToLocalManga.await(sManga.toDomainManga(sourceId)) } sealed interface State { diff --git a/app/src/main/java/exh/GalleryAdder.kt b/app/src/main/java/exh/GalleryAdder.kt index 1f035ecb5f..c092dc4ed2 100644 --- a/app/src/main/java/exh/GalleryAdder.kt +++ b/app/src/main/java/exh/GalleryAdder.kt @@ -135,8 +135,7 @@ class GalleryAdder( } ?: return GalleryAddEvent.Fail.UnknownType(url, context) // Use manga in DB if possible, otherwise, make a new manga - var manga = getManga.await(cleanedMangaUrl, source.id) - ?: networkToLocalManga.await( + var manga = networkToLocalManga.await( Manga.create().copy( source = source.id, url = cleanedMangaUrl, 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 255951568e..7871741f3a 100644 --- a/domain/src/main/java/tachiyomi/domain/manga/interactor/NetworkToLocalManga.kt +++ b/domain/src/main/java/tachiyomi/domain/manga/interactor/NetworkToLocalManga.kt @@ -1,6 +1,8 @@ package tachiyomi.domain.manga.interactor +import exh.util.nullIfBlank import tachiyomi.domain.manga.model.Manga +import tachiyomi.domain.manga.model.toMangaUpdate import tachiyomi.domain.manga.repository.MangaRepository class NetworkToLocalManga( @@ -15,9 +17,9 @@ class NetworkToLocalManga( 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(/* SY --> */ogTitle/* SY <-- */ = manga.title) + // if the manga isn't a favorite, update new info from source to db + manga.updateManga(localManga.id) + manga.copy(id = localManga.id) } else -> { localManga @@ -32,4 +34,14 @@ class NetworkToLocalManga( private suspend fun insertManga(manga: Manga): Long? { return mangaRepository.insert(manga) } + + private suspend fun Manga.updateManga(id: Long) { + mangaRepository.update( + toMangaUpdate() + .copy( + id = id, + thumbnailUrl = ogThumbnailUrl?.nullIfBlank() + ) + ) + } } From e402ee70759e73f716b5995efea594dc1cfc90d5 Mon Sep 17 00:00:00 2001 From: Cuong-Tran Date: Mon, 4 Nov 2024 01:47:23 +0700 Subject: [PATCH 2/3] fix spotless --- app/src/main/java/exh/GalleryAdder.kt | 10 +++++----- .../domain/manga/interactor/NetworkToLocalManga.kt | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/exh/GalleryAdder.kt b/app/src/main/java/exh/GalleryAdder.kt index c092dc4ed2..91b272120f 100644 --- a/app/src/main/java/exh/GalleryAdder.kt +++ b/app/src/main/java/exh/GalleryAdder.kt @@ -136,11 +136,11 @@ class GalleryAdder( // Use manga in DB if possible, otherwise, make a new manga var manga = networkToLocalManga.await( - Manga.create().copy( - source = source.id, - url = cleanedMangaUrl, - ), - ) + Manga.create().copy( + source = source.id, + url = cleanedMangaUrl, + ), + ) // Fetch and copy details val newManga = retry(retry) { source.getMangaDetails(manga.toSManga()) } 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 7871741f3a..80856f65c1 100644 --- a/domain/src/main/java/tachiyomi/domain/manga/interactor/NetworkToLocalManga.kt +++ b/domain/src/main/java/tachiyomi/domain/manga/interactor/NetworkToLocalManga.kt @@ -40,8 +40,8 @@ class NetworkToLocalManga( toMangaUpdate() .copy( id = id, - thumbnailUrl = ogThumbnailUrl?.nullIfBlank() - ) + thumbnailUrl = ogThumbnailUrl?.nullIfBlank(), + ), ) } } From e81f95876ca137e93ef76a2420765122a2f28f88 Mon Sep 17 00:00:00 2001 From: Cuong-Tran Date: Thu, 21 Nov 2024 01:10:40 +0700 Subject: [PATCH 3/3] inline manga update --- .../manga/interactor/NetworkToLocalManga.kt | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) 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 80856f65c1..4e1422c274 100644 --- a/domain/src/main/java/tachiyomi/domain/manga/interactor/NetworkToLocalManga.kt +++ b/domain/src/main/java/tachiyomi/domain/manga/interactor/NetworkToLocalManga.kt @@ -18,7 +18,13 @@ class NetworkToLocalManga( } !localManga.favorite -> { // if the manga isn't a favorite, update new info from source to db - manga.updateManga(localManga.id) + mangaRepository.update( + manga.toMangaUpdate() + .copy( + id = localManga.id, + thumbnailUrl = manga.ogThumbnailUrl?.nullIfBlank(), + ), + ) manga.copy(id = localManga.id) } else -> { @@ -34,14 +40,4 @@ class NetworkToLocalManga( private suspend fun insertManga(manga: Manga): Long? { return mangaRepository.insert(manga) } - - private suspend fun Manga.updateManga(id: Long) { - mangaRepository.update( - toMangaUpdate() - .copy( - id = id, - thumbnailUrl = ogThumbnailUrl?.nullIfBlank(), - ), - ) - } }