From fd30c0adcdfc0efc0aae9e5401843439f2622070 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 29 Jul 2023 12:07:13 -0400 Subject: [PATCH] Avoid showing duplicate entry dialog for same entry Fixes #9772 --- .../ui/browse/source/browse/BrowseSourceScreenModel.kt | 2 +- .../java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt | 2 +- .../main/java/tachiyomi/data/manga/MangaRepositoryImpl.kt | 6 +++--- data/src/main/sqldelight/tachiyomi/data/mangas.sq | 2 +- .../domain/manga/interactor/GetDuplicateLibraryManga.kt | 4 ++-- .../tachiyomi/domain/manga/repository/MangaRepository.kt | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) 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 91e98f80b6..a2a5e0fe3c 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 @@ -321,7 +321,7 @@ class BrowseSourceScreenModel( } suspend fun getDuplicateLibraryManga(manga: Manga): Manga? { - return getDuplicateLibraryManga.await(manga.title) + return getDuplicateLibraryManga.await(manga).getOrNull(0) } private fun moveMangaToCategories(manga: Manga, vararg categories: Category) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt index e5b8285858..ddc1c6f79c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt @@ -284,7 +284,7 @@ class MangaScreenModel( // Add to library // First, check if duplicate exists if callback is provided if (checkDuplicate) { - val duplicate = getDuplicateLibraryManga.await(manga.title) + val duplicate = getDuplicateLibraryManga.await(manga).getOrNull(0) if (duplicate != null) { updateSuccessState { it.copy(dialog = Dialog.DuplicateManga(manga, duplicate)) } diff --git a/data/src/main/java/tachiyomi/data/manga/MangaRepositoryImpl.kt b/data/src/main/java/tachiyomi/data/manga/MangaRepositoryImpl.kt index eb7e996635..d8dacdc3ab 100644 --- a/data/src/main/java/tachiyomi/data/manga/MangaRepositoryImpl.kt +++ b/data/src/main/java/tachiyomi/data/manga/MangaRepositoryImpl.kt @@ -48,9 +48,9 @@ class MangaRepositoryImpl( return handler.subscribeToList { mangasQueries.getFavoriteBySourceId(sourceId, mangaMapper) } } - override suspend fun getDuplicateLibraryManga(title: String): Manga? { - return handler.awaitOneOrNull { - mangasQueries.getDuplicateLibraryManga(title, mangaMapper) + override suspend fun getDuplicateLibraryManga(id: Long, title: String): List { + return handler.awaitList { + mangasQueries.getDuplicateLibraryManga(title, id, mangaMapper) } } diff --git a/data/src/main/sqldelight/tachiyomi/data/mangas.sq b/data/src/main/sqldelight/tachiyomi/data/mangas.sq index 1f57060cb9..a76bbcba4a 100644 --- a/data/src/main/sqldelight/tachiyomi/data/mangas.sq +++ b/data/src/main/sqldelight/tachiyomi/data/mangas.sq @@ -92,7 +92,7 @@ SELECT * FROM mangas WHERE favorite = 1 AND LOWER(title) = :title -LIMIT 1; +AND _id != :id; resetViewerFlags: UPDATE mangas diff --git a/domain/src/main/java/tachiyomi/domain/manga/interactor/GetDuplicateLibraryManga.kt b/domain/src/main/java/tachiyomi/domain/manga/interactor/GetDuplicateLibraryManga.kt index 8fd03436c8..df5cec44a7 100644 --- a/domain/src/main/java/tachiyomi/domain/manga/interactor/GetDuplicateLibraryManga.kt +++ b/domain/src/main/java/tachiyomi/domain/manga/interactor/GetDuplicateLibraryManga.kt @@ -7,7 +7,7 @@ class GetDuplicateLibraryManga( private val mangaRepository: MangaRepository, ) { - suspend fun await(title: String): Manga? { - return mangaRepository.getDuplicateLibraryManga(title.lowercase()) + suspend fun await(manga: Manga): List { + return mangaRepository.getDuplicateLibraryManga(manga.id, manga.title.lowercase()) } } diff --git a/domain/src/main/java/tachiyomi/domain/manga/repository/MangaRepository.kt b/domain/src/main/java/tachiyomi/domain/manga/repository/MangaRepository.kt index 3d065d22bf..c460038cd8 100644 --- a/domain/src/main/java/tachiyomi/domain/manga/repository/MangaRepository.kt +++ b/domain/src/main/java/tachiyomi/domain/manga/repository/MangaRepository.kt @@ -23,7 +23,7 @@ interface MangaRepository { fun getFavoritesBySourceId(sourceId: Long): Flow> - suspend fun getDuplicateLibraryManga(title: String): Manga? + suspend fun getDuplicateLibraryManga(id: Long, title: String): List suspend fun resetViewerFlags(): Boolean