相册预览界面增加删除按钮和二次确认

This commit is contained in:
Developer
2026-04-18 12:14:06 +08:00
parent b85bc11c2a
commit 871f6637ac

View File

@@ -201,6 +201,8 @@ fun GalleryScreen(
// 大图查看对话框(支持双指缩放) // 大图查看对话框(支持双指缩放)
if (selectedImageUri != null) { if (selectedImageUri != null) {
var showDeleteConfirm by remember { mutableStateOf(false) }
AlertDialog( AlertDialog(
onDismissRequest = { selectedImageUri = null }, onDismissRequest = { selectedImageUri = null },
title = { title = {
@@ -210,8 +212,17 @@ fun GalleryScreen(
verticalAlignment = Alignment.CenterVertically verticalAlignment = Alignment.CenterVertically
) { ) {
Text("图片预览") Text("图片预览")
IconButton(onClick = { selectedImageUri = null }) { Row {
Icon(Icons.Default.Close, contentDescription = "关闭") IconButton(onClick = { showDeleteConfirm = true }) {
Icon(
Icons.Default.Delete,
contentDescription = "删除",
tint = Color.Red
)
}
IconButton(onClick = { selectedImageUri = null }) {
Icon(Icons.Default.Close, contentDescription = "关闭")
}
} }
} }
}, },
@@ -229,6 +240,32 @@ fun GalleryScreen(
} }
} }
) )
// 删除二次确认对话框
if (showDeleteConfirm) {
AlertDialog(
onDismissRequest = { showDeleteConfirm = false },
title = { Text("确认删除") },
text = { Text("确定要删除这张图片吗?删除后无法恢复。") },
confirmButton = {
TextButton(onClick = {
scope.launch {
deleteImage(context, selectedImageUri!!)
images = loadImagesFromGallery(context)
selectedImageUri = null
showDeleteConfirm = false
}
}) {
Text("确定删除", color = Color.Red)
}
},
dismissButton = {
TextButton(onClick = { showDeleteConfirm = false }) {
Text("取消")
}
}
)
}
} }
} }