feat: 删除待办前二次确认
This commit is contained in:
parent
9ffe228d8c
commit
3855caf3cb
4 changed files with 76 additions and 8 deletions
|
|
@ -27,6 +27,7 @@ import androidx.compose.runtime.setValue
|
|||
import androidx.compose.ui.Modifier
|
||||
import androidx.window.core.layout.WindowWidthSizeClass
|
||||
import cn.super12138.todo.logic.database.TodoEntity
|
||||
import cn.super12138.todo.ui.pages.main.components.TodoDeleteConfirmDialog
|
||||
import cn.super12138.todo.ui.pages.main.components.TodoFAB
|
||||
import cn.super12138.todo.ui.pages.main.components.TodoTopAppBar
|
||||
import cn.super12138.todo.ui.viewmodels.MainViewModel
|
||||
|
|
@ -45,7 +46,8 @@ fun MainPage(viewModel: MainViewModel, modifier: Modifier = Modifier) {
|
|||
|
||||
val selectedEditTodoItem = viewModel.selectedEditTodo
|
||||
val selectedTodoIds = viewModel.selectedTodoIds.collectAsState()
|
||||
var openBottomSheet by rememberSaveable { mutableStateOf(false) }
|
||||
var showBottomSheet by rememberSaveable { mutableStateOf(false) }
|
||||
var showDeleteConfirmDialog by rememberSaveable { mutableStateOf(false) }
|
||||
val bottomSheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
|
||||
val scope = rememberCoroutineScope()
|
||||
|
||||
|
|
@ -73,7 +75,7 @@ fun MainPage(viewModel: MainViewModel, modifier: Modifier = Modifier) {
|
|||
selectedMode = !isSelectedIdsEmpty,
|
||||
onCancelSelect = { viewModel.clearAllTodoSelection() },
|
||||
onSelectAll = { viewModel.toggleAllSelected() },
|
||||
onDeleteSelectedTodo = { viewModel.deleteSelectedTodo() },
|
||||
onDeleteSelectedTodo = { showDeleteConfirmDialog = true },
|
||||
toSettingsPage = {}
|
||||
)
|
||||
},
|
||||
|
|
@ -85,7 +87,7 @@ fun MainPage(viewModel: MainViewModel, modifier: Modifier = Modifier) {
|
|||
) {
|
||||
TodoFAB(
|
||||
expanded = isExpanded,
|
||||
onClick = { openBottomSheet = true }
|
||||
onClick = { showBottomSheet = true }
|
||||
)
|
||||
}
|
||||
},
|
||||
|
|
@ -106,7 +108,7 @@ fun MainPage(viewModel: MainViewModel, modifier: Modifier = Modifier) {
|
|||
list = filteredTodoList,
|
||||
onItemClick = { item ->
|
||||
if (isSelectedIdsEmpty) {
|
||||
openBottomSheet = true
|
||||
showBottomSheet = true
|
||||
viewModel.setEditTodoItem(item)
|
||||
} else {
|
||||
viewModel.toggleTodoSelection(item)
|
||||
|
|
@ -148,7 +150,7 @@ fun MainPage(viewModel: MainViewModel, modifier: Modifier = Modifier) {
|
|||
list = filteredTodoList,
|
||||
onItemClick = { item ->
|
||||
if (isSelectedIdsEmpty) {
|
||||
openBottomSheet = true
|
||||
showBottomSheet = true
|
||||
viewModel.setEditTodoItem(item)
|
||||
} else {
|
||||
viewModel.toggleTodoSelection(item)
|
||||
|
|
@ -178,11 +180,11 @@ fun MainPage(viewModel: MainViewModel, modifier: Modifier = Modifier) {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (openBottomSheet) {
|
||||
if (showBottomSheet) {
|
||||
TodoBottomSheet(
|
||||
sheetState = bottomSheetState,
|
||||
onDismissRequest = {
|
||||
openBottomSheet = false
|
||||
showBottomSheet = false
|
||||
viewModel.setEditTodoItem(null)
|
||||
},
|
||||
toDo = selectedEditTodoItem,
|
||||
|
|
@ -195,7 +197,7 @@ fun MainPage(viewModel: MainViewModel, modifier: Modifier = Modifier) {
|
|||
.launch { bottomSheetState.hide() }
|
||||
.invokeOnCompletion {
|
||||
if (!bottomSheetState.isVisible) {
|
||||
openBottomSheet = false
|
||||
showBottomSheet = false
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
@ -204,4 +206,17 @@ fun MainPage(viewModel: MainViewModel, modifier: Modifier = Modifier) {
|
|||
}
|
||||
)
|
||||
}
|
||||
if (showDeleteConfirmDialog) {
|
||||
TodoDeleteConfirmDialog(
|
||||
onConfirm = {
|
||||
showDeleteConfirmDialog = false
|
||||
viewModel.apply {
|
||||
deleteSelectedTodo()
|
||||
clearAllTodoSelection()
|
||||
}
|
||||
},
|
||||
onDismiss = { showDeleteConfirmDialog = false },
|
||||
deleteTodoCount = selectedTodoIds.value.size
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
package cn.super12138.todo.ui.pages.main.components
|
||||
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.Delete
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.FilledTonalButton
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import cn.super12138.todo.R
|
||||
|
||||
@Composable
|
||||
fun TodoDeleteConfirmDialog(
|
||||
onConfirm: () -> Unit,
|
||||
onDismiss: () -> Unit,
|
||||
deleteTodoCount: Int,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
AlertDialog(
|
||||
icon = {
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.Delete,
|
||||
contentDescription = stringResource(R.string.action_delete)
|
||||
)
|
||||
},
|
||||
title = {
|
||||
Text(stringResource(R.string.title_warning))
|
||||
},
|
||||
text = {
|
||||
Text(stringResource(R.string.tip_delete_task, deleteTodoCount))
|
||||
},
|
||||
confirmButton = {
|
||||
FilledTonalButton(onClick = onConfirm) {
|
||||
Text(stringResource(R.string.action_confirm))
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = onDismiss) {
|
||||
Text(stringResource(R.string.action_cancel))
|
||||
}
|
||||
},
|
||||
onDismissRequest = onDismiss
|
||||
)
|
||||
}
|
||||
|
|
@ -29,4 +29,7 @@
|
|||
<string name="tip_clear_selected_items">清除已选择的项目</string>
|
||||
<string name="tip_select_all">全选</string>
|
||||
<string name="title_selected_count">已选择 %s 项</string>
|
||||
<string name="action_confirm">确定</string>
|
||||
<string name="title_warning">警告</string>
|
||||
<string name="tip_delete_task">即将删除你选择的 %s 项待办。删除后将无法恢复这些待办,确定删除?</string>
|
||||
</resources>
|
||||
|
|
@ -28,4 +28,7 @@
|
|||
<string name="tip_clear_selected_items">Clear selected items</string>
|
||||
<string name="tip_select_all">Select all</string>
|
||||
<string name="title_selected_count">%s selected</string>
|
||||
<string name="action_confirm">Confirm</string>
|
||||
<string name="title_warning">Warning</string>
|
||||
<string name="tip_delete_task">You are about to delete the %s selected tasks. Once deleted, these tasks cannot be recovered. Are you sure you want to delete them?</string>
|
||||
</resources>
|
||||
Loading…
Reference in a new issue