BulkSelection: avoid using toggle when Select all
(cherry picked from commit 695f872b381feca1051f0f5133a0288d252691e5)
This commit is contained in:
parent
097ce0e2c3
commit
45553eb096
2 changed files with 16 additions and 6 deletions
|
|
@ -56,10 +56,9 @@ fun GlobalSearchScreen(
|
|||
state.filteredItems.forEach { (_, result) ->
|
||||
when (result) {
|
||||
is SearchItemResult.Success -> {
|
||||
result.result.map{manga ->
|
||||
|
||||
result.result.forEach { manga ->
|
||||
if (!bulkFavoriteState.selection.contains(manga))
|
||||
bulkFavoriteScreenModel.toggleSelection(manga)
|
||||
bulkFavoriteScreenModel.select(manga)
|
||||
}
|
||||
}
|
||||
else -> {}
|
||||
|
|
|
|||
|
|
@ -84,12 +84,23 @@ class BulkFavoriteScreenModel(
|
|||
mutableState.update { it.copy(selection = persistentListOf()) }
|
||||
}
|
||||
|
||||
fun toggleSelection(manga: Manga) {
|
||||
fun select(manga: Manga) {
|
||||
toggleSelection(manga, toSelectedState = true)
|
||||
}
|
||||
|
||||
fun unselect(manga: Manga) {
|
||||
toggleSelection(manga, toSelectedState = false)
|
||||
}
|
||||
|
||||
/**
|
||||
* @param toSelectedState set to true to only Select, set to false to only Unselect
|
||||
*/
|
||||
fun toggleSelection(manga: Manga, toSelectedState: Boolean? = null) {
|
||||
mutableState.update { state ->
|
||||
val newSelection = state.selection.mutate { list ->
|
||||
if (list.fastAny { it.id == manga.id }) {
|
||||
if (toSelectedState != true && list.fastAny { it.id == manga.id }) {
|
||||
list.removeAll { it.id == manga.id }
|
||||
} else {
|
||||
} else if (toSelectedState != false) {
|
||||
list.add(manga)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue