Skip to content

Commit

Permalink
BulkSelection: avoid using toggle when Select all
Browse files Browse the repository at this point in the history
(cherry picked from commit 695f872b381feca1051f0f5133a0288d252691e5)
  • Loading branch information
cuong-tran committed Apr 26, 2024
1 parent 097ce0e commit 45553eb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 45553eb

Please sign in to comment.