refactor: 优化全选逻辑和样式
This commit is contained in:
parent
b16c2c2a85
commit
0c5d30a486
3 changed files with 8 additions and 12 deletions
|
|
@ -91,7 +91,7 @@ fun MainPage(
|
||||||
selectedTodoIds = selectedTodoIds,
|
selectedTodoIds = selectedTodoIds,
|
||||||
selectedMode = !isSelectedIdsEmpty,
|
selectedMode = !isSelectedIdsEmpty,
|
||||||
onCancelSelect = { viewModel.clearAllTodoSelection() },
|
onCancelSelect = { viewModel.clearAllTodoSelection() },
|
||||||
onSelectAll = { viewModel.toggleAllSelected() },
|
onSelectAll = { viewModel.selectAllTodos() },
|
||||||
onDeleteSelectedTodo = { showDeleteConfirmDialog = true },
|
onDeleteSelectedTodo = { showDeleteConfirmDialog = true },
|
||||||
toSettingsPage = toSettingsPage
|
toSettingsPage = toSettingsPage
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,10 @@ fun TodoCard(
|
||||||
},
|
},
|
||||||
modifier = Modifier.padding(start = 5.dp)
|
modifier = Modifier.padding(start = 5.dp)
|
||||||
) {
|
) {
|
||||||
Text(priority.getDisplayName(context))
|
Text(
|
||||||
|
text = priority.getDisplayName(context),
|
||||||
|
textDecoration = if (completed) TextDecoration.LineThrough else TextDecoration.None,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
|
|
|
||||||
|
|
@ -116,19 +116,12 @@ class MainViewModel : ViewModel() {
|
||||||
/**
|
/**
|
||||||
* 切换是否全选
|
* 切换是否全选
|
||||||
*/
|
*/
|
||||||
fun toggleAllSelected() {
|
fun selectAllTodos() {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
toDos.firstOrNull()?.let { todos ->
|
toDos.firstOrNull()?.let { todos ->
|
||||||
|
// 无论是否有选择都全选
|
||||||
val allIds = todos.map { it.id }
|
val allIds = todos.map { it.id }
|
||||||
_selectedTodoIds.update { currentSelectedIds ->
|
_selectedTodoIds.value = allIds
|
||||||
if (currentSelectedIds.containsAll(allIds)) {
|
|
||||||
// 如果当前是全选状态,取消所有选择(切换为全不选)
|
|
||||||
emptyList()
|
|
||||||
} else {
|
|
||||||
// 如果当前不是全选状态,选中所有项
|
|
||||||
allIds
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue