feat: lut rename
This commit is contained in:
1 parent
696f291b86
commit
9834048d8d
6 files changed
+141
-11
No files matched your search
@@ -210,6 +210,46 @@ class CustomImportManager(private val context: Context) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新自定义 LUT 名称
|
||||
*/
|
||||
fun updateLutName(lutId: String, newName: String): Boolean {
|
||||
return try {
|
||||
val configFile = File(context.filesDir, CUSTOM_LUT_CONFIG)
|
||||
if (!configFile.exists()) {
|
||||
return false
|
||||
}
|
||||
|
||||
val configJson = configFile.readText()
|
||||
val jsonArray = JSONArray(configJson)
|
||||
val newArray = JSONArray()
|
||||
|
||||
var updated = false
|
||||
for (i in 0 until jsonArray.length()) {
|
||||
val lutObj = jsonArray.getJSONObject(i)
|
||||
if (lutObj.getString("id") == lutId) {
|
||||
// 更新名称
|
||||
lutObj.put("name", JSONObject().apply {
|
||||
put("en", newName)
|
||||
put("zh", newName)
|
||||
})
|
||||
updated = true
|
||||
}
|
||||
newArray.put(lutObj)
|
||||
}
|
||||
|
||||
if (updated) {
|
||||
configFile.writeText(newArray.toString())
|
||||
PLog.d(TAG, "LUT name updated: $lutId -> $newName")
|
||||
}
|
||||
|
||||
updated
|
||||
} catch (e: Exception) {
|
||||
PLog.e(TAG, "Failed to update LUT name", e)
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除自定义 LUT
|
||||
*/
|
||||
|
||||
@@ -9,6 +9,7 @@ import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Add
|
||||
import androidx.compose.material.icons.filled.Delete
|
||||
import androidx.compose.material.icons.filled.Edit
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
@@ -204,6 +205,20 @@ fun CustomImportSection(
|
||||
CustomContentItem(
|
||||
name = lut.getName(),
|
||||
type = stringResource(R.string.lut_type),
|
||||
showEditButton = true, // LUT 支持编辑
|
||||
onEdit = { newName ->
|
||||
scope.launch {
|
||||
val success = withContext(Dispatchers.IO) {
|
||||
customImportManager.updateLutName(lut.id, newName)
|
||||
}
|
||||
if (success) {
|
||||
importResult = "已更新: $newName"
|
||||
refreshCustomContent()
|
||||
} else {
|
||||
importResult = "更新失败"
|
||||
}
|
||||
}
|
||||
},
|
||||
onDelete = {
|
||||
scope.launch {
|
||||
withContext(Dispatchers.IO) {
|
||||
@@ -246,9 +261,13 @@ private fun CustomContentItem(
|
||||
name: String,
|
||||
type: String,
|
||||
onDelete: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
modifier: Modifier = Modifier,
|
||||
showEditButton: Boolean = false,
|
||||
onEdit: ((String) -> Unit)? = null
|
||||
) {
|
||||
var showDeleteDialog by remember { mutableStateOf(false) }
|
||||
var showEditDialog by remember { mutableStateOf(false) }
|
||||
var editedName by remember { mutableStateOf(name) }
|
||||
|
||||
Row(
|
||||
modifier = modifier
|
||||
@@ -276,18 +295,80 @@ private fun CustomContentItem(
|
||||
)
|
||||
}
|
||||
|
||||
IconButton(
|
||||
onClick = { showDeleteDialog = true },
|
||||
modifier = Modifier.size(36.dp)
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(4.dp)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Delete,
|
||||
contentDescription = stringResource(R.string.delete),
|
||||
tint = Color(0xFFFF5252)
|
||||
)
|
||||
// 编辑按钮(仅当 showEditButton 为 true 时显示)
|
||||
if (showEditButton && onEdit != null) {
|
||||
IconButton(
|
||||
onClick = {
|
||||
editedName = name
|
||||
showEditDialog = true
|
||||
},
|
||||
modifier = Modifier.size(36.dp)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Edit,
|
||||
contentDescription = stringResource(R.string.edit),
|
||||
tint = Color(0xFF4CAF50)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// 删除按钮
|
||||
IconButton(
|
||||
onClick = { showDeleteDialog = true },
|
||||
modifier = Modifier.size(36.dp)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Delete,
|
||||
contentDescription = stringResource(R.string.delete),
|
||||
tint = Color(0xFFFF5252)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 编辑对话框
|
||||
if (showEditDialog) {
|
||||
AlertDialog(
|
||||
onDismissRequest = { showEditDialog = false },
|
||||
title = {
|
||||
Text(text = stringResource(R.string.edit_name))
|
||||
},
|
||||
text = {
|
||||
OutlinedTextField(
|
||||
value = editedName,
|
||||
onValueChange = { editedName = it },
|
||||
singleLine = true,
|
||||
label = { Text(stringResource(R.string.name)) },
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
)
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(
|
||||
onClick = {
|
||||
if (editedName.isNotBlank() && editedName != name) {
|
||||
onEdit?.invoke(editedName)
|
||||
}
|
||||
showEditDialog = false
|
||||
},
|
||||
enabled = editedName.isNotBlank()
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.confirm),
|
||||
color = Color(0xFF4CAF50)
|
||||
)
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = { showEditDialog = false }) {
|
||||
Text(text = stringResource(R.string.cancel))
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
// 删除确认对话框
|
||||
if (showDeleteDialog) {
|
||||
AlertDialog(
|
||||
|
||||
@@ -59,6 +59,9 @@
|
||||
<string name="none">无</string>
|
||||
<string name="show_app_branding">显示 App 品牌</string>
|
||||
<string name="export_with_frame_confirm">导出带边框水印的照片?</string>
|
||||
<string name="edit_name">编辑名称</string>
|
||||
<string name="name">名称</string>
|
||||
<string name="confirm">确认</string>
|
||||
|
||||
<!-- Developer Options -->
|
||||
<string name="settings_section_developer">开发者选项</string>
|
||||
|
||||
@@ -128,6 +128,9 @@
|
||||
<string name="delete_confirm_title">删除确认</string>
|
||||
<string name="delete_custom_content_confirm">删除 "%s" 吗?</string>
|
||||
<string name="importing">导入中...</string>
|
||||
<string name="edit_name">编辑名称</string>
|
||||
<string name="name">名称</string>
|
||||
<string name="confirm">确认</string>
|
||||
|
||||
<!-- Developer Options -->
|
||||
<string name="settings_section_developer">开发者选项</string>
|
||||
|
||||
@@ -129,6 +129,9 @@
|
||||
<string name="delete_confirm_title">Delete Confirmation</string>
|
||||
<string name="delete_custom_content_confirm">Delete "%s"?</string>
|
||||
<string name="importing">Importing...</string>
|
||||
<string name="edit_name">Edit Name</string>
|
||||
<string name="name">Name</string>
|
||||
<string name="confirm">Confirm</string>
|
||||
|
||||
<!-- Developer Options -->
|
||||
<string name="settings_section_developer">Developer Options</string>
|
||||
|
||||
Reference in new issue
Block a user