Allow skip duplicates

This commit is contained in:
Cuong M. Tran 2024-03-06 15:42:21 +07:00 committed by Cuong Tran
parent b64c7f30c0
commit 83910501b7
No known key found for this signature in database
GPG key ID: 733AA7624B9315C2
4 changed files with 94 additions and 1 deletions

View file

@ -57,3 +57,60 @@ fun DuplicateMangaDialog(
},
)
}
// KMK -->
@Composable
fun AllowDuplicateDialog(
onDismissRequest: () -> Unit,
onAllowDuplicate: () -> Unit,
onSkipDuplicate: () -> Unit,
onOpenManga: () -> Unit = { },
) {
AlertDialog(
onDismissRequest = onDismissRequest,
dismissButton = {
TextButton(onClick = onDismissRequest) {
Text(text = stringResource(MR.strings.action_cancel))
}
},
title = {
Text(text = stringResource(MR.strings.are_you_sure))
},
text = {
Text(text = stringResource(MR.strings.confirm_add_duplicate_manga))
},
confirmButton = {
FlowRow(
horizontalArrangement = Arrangement.spacedBy(MaterialTheme.padding.extraSmall),
) {
TextButton(
onClick = {
onDismissRequest()
onOpenManga()
},
) {
Text(text = stringResource(MR.strings.action_show_manga))
}
TextButton(
onClick = {
onDismissRequest()
onSkipDuplicate()
},
) {
Text(text = stringResource(MR.strings.action_skip_duplicate_manga))
}
TextButton(
onClick = {
onDismissRequest()
onAllowDuplicate()
},
) {
Text(text = stringResource(MR.strings.action_allow_duplicate_manga))
}
}
},
)
}
// KMK <--

View file

@ -45,6 +45,7 @@ import eu.kanade.presentation.browse.components.SavedSearchCreateDialog
import eu.kanade.presentation.browse.components.SavedSearchDeleteDialog
import eu.kanade.presentation.browse.components.SelectionToolbar
import eu.kanade.presentation.category.components.ChangeCategoryDialog
import eu.kanade.presentation.manga.AllowDuplicateDialog
import eu.kanade.presentation.manga.DuplicateMangaDialog
import eu.kanade.presentation.util.AssistContentScreen
import eu.kanade.presentation.util.Screen
@ -395,6 +396,17 @@ data class BrowseSourceScreen(
},
)
}
is BrowseSourceScreenModel.Dialog.AllowDuplicate -> {
AllowDuplicateDialog(
onDismissRequest = onDismissRequest,
onAllowDuplicate = {
screenModel.addFavoriteDuplicate()
},
onSkipDuplicate = {
screenModel.addFavoriteDuplicate(skipDuplicate = true)
},
)
}
// KMK <--
else -> {}
}

View file

@ -477,7 +477,16 @@ open class BrowseSourceScreenModel(
fun addFavorite() {
screenModelScope.launch {
val mangaList = state.value.selection
if (hasDuplicateLibraryMangas(state.value.selection))
setDialog(Dialog.AllowDuplicate)
else
addFavoriteDuplicate()
}
}
fun addFavoriteDuplicate(skipDuplicate: Boolean = false) {
screenModelScope.launch {
val mangaList = if (skipDuplicate) getNotDuplicateLibraryMangas() else state.value.selection
val categories = getCategories()
val defaultCategoryId = libraryPreferences.defaultCategory().get()
val defaultCategory = categories.find { it.id == defaultCategoryId.toLong() }
@ -574,6 +583,18 @@ open class BrowseSourceScreenModel(
val common = mangaCategories.reduce { set1, set2 -> set1.intersect(set2) }
return mangaCategories.flatten().distinct().subtract(common)
}
private suspend fun getNotDuplicateLibraryMangas(): List<Manga> {
return state.value.selection.filterNot { manga ->
getDuplicateLibraryManga.await(manga).isNotEmpty()
}
}
private suspend fun hasDuplicateLibraryMangas(mangas: List<Manga>): Boolean {
return mangas.fastAny { manga ->
getDuplicateLibraryManga.await(manga).isNotEmpty()
}
}
// KMK <--
sealed interface Dialog {
@ -595,6 +616,7 @@ open class BrowseSourceScreenModel(
val mangas: List<Manga>,
val initialSelection: ImmutableList<CheckboxState<Category>>,
) : Dialog
data object AllowDuplicate : Dialog
// KMK <--
}

View file

@ -689,6 +689,8 @@
<string name="source_not_installed">Source not installed: %1$s</string>
<string name="snack_add_to_library">Add to library?</string>
<string name="description_placeholder">No description</string>
<string name="action_allow_duplicate_manga">Allow duplicate</string>
<string name="action_skip_duplicate_manga">Skip duplicate</string>
<!-- Manga chapters -->
<string name="display_mode_chapter">Chapter %1$s</string>