Show new multi-Duplicate dialog when Bulk-favorite with only 1 manga

This commit is contained in:
Cuong-Tran 2025-04-06 17:33:40 +07:00
parent d58523161f
commit 8c45ac552f
No known key found for this signature in database
GPG key ID: 733AA7624B9315C2

View file

@ -133,9 +133,16 @@ class BulkFavoriteScreenModel(
fun addFavorite(startIdx: Int = 0) { fun addFavorite(startIdx: Int = 0) {
screenModelScope.launch { screenModelScope.launch {
startRunning() startRunning()
val mangaWithDup = getDuplicateLibraryManga(startIdx) val entryWithDuplicates = getDuplicateLibraryManga(startIdx)
if (mangaWithDup != null) { if (entryWithDuplicates != null) {
setDialog(Dialog.AllowDuplicate(mangaWithDup)) val (index, duplicates) = entryWithDuplicates
if (state.value.selection.size == 1) {
val manga = state.value.selection.first()
// If only one manga is selected, show the multiple duplicates dialog.
setDialog(Dialog.AddDuplicateManga(manga, duplicates))
} else {
setDialog(Dialog.AllowDuplicate(index to duplicates.first()))
}
} else { } else {
addFavoriteDuplicate() addFavoriteDuplicate()
} }
@ -199,13 +206,13 @@ class BulkFavoriteScreenModel(
} }
} }
private suspend fun getDuplicateLibraryManga(startIdx: Int = 0): Pair<Int, Manga>? { private suspend fun getDuplicateLibraryManga(startIdx: Int = 0): Pair<Int, List<Manga>>? {
val mangas = state.value.selection val mangas = state.value.selection
mangas.fastForEachIndexed { index, manga -> mangas.fastForEachIndexed { index, manga ->
if (index < startIdx) return@fastForEachIndexed if (index < startIdx) return@fastForEachIndexed
val dup = getDuplicateLibraryManga(manga) val duplicates = getDuplicateLibraryManga(manga)
if (dup.isEmpty()) return@fastForEachIndexed if (duplicates.isEmpty()) return@fastForEachIndexed
return Pair(index, dup.first()) return Pair(index, duplicates)
} }
return null return null
} }
@ -435,10 +442,15 @@ fun AddDuplicateMangaDialog(bulkFavoriteScreenModel: BulkFavoriteScreenModel) {
val bulkFavoriteState by bulkFavoriteScreenModel.state.collectAsState() val bulkFavoriteState by bulkFavoriteScreenModel.state.collectAsState()
val dialog = bulkFavoriteState.dialog as BulkFavoriteScreenModel.Dialog.AddDuplicateManga val dialog = bulkFavoriteState.dialog as BulkFavoriteScreenModel.Dialog.AddDuplicateManga
bulkFavoriteScreenModel.stopRunning()
DuplicateMangaDialog( DuplicateMangaDialog(
duplicates = dialog.duplicates, duplicates = dialog.duplicates,
onDismissRequest = bulkFavoriteScreenModel::dismissDialog, onDismissRequest = bulkFavoriteScreenModel::dismissDialog,
onConfirm = { bulkFavoriteScreenModel.addFavorite(dialog.manga) }, onConfirm = {
bulkFavoriteScreenModel.toggleSelectionMode()
bulkFavoriteScreenModel.addFavorite(dialog.manga)
},
onOpenManga = { navigator.push(MangaScreen(it.id)) }, onOpenManga = { navigator.push(MangaScreen(it.id)) },
onMigrate = { onMigrate = {
PreMigrationScreen.navigateToMigration( PreMigrationScreen.navigateToMigration(