Allow skip duplicates
This commit is contained in:
parent
b64c7f30c0
commit
83910501b7
4 changed files with 94 additions and 1 deletions
|
|
@ -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 <--
|
||||
|
|
|
|||
|
|
@ -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 -> {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 <--
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
Loading…
Reference in a new issue