feat: lut category

This commit is contained in:
zhoubinjia committed 2026-01-20 13:38:58 +08:00
1 parent f357b87675
commit f5cd548b67
9 files changed
+571 -164

No files matched your search

+1 -1
View File
@@ -18,7 +18,7 @@
- [x] LUT顺序、编辑
- [x] 降噪等级
- [x] 音量键曝光补偿
- [ ] LUT分类
- [x] LUT分类
- [ ] 摄像头方向修正
- [ ] 水印 LOGO 缺少
- [ ] 焦段多余
@@ -31,6 +31,26 @@ class CustomImportManager(private val context: Context) {
// 配置文件
private const val CUSTOM_LUT_CONFIG = "custom_luts.json"
private const val CUSTOM_FRAME_CONFIG = "custom_frames.json"
private const val CATEGORY_OVERRIDES_CONFIG = "category_overrides.json"
}
/**
* 获取分类重定向/重写映射
*/
fun getCategoryOverrides(): Map<String, String> {
return try {
val file = File(context.filesDir, CATEGORY_OVERRIDES_CONFIG)
if (!file.exists()) return emptyMap()
val json = JSONObject(file.readText())
val map = mutableMapOf<String, String>()
json.keys().forEach { key ->
map[key] = json.getString(key)
}
map
} catch (e: Exception) {
PLog.e(TAG, "Failed to get category overrides", e)
emptyMap()
}
}
private val customLutDir: File
@@ -212,7 +232,8 @@ class CustomImportManager(private val context: Context) {
fileName = lutFile.absolutePath,
isBuiltIn = false,
isDefault = false,
isVip = false
isVip = false,
category = lutObj.optString("category", "")
)
)
}
@@ -308,45 +329,88 @@ class CustomImportManager(private val context: Context) {
}
}
/**
* 更新自定义边框名称
*/
fun updateFrameName(frameId: String, newName: String): Boolean {
return try {
val configFile = File(context.filesDir, CUSTOM_FRAME_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 frameObj = jsonArray.getJSONObject(i)
if (frameObj.getString("id") == frameId) {
// 更新名称
frameObj.put("name", JSONObject().apply {
put("en", newName)
put("zh", newName)
})
updated = true
/**
* 更新 LUT 分类(支持内置和自定义)
*/
fun updateLutCategory(lutId: String, newCategory: String): Boolean {
return try {
// 1. 同步到分类重写文件 (核心:支持内置)
val overridesFile = File(context.filesDir, CATEGORY_OVERRIDES_CONFIG)
val overridesJson = if (overridesFile.exists()) {
JSONObject(overridesFile.readText())
} else {
JSONObject()
}
newArray.put(frameObj)
}
overridesJson.put(lutId, newCategory)
overridesFile.writeText(overridesJson.toString())
if (updated) {
configFile.writeText(newArray.toString())
PLog.d(TAG, "Frame name updated: $frameId -> $newName")
}
// 2. 如果是自定义滤镜,也同步更新 custom_luts.json (保持一致性)
val configFile = File(context.filesDir, CUSTOM_LUT_CONFIG)
if (configFile.exists()) {
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("category", newCategory)
updated = true
}
newArray.put(lutObj)
}
if (updated) {
configFile.writeText(newArray.toString())
}
}
updated
} catch (e: Exception) {
PLog.e(TAG, "Failed to update frame name", e)
false
PLog.d(TAG, "LUT category updated: $lutId -> $newCategory")
true
} catch (e: Exception) {
PLog.e(TAG, "Failed to update LUT category", e)
false
}
}
/**
* 更新自定义边框名称
*/
fun updateFrameName(frameId: String, newName: String): Boolean {
return try {
val configFile = File(context.filesDir, CUSTOM_FRAME_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 frameObj = jsonArray.getJSONObject(i)
if (frameObj.getString("id") == frameId) {
// 更新名称
frameObj.put("name", JSONObject().apply {
put("en", newName)
put("zh", newName)
})
updated = true
}
newArray.put(frameObj)
}
if (updated) {
configFile.writeText(newArray.toString())
PLog.d(TAG, "Frame name updated: $frameId -> $newName")
}
updated
} catch (e: Exception) {
PLog.e(TAG, "Failed to update frame name", e)
false
}
}
}
/**
* 删除自定义 LUT
@@ -27,7 +27,7 @@ data class LutConfig(
if (data != null) {
return FloatBuffer.wrap(data)
}
val buffer = byteBuffer ?: throw IllegalStateException("No data available in LutConfig")
val fb = FloatBuffer.allocate(size * size * size * 3)
buffer.position(0)
@@ -37,7 +37,7 @@ data class LutConfig(
fb.position(0)
return fb
}
/**
* 获取用于 OpenGL 纹理上传的 ByteBuffer (GL_RGB8 格式)
* 将浮点数据转换为 0-255 的字节数据,或者直接返回已有的 byteBuffer
@@ -47,7 +47,7 @@ data class LutConfig(
byteBuffer.position(0)
return byteBuffer
}
val floatData = data ?: throw IllegalStateException("No data available in LutConfig")
val byteData = ByteArray(floatData.size)
for (i in floatData.indices) {
@@ -60,7 +60,7 @@ data class LutConfig(
buffer.position(0)
return buffer
}
/**
* 验证 LUT 数据是否有效
*/
@@ -68,24 +68,24 @@ data class LutConfig(
val expectedSize = size * size * size * 3
return size > 0 && (data?.size == expectedSize || byteBuffer?.capacity() == expectedSize)
}
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as LutConfig
if (size != other.size) return false
if (data != null) {
if (other.data == null || !data.contentEquals(other.data)) return false
} else if (other.data != null) return false
if (byteBuffer != other.byteBuffer) return false
if (title != other.title) return false
return true
}
override fun hashCode(): Int {
var result = size
result = 31 * result + (data?.contentHashCode() ?: 0)
@@ -105,6 +105,7 @@ data class LutInfo(
val isBuiltIn: Boolean = true,
val isDefault: Boolean = false, // 是否为默认 LUT
val isVip: Boolean = false, // 是否为 VIP LUT
val category: String = "", // 分类
) {
/**
* 获取显示名称(优先当前系统语言)
@@ -87,11 +87,25 @@ class LutManager(private val context: Context) {
* 初始化,扫描可用的 LUT 文件(包括内置和自定义)
*/
fun initialize() {
val builtInLuts = LutParser.listAvailableLuts(context, BUILT_IN_LUT_FOLDER)
// 加载内置滤镜并强制把初始分类设为空(用户不想要内置分类标签)
val builtInLuts = LutParser.listAvailableLuts(context, BUILT_IN_LUT_FOLDER).map {
it.copy(category = "")
}
val customLuts = customImportManager.getCustomLuts()
val categoryOverrides = customImportManager.getCategoryOverrides()
// 将自定义 LUT 放在最前面
availableLuts = customLuts + builtInLuts
// 合并列表
val allLuts = customLuts + builtInLuts
// 应用分类重写 (用户手动创建的分类会通过这里恢复)
availableLuts = allLuts.map { lut ->
val overriddenCategory = categoryOverrides[lut.id]
if (overriddenCategory != null) {
lut.copy(category = overriddenCategory)
} else {
lut
}
}
PLog.d(TAG, "Found ${availableLuts.size} LUT files (${customLuts.size} custom, ${builtInLuts.size} built-in)")
}
@@ -100,14 +114,14 @@ class LutManager(private val context: Context) {
* 获取可用的 LUT 列表(自定义 LUT 在前)
*/
fun getAvailableLuts(): List<LutInfo> = availableLuts
/**
* 通过 ID 获取 LUT 信息
*/
fun getLutInfo(id: String): LutInfo? {
return availableLuts.find { it.id == id }
}
/**
* 加载 LUT 配置
*
@@ -158,7 +172,7 @@ class LutManager(private val context: Context) {
* 获取自定义导入管理器
*/
fun getCustomImportManager(): CustomImportManager = customImportManager
/**
* 预加载 LUT
*
@@ -168,20 +182,20 @@ class LutManager(private val context: Context) {
if (lutCache.get(id) != null) {
return // 已在缓存中
}
// 后台加载
Thread {
loadLut(id)
}.start()
}
/**
* 清除缓存中的特定 LUT
*/
fun evictLut(id: String) {
lutCache.remove(id)
}
/**
* 清除所有缓存
*/
@@ -189,7 +203,7 @@ class LutManager(private val context: Context) {
lutCache.evictAll()
PLog.d(TAG, "LUT cache cleared")
}
/**
* 获取缓存状态信息
*/
@@ -20,7 +20,7 @@ object LutParser {
*/
fun parse(inputStream: InputStream, title: String = ""): LutConfig {
val stream = if (inputStream.markSupported()) inputStream else inputStream.buffered()
// 先读取前 4 个字节判断是否为二进制格式
val header = ByteArray(4)
stream.mark(16)
@@ -51,12 +51,12 @@ object LutParser {
val dataType = buffer.int
val expectedSize = size * size * size * 3
//dataType 0 = UINT8, 1 = FLOAT32 (未来扩展)
if (dataType == 0) {
val directBuffer = ByteBuffer.allocateDirect(expectedSize)
.order(ByteOrder.nativeOrder())
// 将数据拷贝到 DirectByteBuffer 以便 OpenGL 使用
val data = ByteArray(expectedSize)
buffer.get(data)
@@ -90,13 +90,13 @@ object LutParser {
return try {
// 读取 config.json
val configPath = "$folder/config.json"
val configJson = context.assets.open(configPath).use {
val configJson = context.assets.open(configPath).use {
it.bufferedReader().readText()
}
val jsonObject = JSONObject(configJson)
val lutsArray = jsonObject.getJSONArray("luts")
// 按配置文件中的顺序读取 LUT
val lutList = mutableListOf<LutInfo>()
for (i in 0 until lutsArray.length()) {
@@ -106,13 +106,14 @@ object LutParser {
val nameObj = lutObj.getJSONObject("name")
val isDefault = lutObj.optBoolean("isDefault", false)
val isVip = lutObj.getBoolean("isVip")
val category = lutObj.optString("category", "Built-in")
// 读取多语言名称
val nameMap = mutableMapOf<String, String>()
nameObj.keys().forEach { lang ->
nameMap[lang] = nameObj.getString(lang)
}
lutList.add(
LutInfo(
id = id,
@@ -120,11 +121,12 @@ object LutParser {
fileName = "$folder/$path",
isBuiltIn = true,
isDefault = isDefault,
isVip = isVip
isVip = isVip,
category = category
)
)
}
PLog.d(TAG, "Loaded ${lutList.size} LUTs from config.json")
lutList
} catch (e: Exception) {
@@ -2,6 +2,7 @@ package com.hinnka.mycamera.ui.components
import android.graphics.Bitmap
import androidx.compose.foundation.*
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items
@@ -49,23 +50,38 @@ fun LutSelector(
val scrollState = rememberLazyListState()
val coroutineScope = rememberCoroutineScope()
var showLutEditDialogState by remember { mutableStateOf(false) }
// 分类逻辑
val categories = remember(availableLuts) {
listOf(null) + availableLuts.map { it.category }.distinct().filter { it.isNotEmpty() } + listOf("Custom")
}
var selectedCategory by remember { mutableStateOf<String?>(null) }
val filteredLuts = remember(selectedCategory, availableLuts) {
when (selectedCategory) {
null -> availableLuts
"Custom" -> availableLuts.filter { !it.isBuiltIn }
else -> availableLuts.filter { it.category == selectedCategory }
}
}
val actualShowLutEditDialog = onEditClick == null && showLutEditDialogState
// 在组件首次加载时滚动到当前选中的 LUT
LaunchedEffect(currentLutId) {
currentLutId?.let { lutId ->
val selectedIndex = availableLuts.indexOfFirst { it.id == lutId }
val selectedIndex = filteredLuts.indexOfFirst { it.id == lutId }
if (selectedIndex >= 2) {
coroutineScope.launch {
// 使用 animateScrollTo 进行平滑滚动,将选中项滚动到可视区域中心
scrollState.animateScrollToItem(selectedIndex - 2)
}
}
}
}
// 全局 LUT 编辑底部弹窗 (如果没有提供外部点击处理)
// 如果选中的 LUT 不在当前分类中,可选:不自动切换分类,或者在切换分类时如果是“全部”则保持选中
// 全局 LUT 编辑底部弹窗
if (actualShowLutEditDialog && currentLutId != null) {
LutEditBottomSheet(
lutId = currentLutId,
@@ -74,34 +90,69 @@ fun LutSelector(
}
)
}
LazyRow(
modifier = modifier
.fillMaxWidth()
.padding(vertical = 8.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp),
state = scrollState
) {
// LUT 列表
items(availableLuts) { lut ->
LutItem(
name = lut.getName(),
previewBitmap = lutPreviewBitmaps[lut.id],
isSelected = currentLutId == lut.id,
isVip = lut.isVip,
isCustom = !lut.isBuiltIn, // 添加自定义标识
onClick = {
if (currentLutId == lut.id) {
if (onEditClick != null) {
onEditClick()
} else {
showLutEditDialogState = true
}
} else {
onLutSelected(lut.id)
}
Column(modifier = modifier.fillMaxWidth()) {
// 分类选择器 (小芯片样式)
LazyRow(
modifier = Modifier
.fillMaxWidth()
.padding(bottom = 4.dp),
horizontalArrangement = Arrangement.spacedBy(12.dp),
contentPadding = PaddingValues(horizontal = 8.dp)
) {
items(categories) { category ->
val isSelected = selectedCategory == category
val categoryName = when (category) {
null -> stringResource(R.string.category_all)
"Custom" -> stringResource(R.string.category_custom)
else -> category
}
)
Text(
text = categoryName,
color = if (isSelected) Color(0xFFFF6B35) else Color.White.copy(alpha = 0.5f),
fontSize = 12.sp,
fontWeight = if (isSelected) FontWeight.Bold else FontWeight.Medium,
modifier = Modifier
.clickable(
interactionSource = remember { MutableInteractionSource() },
indication = null
) {
selectedCategory = category
}
.padding(vertical = 4.dp)
)
}
}
LazyRow(
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 4.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp),
state = scrollState
) {
// LUT 列表
items(filteredLuts, key = { it.id }) { lut ->
LutItem(
name = lut.getName(),
previewBitmap = lutPreviewBitmaps[lut.id],
isSelected = currentLutId == lut.id,
isVip = lut.isVip,
isCustom = !lut.isBuiltIn,
onClick = {
if (currentLutId == lut.id) {
if (onEditClick != null) {
onEditClick()
} else {
showLutEditDialogState = true
}
} else {
onLutSelected(lut.id)
}
}
)
}
}
}
}
@@ -3,9 +3,11 @@ package com.hinnka.mycamera.ui.settings
import android.net.Uri
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed
@@ -15,6 +17,7 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.*
import androidx.compose.material3.*
import androidx.compose.material3.TabRowDefaults.tabIndicatorOffset
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
@@ -41,7 +44,7 @@ import sh.calvin.reorderable.rememberReorderableLazyListState
*
* 支持选择默认滤镜、拖拽排序、重命名、删除(非内建)、导入
*/
@OptIn(ExperimentalMaterial3Api::class)
@OptIn(ExperimentalMaterial3Api::class, ExperimentalFoundationApi::class)
@Composable
fun FilterManagementScreen(
viewModel: CameraViewModel,
@@ -52,10 +55,10 @@ fun FilterManagementScreen(
val availableLuts = viewModel.availableLutList
val customImportManager = viewModel.getCustomImportManager()
val scope = rememberCoroutineScope()
// 本地可变列表用于拖拽排序
var localLutList by remember { mutableStateOf(availableLuts) }
// 当 availableLuts 更新时同步本地列表(保留现有顺序,将新项目添加到末尾)
LaunchedEffect(availableLuts) {
val existingIds = localLutList.map { it.id }.toSet()
@@ -84,6 +87,12 @@ fun FilterManagementScreen(
var showColorRecipeSheet by remember { mutableStateOf(false) }
var editingLutId by remember { mutableStateOf<String?>(null) }
// 分类编辑状态
var showCategoryDialog by remember { mutableStateOf(false) }
var categorizingLut by remember { mutableStateOf<LutInfo?>(null) }
var categoryText by remember { mutableStateOf("") }
var categoryToDelete by remember { mutableStateOf<String?>(null) }
// 批量文件选择器
val lutFilePicker = rememberLauncherForActivityResult(
contract = ActivityResultContracts.GetMultipleContents()
@@ -120,7 +129,46 @@ fun FilterManagementScreen(
}
}
}
// 分类删除确认对话框
if (categoryToDelete != null) {
val target = categoryToDelete!!
AlertDialog(
onDismissRequest = { categoryToDelete = null },
title = { Text(stringResource(R.string.delete_category_title)) },
text = { Text(stringResource(R.string.delete_category_message, target)) },
confirmButton = {
TextButton(
onClick = {
scope.launch {
// 立即更新本地 UI 列表防止闪烁
localLutList = localLutList.map {
if (it.category == target) it.copy(category = "") else it
}
withContext(Dispatchers.IO) {
// 批量在持久层清空分类
val impacted = availableLuts.filter { it.category == target }
impacted.forEach { lut ->
customImportManager.updateLutCategory(lut.id, "")
}
}
viewModel.refreshCustomContent()
categoryToDelete = null
}
},
colors = ButtonDefaults.textButtonColors(contentColor = Color.Red)
) {
Text(stringResource(R.string.delete))
}
},
dismissButton = {
TextButton(onClick = { categoryToDelete = null }) {
Text(stringResource(R.string.cancel))
}
}
)
}
// 拖拽排序状态
val lazyListState = rememberLazyListState()
val reorderableLazyListState = rememberReorderableLazyListState(lazyListState) { from, to ->
@@ -200,6 +248,84 @@ fun FilterManagementScreen(
)
)
// 导入进度提示
importProgress?.takeIf { isImporting }?.let { progress ->
Box(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 8.dp)
) {
LinearProgressIndicator(
progress = { progress.first.toFloat() / (progress.second.takeIf { it > 0 } ?: 1) },
modifier = Modifier.fillMaxWidth().height(4.dp).clip(RoundedCornerShape(2.dp)),
color = Color(0xFFFF6B35),
trackColor = Color.White.copy(alpha = 0.1f)
)
}
}
// 分类 Tabs
val allText = stringResource(R.string.category_all)
val customText = stringResource(R.string.custom)
val categories = remember(localLutList, allText, customText) {
// 动态分类提取:只取数据中实际存在的分类,且排除掉“所有”和“自定义”这两个保留词用于逻辑分页
val dynamicCategories = localLutList.map { it.category }
.distinct()
.filter { it.isNotEmpty() && it != allText && it != customText }
.sorted()
listOf(allText, customText) + dynamicCategories
}
var selectedTabIndex by remember { mutableStateOf(0) }
// 修正 Tab 越界(如果分类消失了)
LaunchedEffect(categories.size) {
if (selectedTabIndex >= categories.size) {
selectedTabIndex = 0
}
}
val filteredLutList = remember(selectedTabIndex, localLutList, categories) {
if (selectedTabIndex >= categories.size) return@remember localLutList
when (selectedTabIndex) {
0 -> localLutList // All
1 -> localLutList.filter { !it.isBuiltIn } // Custom
else -> localLutList.filter { it.category == categories[selectedTabIndex] }
}
}
ScrollableTabRow(
selectedTabIndex = selectedTabIndex,
containerColor = Color.Transparent,
contentColor = Color.White,
edgePadding = 16.dp,
divider = {},
indicator = { tabPositions ->
TabRowDefaults.SecondaryIndicator(
modifier = Modifier.tabIndicatorOffset(tabPositions[selectedTabIndex]),
color = Color(0xFFFF6B35)
)
}
) {
categories.forEachIndexed { index, category ->
Tab(
selected = selectedTabIndex == index,
onClick = { selectedTabIndex = index },
modifier = Modifier.clickable { selectedTabIndex = index },
text = {
Text(
text = category,
fontSize = 14.sp,
fontWeight = if (selectedTabIndex == index) FontWeight.Bold else FontWeight.Normal
)
}
)
}
}
// 滤镜列表
LazyColumn(
modifier = Modifier
@@ -225,14 +351,14 @@ fun FilterManagementScreen(
)
.padding(horizontal = 12.dp, vertical = 8.dp)
)
LaunchedEffect(result) {
kotlinx.coroutines.delay(3000)
importResult = null
}
}
}
itemsIndexed(localLutList, key = { _, it -> it.id }) { index, lutInfo ->
itemsIndexed(filteredLutList, key = { _, it -> it.id }) { index, lutInfo ->
ReorderableItem(reorderableLazyListState, key = lutInfo.id) { isDragging ->
FilterManagementItem(
lutInfo = lutInfo,
@@ -258,6 +384,11 @@ fun FilterManagementScreen(
showDeleteDialog = true
}
} else null,
onEditCategory = {
categorizingLut = lutInfo
categoryText = lutInfo.category
showCategoryDialog = true
},
dragModifier = Modifier.draggableHandle()
)
}
@@ -345,7 +476,113 @@ fun FilterManagementScreen(
}
)
}
// 分类编辑对话框
if (showCategoryDialog && categorizingLut != null) {
AlertDialog(
onDismissRequest = { showCategoryDialog = false },
title = {
Text(stringResource(R.string.edit_category))
},
text = {
Column {
OutlinedTextField(
value = categoryText,
onValueChange = { categoryText = it },
label = { Text(stringResource(R.string.category)) },
singleLine = true,
modifier = Modifier.fillMaxWidth(),
trailingIcon = if (categoryText.isNotEmpty()) {
{
IconButton(onClick = { categoryText = "" }) {
Icon(
imageVector = Icons.Default.Clear,
contentDescription = "Clear",
tint = Color.White.copy(alpha = 0.5f)
)
}
}
} else null
)
Spacer(modifier = Modifier.height(8.dp))
// 常用分类快速选择
val commonCategories = localLutList.map { it.category }.distinct().filter { it.isNotEmpty() }
if (commonCategories.isNotEmpty()) {
Text(
text = stringResource(R.string.common_categories),
fontSize = 12.sp,
color = Color.White.copy(alpha = 0.5f),
modifier = Modifier.padding(vertical = 4.dp)
)
FlowRow(
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalArrangement = Arrangement.spacedBy(4.dp)
) {
// 清除选项
if (categoryText.isNotEmpty()) {
SuggestionChip(
onClick = { categoryText = "" },
label = { Text(stringResource(R.string.none)) },
colors = SuggestionChipDefaults.suggestionChipColors(
labelColor = Color(0xFFFF5252)
)
)
}
commonCategories.forEach { cat ->
InputChip(
selected = categoryText == cat,
onClick = { categoryText = cat },
label = { Text(cat) },
trailingIcon = {
Icon(
imageVector = Icons.Default.Delete,
contentDescription = "Delete",
modifier = Modifier.size(16.dp).clickable { categoryToDelete = cat },
tint = Color.White.copy(alpha = 0.5f)
)
}
)
}
}
} else if (categoryText.isNotEmpty()) {
// 如果没有常用分类但当前有文本,也显示清除按钮
SuggestionChip(
onClick = { categoryText = "" },
label = { Text(stringResource(R.string.none)) },
colors = SuggestionChipDefaults.suggestionChipColors(
labelColor = Color(0xFFFF5252)
)
)
}
}
},
confirmButton = {
TextButton(
onClick = {
scope.launch {
withContext(Dispatchers.IO) {
customImportManager.updateLutCategory(categorizingLut!!.id, categoryText)
}
viewModel.refreshCustomContent()
showCategoryDialog = false
categorizingLut = null
}
}
) {
Text(stringResource(R.string.confirm))
}
},
dismissButton = {
TextButton(onClick = { showCategoryDialog = false }) {
Text(stringResource(R.string.cancel))
}
}
)
}
// 页面退出时保存排序
DisposableEffect(Unit) {
onDispose {
@@ -377,6 +614,7 @@ private fun FilterManagementItem(
onRename: (() -> Unit)?,
onEditColorRecipe: (() -> Unit)?,
onDelete: (() -> Unit)?,
onEditCategory: (() -> Unit)? = null,
dragModifier: Modifier = Modifier,
modifier: Modifier = Modifier
) {
@@ -397,22 +635,24 @@ private fun FilterManagementItem(
color = borderColor,
shape = RoundedCornerShape(12.dp)
)
.clickable(onClick = onSetDefault)
.padding(horizontal = 12.dp, vertical = 12.dp),
.padding(horizontal = 4.dp, vertical = 8.dp), // 减少 Row 整体 Padding
verticalAlignment = Alignment.CenterVertically
) {
// 拖拽图标 - 仅在此图标上应用拖拽手势
// 拖拽图标
Icon(
imageVector = Icons.Default.DragHandle,
contentDescription = "Drag to reorder",
tint = Color.White.copy(alpha = 0.5f),
modifier = dragModifier.size(24.dp)
modifier = dragModifier.padding(8.dp).size(24.dp)
)
Spacer(modifier = Modifier.width(12.dp))
// 滤镜名称和类型
Column(modifier = Modifier.weight(1f)) {
// 核心信息区(点击设为默认)
Column(
modifier = Modifier
.weight(1f)
.clickable(onClick = onSetDefault)
.padding(vertical = 4.dp, horizontal = 4.dp)
) {
Row(verticalAlignment = Alignment.CenterVertically) {
Text(
text = lutInfo.getName(),
@@ -423,95 +663,116 @@ private fun FilterManagementItem(
overflow = TextOverflow.Ellipsis,
modifier = Modifier.weight(1f, fill = false)
)
Spacer(modifier = Modifier.width(8.dp))
Spacer(modifier = Modifier.width(6.dp))
// 类型标签
val typeText = if (lutInfo.isBuiltIn) {
stringResource(R.string.built_in)
} else {
stringResource(R.string.custom)
}
val typeText =
if (lutInfo.isBuiltIn) stringResource(R.string.built_in) else stringResource(R.string.custom)
Text(
text = typeText,
color = if (lutInfo.isBuiltIn) Color.White.copy(alpha = 0.5f) else Color(0xFFFF6B35),
fontSize = 11.sp,
fontSize = 10.sp,
modifier = Modifier
.clip(RoundedCornerShape(4.dp))
.background(
if (lutInfo.isBuiltIn) Color.White.copy(alpha = 0.1f)
else Color(0xFFFF6B35).copy(alpha = 0.2f)
if (lutInfo.isBuiltIn) Color.White.copy(alpha = 0.1f) else Color(0xFFFF6B35).copy(
alpha = 0.2f
)
)
.padding(horizontal = 6.dp, vertical = 2.dp)
.padding(horizontal = 4.dp, vertical = 1.dp)
)
// VIP 标签
if (lutInfo.isVip) {
Spacer(modifier = Modifier.width(4.dp))
Text(
text = stringResource(R.string.billing_vip_tag),
color = Color(0xFFFFD700),
fontSize = 11.sp,
fontSize = 10.sp,
modifier = Modifier
.clip(RoundedCornerShape(4.dp))
.background(Color(0xFFFFD700).copy(alpha = 0.2f))
.padding(horizontal = 6.dp, vertical = 2.dp)
.padding(horizontal = 4.dp, vertical = 1.dp)
)
}
}
// 默认标识
if (isDefault) {
Spacer(modifier = Modifier.height(4.dp))
Text(
text = stringResource(R.string.current_default),
color = Color(0xFFFF6B35),
fontSize = 12.sp
fontSize = 11.sp
)
}
}
// 色彩配方编辑按钮
if (onEditColorRecipe != null) {
// 右侧操作区 (精简为核心操作 + 更多菜单)
Row(verticalAlignment = Alignment.CenterVertically) {
// 色彩配方编辑按钮 (高频,保留直达)
IconButton(
onClick = onEditColorRecipe,
onClick = onEditColorRecipe ?: {},
modifier = Modifier.size(36.dp)
) {
Icon(
imageVector = Icons.Default.Tune,
contentDescription = stringResource(R.string.color_recipe),
tint = Color.White.copy(alpha = 0.7f),
tint = Color.White.copy(alpha = 0.8f),
modifier = Modifier.size(20.dp)
)
}
}
// 操作按钮(仅自定义滤镜)
if (onRename != null) {
IconButton(
onClick = onRename,
modifier = Modifier.size(36.dp)
) {
Icon(
imageVector = Icons.Default.Edit,
contentDescription = stringResource(R.string.rename),
tint = Color.White.copy(alpha = 0.7f),
modifier = Modifier.size(20.dp)
)
}
}
// 更多操作菜单
var showMenu by remember { mutableStateOf(false) }
Box {
IconButton(onClick = { showMenu = true }, modifier = Modifier.size(36.dp)) {
Icon(
imageVector = Icons.Default.MoreVert,
contentDescription = "More",
tint = Color.White.copy(alpha = 0.6f),
modifier = Modifier.size(20.dp)
)
}
if (onDelete != null) {
IconButton(
onClick = onDelete,
modifier = Modifier.size(36.dp)
) {
Icon(
imageVector = Icons.Default.Delete,
contentDescription = stringResource(R.string.delete),
tint = Color.White.copy(alpha = 0.7f),
modifier = Modifier.size(20.dp)
)
DropdownMenu(
expanded = showMenu,
onDismissRequest = { showMenu = false },
modifier = Modifier.background(Color(0xFF2C313F))
) {
// 分类修改 (所有滤镜可用)
DropdownMenuItem(
text = { Text(stringResource(R.string.category), color = Color.White) },
leadingIcon = { Icon(Icons.Default.Label, null, tint = Color.White.copy(alpha = 0.7f)) },
onClick = {
showMenu = false
onEditCategory?.invoke()
}
)
// 重命名 (仅自定义)
if (onRename != null) {
DropdownMenuItem(
text = { Text(stringResource(R.string.rename), color = Color.White) },
leadingIcon = { Icon(Icons.Default.Edit, null, tint = Color.White.copy(alpha = 0.7f)) },
onClick = {
showMenu = false
onRename()
}
)
}
// 删除 (仅自定义)
if (onDelete != null) {
DropdownMenuItem(
text = { Text(stringResource(R.string.delete), color = Color.Red) },
leadingIcon = { Icon(Icons.Default.Delete, null, tint = Color.Red.copy(alpha = 0.7f)) },
onClick = {
showMenu = false
onDelete()
}
)
}
}
}
}
}
+7
View File
@@ -215,6 +215,8 @@
<string name="settings_frame_management_description">管理边框,设置默认,排序</string>
<string name="filter_management_title">滤镜管理</string>
<string name="frame_management_title">边框管理</string>
<string name="category_all">所有</string>
<string name="category_custom">自定义</string>
<string name="set_as_default">设为默认</string>
<string name="current_default">默认</string>
<string name="rename">重命名</string>
@@ -224,6 +226,11 @@
<string name="delete_filter_confirm_message">删除滤镜 "%s"?</string>
<string name="delete_frame_confirm_message">删除边框 "%s"?</string>
<string name="rename_dialog_title">重命名</string>
<string name="edit_category">编辑分类</string>
<string name="category">分类</string>
<string name="common_categories">已有分类</string>
<string name="delete_category_title">删除分类</string>
<string name="delete_category_message">确认删除分类 "%s"?该分类下的滤镜将被设为未分类。</string>
<string name="built_in">内置</string>
<string name="custom">自定义</string>
<string name="no_filters">暂无自定义滤镜</string>
+7
View File
@@ -216,6 +216,8 @@
<string name="settings_frame_management_description">Manage frames, set default, reorder</string>
<string name="filter_management_title">Filter Management</string>
<string name="frame_management_title">Frame Management</string>
<string name="category_all">All</string>
<string name="category_custom">Custom</string>
<string name="set_as_default">Set as Default</string>
<string name="current_default">Default</string>
<string name="rename">Rename</string>
@@ -225,6 +227,11 @@
<string name="delete_filter_confirm_message">Delete filter \"%s\"?</string>
<string name="delete_frame_confirm_message">Delete frame \"%s\"?</string>
<string name="rename_dialog_title">Rename</string>
<string name="edit_category">Edit Category</string>
<string name="category">Category</string>
<string name="common_categories">Common Categories</string>
<string name="delete_category_title">Delete Category</string>
<string name="delete_category_message">Are you sure you want to delete category \"%s\"? Filters under this category will be reset to uncategorized.</string>
<string name="built_in">Built-in</string>
<string name="custom">Custom</string>
<string name="no_filters">No custom filters</string>