feat(editor): 删除前二次确认
This commit is contained in:
parent
df3ec533ea
commit
31c58b3a03
5 changed files with 24 additions and 15 deletions
|
|
@ -29,7 +29,10 @@ fun WarningDialog(
|
||||||
text = { Text(description) },
|
text = { Text(description) },
|
||||||
confirmButton = stringResource(R.string.action_confirm),
|
confirmButton = stringResource(R.string.action_confirm),
|
||||||
dismissButton = stringResource(R.string.action_cancel),
|
dismissButton = stringResource(R.string.action_cancel),
|
||||||
onConfirm = onConfirm,
|
onConfirm = {
|
||||||
|
onConfirm()
|
||||||
|
onDismiss()
|
||||||
|
},
|
||||||
onDismiss = onDismiss,
|
onDismiss = onDismiss,
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,8 @@ fun TodoEditorPage(
|
||||||
animatedVisibilityScope: AnimatedVisibilityScope,
|
animatedVisibilityScope: AnimatedVisibilityScope,
|
||||||
modifier: Modifier = Modifier
|
modifier: Modifier = Modifier
|
||||||
) {
|
) {
|
||||||
var showConfirmDialog by rememberSaveable { mutableStateOf(false) }
|
var showExitConfirmDialog by rememberSaveable { mutableStateOf(false) }
|
||||||
|
var showDeleteConfirmDialog by rememberSaveable { mutableStateOf(false) }
|
||||||
|
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior()
|
val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior()
|
||||||
|
|
@ -84,7 +85,7 @@ fun TodoEditorPage(
|
||||||
if ((toDo?.subject ?: 0) != selectedSubjectIndex) isModified = true
|
if ((toDo?.subject ?: 0) != selectedSubjectIndex) isModified = true
|
||||||
if ((toDo?.priority ?: 0f) != priorityState) isModified = true
|
if ((toDo?.priority ?: 0f) != priorityState) isModified = true
|
||||||
if (isModified) {
|
if (isModified) {
|
||||||
showConfirmDialog = true
|
showExitConfirmDialog = true
|
||||||
} else {
|
} else {
|
||||||
onNavigateUp()
|
onNavigateUp()
|
||||||
}
|
}
|
||||||
|
|
@ -105,20 +106,20 @@ fun TodoEditorPage(
|
||||||
icon = {
|
icon = {
|
||||||
Icon(
|
Icon(
|
||||||
imageVector = Icons.Outlined.Delete,
|
imageVector = Icons.Outlined.Delete,
|
||||||
contentDescription = stringResource(R.string.action_delete)
|
contentDescription = null
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
text = { Text(stringResource(R.string.action_delete)) },
|
text = { Text(stringResource(R.string.action_delete)) },
|
||||||
expanded = true,
|
expanded = true,
|
||||||
containerColor = MaterialTheme.colorScheme.errorContainer,
|
containerColor = MaterialTheme.colorScheme.errorContainer,
|
||||||
onClick = onDelete
|
onClick = { showDeleteConfirmDialog = true }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
AnimatedExtendedFloatingActionButton(
|
AnimatedExtendedFloatingActionButton(
|
||||||
icon = {
|
icon = {
|
||||||
Icon(
|
Icon(
|
||||||
imageVector = Icons.Outlined.Save,
|
imageVector = Icons.Outlined.Save,
|
||||||
contentDescription = stringResource(R.string.action_save)
|
contentDescription = null
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
text = { Text(stringResource(R.string.action_save)) },
|
text = { Text(stringResource(R.string.action_save)) },
|
||||||
|
|
@ -246,13 +247,21 @@ fun TodoEditorPage(
|
||||||
}
|
}
|
||||||
|
|
||||||
WarningDialog(
|
WarningDialog(
|
||||||
visible = showConfirmDialog,
|
visible = showExitConfirmDialog,
|
||||||
icon = Icons.AutoMirrored.Outlined.Undo,
|
icon = Icons.AutoMirrored.Outlined.Undo,
|
||||||
description = stringResource(R.string.tip_discard_changes),
|
description = stringResource(R.string.tip_discard_changes),
|
||||||
onConfirm = {
|
onConfirm = {
|
||||||
showConfirmDialog = false
|
showExitConfirmDialog = false
|
||||||
onNavigateUp()
|
onNavigateUp()
|
||||||
},
|
},
|
||||||
onDismiss = { showConfirmDialog = false }
|
onDismiss = { showExitConfirmDialog = false }
|
||||||
|
)
|
||||||
|
|
||||||
|
WarningDialog(
|
||||||
|
visible = showDeleteConfirmDialog,
|
||||||
|
icon = Icons.Outlined.Delete,
|
||||||
|
description = stringResource(R.string.tip_delete_task, 1),
|
||||||
|
onConfirm = onDelete,
|
||||||
|
onDismiss = { showDeleteConfirmDialog = false }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -212,10 +212,7 @@ fun MainPage(
|
||||||
visible = showDeleteConfirmDialog,
|
visible = showDeleteConfirmDialog,
|
||||||
icon = Icons.Outlined.Delete,
|
icon = Icons.Outlined.Delete,
|
||||||
description = stringResource(R.string.tip_delete_task, selectedTodoIds.value.size),
|
description = stringResource(R.string.tip_delete_task, selectedTodoIds.value.size),
|
||||||
onConfirm = {
|
onConfirm = { viewModel.deleteSelectedTodo() },
|
||||||
showDeleteConfirmDialog = false
|
|
||||||
viewModel.deleteSelectedTodo()
|
|
||||||
},
|
|
||||||
onDismiss = { showDeleteConfirmDialog = false }
|
onDismiss = { showDeleteConfirmDialog = false }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -31,7 +31,7 @@
|
||||||
<string name="title_selected_count">已选择 %s 项</string>
|
<string name="title_selected_count">已选择 %s 项</string>
|
||||||
<string name="action_confirm">确定</string>
|
<string name="action_confirm">确定</string>
|
||||||
<string name="title_warning">警告</string>
|
<string name="title_warning">警告</string>
|
||||||
<string name="tip_delete_task">即将删除你选择的 %s 项待办。删除后将无法恢复这些待办,确定删除?</string>
|
<string name="tip_delete_task">即将删除 %s 项待办。删除后将无法恢复这些待办,确定删除?</string>
|
||||||
<string name="action_back">返回</string>
|
<string name="action_back">返回</string>
|
||||||
<string name="pref_about">关于</string>
|
<string name="pref_about">关于</string>
|
||||||
<string name="pref_about_desc">关于本应用</string>
|
<string name="pref_about_desc">关于本应用</string>
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@
|
||||||
<string name="title_selected_count">%s selected</string>
|
<string name="title_selected_count">%s selected</string>
|
||||||
<string name="action_confirm">Confirm</string>
|
<string name="action_confirm">Confirm</string>
|
||||||
<string name="title_warning">Warning</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>
|
<string name="tip_delete_task">You are about to delete the %s tasks. Once deleted, these tasks cannot be recovered. Are you sure you want to delete them?</string>
|
||||||
<string name="placeholder_divider" translatable="false">/</string>
|
<string name="placeholder_divider" translatable="false">/</string>
|
||||||
<string name="action_back">Back</string>
|
<string name="action_back">Back</string>
|
||||||
<string name="pref_about">About</string>
|
<string name="pref_about">About</string>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue