From a0f47d3f1b874c9b6d62dfc1679daa9398bf9b98 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 8 Jan 2023 22:06:42 -0500 Subject: [PATCH] Don't exclude same source when checking for duplicate entries Closes #8870 --- .../java/eu/kanade/data/manga/MangaRepositoryImpl.kt | 4 ++-- .../domain/manga/interactor/GetDuplicateLibraryManga.kt | 4 ++-- .../eu/kanade/domain/manga/repository/MangaRepository.kt | 2 +- .../presentation/components/DuplicateMangaDialog.kt | 9 +-------- .../ui/browse/source/browse/BrowseSourceScreen.kt | 1 - .../ui/browse/source/browse/BrowseSourceScreenModel.kt | 9 ++------- .../java/eu/kanade/tachiyomi/ui/manga/MangaScreen.kt | 1 - .../eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt | 7 +------ app/src/main/sqldelight/data/mangas.sq | 1 - i18n/src/main/res/values/strings.xml | 2 +- 10 files changed, 10 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/eu/kanade/data/manga/MangaRepositoryImpl.kt b/app/src/main/java/eu/kanade/data/manga/MangaRepositoryImpl.kt index 43d0be0e9..7e542f314 100644 --- a/app/src/main/java/eu/kanade/data/manga/MangaRepositoryImpl.kt +++ b/app/src/main/java/eu/kanade/data/manga/MangaRepositoryImpl.kt @@ -48,9 +48,9 @@ class MangaRepositoryImpl( return handler.subscribeToList { mangasQueries.getFavoriteBySourceId(sourceId, mangaMapper) } } - override suspend fun getDuplicateLibraryManga(title: String, sourceId: Long): Manga? { + override suspend fun getDuplicateLibraryManga(title: String): Manga? { return handler.awaitOneOrNull { - mangasQueries.getDuplicateLibraryManga(title, sourceId, mangaMapper) + mangasQueries.getDuplicateLibraryManga(title, mangaMapper) } } diff --git a/app/src/main/java/eu/kanade/domain/manga/interactor/GetDuplicateLibraryManga.kt b/app/src/main/java/eu/kanade/domain/manga/interactor/GetDuplicateLibraryManga.kt index 7193ed368..02e7a4fc3 100644 --- a/app/src/main/java/eu/kanade/domain/manga/interactor/GetDuplicateLibraryManga.kt +++ b/app/src/main/java/eu/kanade/domain/manga/interactor/GetDuplicateLibraryManga.kt @@ -7,7 +7,7 @@ class GetDuplicateLibraryManga( private val mangaRepository: MangaRepository, ) { - suspend fun await(title: String, sourceId: Long): Manga? { - return mangaRepository.getDuplicateLibraryManga(title.lowercase(), sourceId) + suspend fun await(title: String): Manga? { + return mangaRepository.getDuplicateLibraryManga(title.lowercase()) } } diff --git a/app/src/main/java/eu/kanade/domain/manga/repository/MangaRepository.kt b/app/src/main/java/eu/kanade/domain/manga/repository/MangaRepository.kt index 8c44287aa..5930dd159 100644 --- a/app/src/main/java/eu/kanade/domain/manga/repository/MangaRepository.kt +++ b/app/src/main/java/eu/kanade/domain/manga/repository/MangaRepository.kt @@ -23,7 +23,7 @@ interface MangaRepository { fun getFavoritesBySourceId(sourceId: Long): Flow> - suspend fun getDuplicateLibraryManga(title: String, sourceId: Long): Manga? + suspend fun getDuplicateLibraryManga(title: String): Manga? suspend fun resetViewerFlags(): Boolean diff --git a/app/src/main/java/eu/kanade/presentation/components/DuplicateMangaDialog.kt b/app/src/main/java/eu/kanade/presentation/components/DuplicateMangaDialog.kt index 06e6fd9e4..6c416716d 100644 --- a/app/src/main/java/eu/kanade/presentation/components/DuplicateMangaDialog.kt +++ b/app/src/main/java/eu/kanade/presentation/components/DuplicateMangaDialog.kt @@ -9,14 +9,12 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.source.Source @Composable fun DuplicateMangaDialog( onDismissRequest: () -> Unit, onConfirm: () -> Unit, onOpenManga: () -> Unit, - duplicateFrom: Source, ) { AlertDialog( onDismissRequest = onDismissRequest, @@ -46,12 +44,7 @@ fun DuplicateMangaDialog( Text(text = stringResource(R.string.are_you_sure)) }, text = { - Text( - text = stringResource( - id = R.string.confirm_manga_add_duplicate, - duplicateFrom.name, - ), - ) + Text(text = stringResource(R.string.confirm_add_duplicate_manga)) }, ) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceScreen.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceScreen.kt index 36caf2357..4be17c817 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceScreen.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceScreen.kt @@ -231,7 +231,6 @@ data class BrowseSourceScreen( onDismissRequest = onDismissRequest, onConfirm = { screenModel.addFavorite(dialog.manga) }, onOpenManga = { navigator.push(MangaScreen(dialog.duplicate.id)) }, - duplicateFrom = screenModel.getSourceOrStub(dialog.duplicate), ) } is BrowseSourceScreenModel.Dialog.RemoveManga -> { 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 ced6cb7a2..30ce4e2a0 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 @@ -40,7 +40,6 @@ import eu.kanade.tachiyomi.data.track.EnhancedTrackService import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.data.track.TrackService import eu.kanade.tachiyomi.source.CatalogueSource -import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.model.FilterList import eu.kanade.tachiyomi.ui.browse.source.filter.CheckboxItem @@ -80,7 +79,7 @@ import eu.kanade.tachiyomi.source.model.Filter as SourceModelFilter class BrowseSourceScreenModel( private val sourceId: Long, listingQuery: String?, - private val sourceManager: SourceManager = Injekt.get(), + sourceManager: SourceManager = Injekt.get(), sourcePreferences: SourcePreferences = Injekt.get(), private val libraryPreferences: LibraryPreferences = Injekt.get(), private val coverCache: CoverCache = Injekt.get(), @@ -273,10 +272,6 @@ class BrowseSourceScreenModel( } } - fun getSourceOrStub(manga: Manga): Source { - return sourceManager.getOrStub(manga.source) - } - fun addFavorite(manga: Manga) { coroutineScope.launch { val categories = getCategories() @@ -340,7 +335,7 @@ class BrowseSourceScreenModel( } suspend fun getDuplicateLibraryManga(manga: Manga): Manga? { - return getDuplicateLibraryManga.await(manga.title, manga.source) + return getDuplicateLibraryManga.await(manga.title) } fun moveMangaToCategories(manga: Manga, vararg categories: Category) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreen.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreen.kt index f5330902d..6a29d43ac 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreen.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreen.kt @@ -169,7 +169,6 @@ class MangaScreen( onDismissRequest = onDismissRequest, onConfirm = { screenModel.toggleFavorite(onRemoved = {}, checkDuplicate = false) }, onOpenManga = { navigator.push(MangaScreen(dialog.duplicate.id)) }, - duplicateFrom = screenModel.getSourceOrStub(dialog.duplicate), ) MangaInfoScreenModel.Dialog.SettingsSheet -> ChapterSettingsDialog( onDismissRequest = onDismissRequest, 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 ffaabcf35..0accfd419 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 @@ -82,7 +82,6 @@ class MangaInfoScreenModel( private val libraryPreferences: LibraryPreferences = Injekt.get(), private val uiPreferences: UiPreferences = Injekt.get(), private val trackManager: TrackManager = Injekt.get(), - private val sourceManager: SourceManager = Injekt.get(), private val downloadManager: DownloadManager = Injekt.get(), private val downloadCache: DownloadCache = Injekt.get(), private val getMangaAndChapters: GetMangaWithChapters = Injekt.get(), @@ -272,7 +271,7 @@ class MangaInfoScreenModel( // Add to library // First, check if duplicate exists if callback is provided if (checkDuplicate) { - val duplicate = getDuplicateLibraryManga.await(manga.title, manga.source) + val duplicate = getDuplicateLibraryManga.await(manga.title) if (duplicate != null) { mutableState.update { state -> @@ -926,10 +925,6 @@ class MangaInfoScreenModel( // Track sheet - end - fun getSourceOrStub(manga: Manga): Source { - return sourceManager.getOrStub(manga.source) - } - sealed class Dialog { data class ChangeCategory(val manga: Manga, val initialSelection: List>) : Dialog() data class DeleteChapters(val chapters: List) : Dialog() diff --git a/app/src/main/sqldelight/data/mangas.sq b/app/src/main/sqldelight/data/mangas.sq index ccdec3621..09522468c 100644 --- a/app/src/main/sqldelight/data/mangas.sq +++ b/app/src/main/sqldelight/data/mangas.sq @@ -63,7 +63,6 @@ SELECT * FROM mangas WHERE favorite = 1 AND LOWER(title) = :title -AND source != :source LIMIT 1; resetViewerFlags: diff --git a/i18n/src/main/res/values/strings.xml b/i18n/src/main/res/values/strings.xml index 707dffa46..6014e6aba 100644 --- a/i18n/src/main/res/values/strings.xml +++ b/i18n/src/main/res/values/strings.xml @@ -626,7 +626,7 @@ Remove from library Unknown title - You have an entry in your library with the same name but from a different source (%1$s).\n\nDo you still wish to continue? + You have an entry in your library with the same name.\n\nDo you still wish to continue? Added to library Removed from library More