Don't exclude same source when checking for duplicate entries

Closes #8870
This commit is contained in:
arkon 2023-01-08 22:06:42 -05:00
parent 6efcb8ccfa
commit a0f47d3f1b
10 changed files with 10 additions and 30 deletions

View File

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

View File

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

View File

@ -23,7 +23,7 @@ interface MangaRepository {
fun getFavoritesBySourceId(sourceId: Long): Flow<List<Manga>>
suspend fun getDuplicateLibraryManga(title: String, sourceId: Long): Manga?
suspend fun getDuplicateLibraryManga(title: String): Manga?
suspend fun resetViewerFlags(): Boolean

View File

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

View File

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

View File

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

View File

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

View File

@ -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<CheckboxState<Category>>) : Dialog()
data class DeleteChapters(val chapters: List<Chapter>) : Dialog()

View File

@ -63,7 +63,6 @@ SELECT *
FROM mangas
WHERE favorite = 1
AND LOWER(title) = :title
AND source != :source
LIMIT 1;
resetViewerFlags:

View File

@ -626,7 +626,7 @@
<!-- missing confirm menu after Compose rewrite #7901 -->
<string name="remove_from_library">Remove from library</string>
<string name="unknown_title">Unknown title</string>
<string name="confirm_manga_add_duplicate">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?</string>
<string name="confirm_add_duplicate_manga">You have an entry in your library with the same name.\n\nDo you still wish to continue?</string>
<string name="manga_added_library">Added to library</string>
<string name="manga_removed_library">Removed from library</string>
<string name="manga_info_expand">More</string>