diff --git a/app/src/main/assets/luts/config.json b/app/src/main/assets/luts/config.json index 9ac44106..bd18d176 100644 --- a/app/src/main/assets/luts/config.json +++ b/app/src/main/assets/luts/config.json @@ -13,8 +13,8 @@ { "id": "standard", "name": { - "en": "STD", - "zh": "STD" + "en": "Standard", + "zh": "标准" }, "path": "standard.plut", "isDefault": true, diff --git a/app/src/main/java/com/hinnka/mycamera/data/CustomImportManager.kt b/app/src/main/java/com/hinnka/mycamera/data/CustomImportManager.kt index 84175bad..36800207 100644 --- a/app/src/main/java/com/hinnka/mycamera/data/CustomImportManager.kt +++ b/app/src/main/java/com/hinnka/mycamera/data/CustomImportManager.kt @@ -41,6 +41,7 @@ class CustomImportManager(private val context: Context) { private const val CUSTOM_FRAME_CONFIG = "custom_frames.json" private const val CUSTOM_DCP_CONFIG = "custom_dcps.json" private const val CATEGORY_OVERRIDES_CONFIG = "category_overrides.json" + private const val FAVORITE_OVERRIDES_CONFIG = "favorite_overrides.json" // 自定义字体目录 private const val CUSTOM_FONT_DIR = "custom_fonts" @@ -81,6 +82,25 @@ class CustomImportManager(private val context: Context) { } } + /** + * 获取收藏重写映射。 + */ + fun getFavoriteOverrides(): Map { + return try { + val file = File(context.filesDir, FAVORITE_OVERRIDES_CONFIG) + if (!file.exists()) return emptyMap() + val json = JSONObject(file.readText()) + val map = mutableMapOf() + json.keys().forEach { key -> + map[key] = json.optBoolean(key, false) + } + map + } catch (e: Exception) { + PLog.e(TAG, "Failed to get favorite overrides", e) + emptyMap() + } + } + private val customLutDir: File get() = File(context.filesDir, CUSTOM_LUT_DIR).apply { mkdirs() } @@ -456,7 +476,8 @@ class CustomImportManager(private val context: Context) { isBuiltIn = false, isDefault = false, isVip = false, - category = lutObj.optString("category", "") + category = lutObj.optString("category", ""), + isFavorite = lutObj.optBoolean("isFavorite", false) ) ) } @@ -638,6 +659,47 @@ class CustomImportManager(private val context: Context) { } } + /** + * 更新 LUT 收藏状态(支持内置和自定义)。 + */ + fun updateLutFavorite(lutId: String, isFavorite: Boolean): Boolean { + return try { + val overridesFile = File(context.filesDir, FAVORITE_OVERRIDES_CONFIG) + val overridesJson = if (overridesFile.exists()) { + JSONObject(overridesFile.readText()) + } else { + JSONObject() + } + overridesJson.put(lutId, isFavorite) + overridesFile.writeText(overridesJson.toString()) + + 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("isFavorite", isFavorite) + updated = true + } + newArray.put(lutObj) + } + if (updated) { + configFile.writeText(newArray.toString()) + } + } + + PLog.d(TAG, "LUT favorite updated: $lutId -> $isFavorite") + true + } catch (e: Exception) { + PLog.e(TAG, "Failed to update LUT favorite", e) + false + } + } + /** * 更新自定义边框名称 */ diff --git a/app/src/main/java/com/hinnka/mycamera/lut/LutConfig.kt b/app/src/main/java/com/hinnka/mycamera/lut/LutConfig.kt index e9c7db7c..10f53a8e 100644 --- a/app/src/main/java/com/hinnka/mycamera/lut/LutConfig.kt +++ b/app/src/main/java/com/hinnka/mycamera/lut/LutConfig.kt @@ -108,6 +108,7 @@ data class LutInfo( val isDefault: Boolean = false, // 是否为默认 LUT val isVip: Boolean = false, // 是否为 VIP LUT val category: String = "", // 分类 + val isFavorite: Boolean = false, // 是否收藏 ) { /** * 获取显示名称(优先当前系统语言) diff --git a/app/src/main/java/com/hinnka/mycamera/lut/LutDisplayOrdering.kt b/app/src/main/java/com/hinnka/mycamera/lut/LutDisplayOrdering.kt index e6c9f6d2..096f5d96 100644 --- a/app/src/main/java/com/hinnka/mycamera/lut/LutDisplayOrdering.kt +++ b/app/src/main/java/com/hinnka/mycamera/lut/LutDisplayOrdering.kt @@ -13,9 +13,10 @@ fun orderedLutCategoryTitles( luts: List, categoryOrder: List, builtInText: String, - uncategorizedText: String + uncategorizedText: String, + favoriteText: String? = null ): List { - val reservedCategoryNames = setOf(builtInText, uncategorizedText) + val reservedCategoryNames = setOfNotNull(builtInText, uncategorizedText, favoriteText) val dynamicCategories = luts.map { it.category } .distinct() .filter { it.isNotEmpty() && it !in reservedCategoryNames } @@ -24,6 +25,7 @@ fun orderedLutCategoryTitles( val remainingDynamic = dynamicCategories.filterNot { it in orderedKnownCategories }.sorted() return buildList { + favoriteText?.let { add(it) } if (orderedKnownCategories.isEmpty()) { add(builtInText) addAll(remainingDynamic) @@ -42,16 +44,19 @@ fun groupLutsForDisplay( luts: List, categoryOrder: List, builtInText: String, - uncategorizedText: String + uncategorizedText: String, + favoriteText: String? = null ): List>> { val categories = orderedLutCategoryTitles( luts = luts, categoryOrder = categoryOrder, builtInText = builtInText, - uncategorizedText = uncategorizedText + uncategorizedText = uncategorizedText, + favoriteText = favoriteText ) return categories.mapNotNull { category -> val items = when (category) { + favoriteText -> luts.filter { it.isFavorite } builtInText -> luts.filter { it.isBuiltIn } uncategorizedText -> luts.filter { !it.isBuiltIn && it.category.isEmpty() } else -> luts.filter { it.category == category } diff --git a/app/src/main/java/com/hinnka/mycamera/lut/LutManager.kt b/app/src/main/java/com/hinnka/mycamera/lut/LutManager.kt index a4832bc9..3b212456 100644 --- a/app/src/main/java/com/hinnka/mycamera/lut/LutManager.kt +++ b/app/src/main/java/com/hinnka/mycamera/lut/LutManager.kt @@ -164,6 +164,7 @@ class LutManager(private val context: Context) { } val customLuts = customImportManager.getCustomLuts() val categoryOverrides = customImportManager.getCategoryOverrides() + val favoriteOverrides = customImportManager.getFavoriteOverrides() // 合并列表 val allLuts = customLuts + builtInLuts @@ -171,11 +172,11 @@ class LutManager(private val context: Context) { // 应用分类重写 (用户手动创建的分类会通过这里恢复) availableLuts = allLuts.map { lut -> val overriddenCategory = categoryOverrides[lut.id] - if (overriddenCategory != null) { - lut.copy(category = overriddenCategory) - } else { - lut - } + val overriddenFavorite = favoriteOverrides[lut.id] + lut.copy( + category = overriddenCategory ?: lut.category, + isFavorite = overriddenFavorite ?: lut.isFavorite + ) } PLog.d(TAG, "Found ${availableLuts.size} LUT files (${customLuts.size} custom, ${builtInLuts.size} built-in)") diff --git a/app/src/main/java/com/hinnka/mycamera/lut/LutParser.kt b/app/src/main/java/com/hinnka/mycamera/lut/LutParser.kt index 6b02763a..f07ecaba 100644 --- a/app/src/main/java/com/hinnka/mycamera/lut/LutParser.kt +++ b/app/src/main/java/com/hinnka/mycamera/lut/LutParser.kt @@ -119,6 +119,7 @@ object LutParser { val isDefault = lutObj.optBoolean("isDefault", false) val isVip = lutObj.getBoolean("isVip") val category = lutObj.optString("category", "Built-in") + val isFavorite = lutObj.optBoolean("isFavorite", false) // 读取多语言名称 val nameMap = mutableMapOf() @@ -134,7 +135,8 @@ object LutParser { isBuiltIn = true, isDefault = isDefault, isVip = isVip, - category = category + category = category, + isFavorite = isFavorite ) ) } diff --git a/app/src/main/java/com/hinnka/mycamera/ui/components/LutSelector.kt b/app/src/main/java/com/hinnka/mycamera/ui/components/LutSelector.kt index b737fbc1..f34189bf 100644 --- a/app/src/main/java/com/hinnka/mycamera/ui/components/LutSelector.kt +++ b/app/src/main/java/com/hinnka/mycamera/ui/components/LutSelector.kt @@ -45,6 +45,7 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.withContext private sealed class LutCategoryTab { + data object Favorite : LutCategoryTab() data object BuiltIn : LutCategoryTab() data object Uncategorized : LutCategoryTab() data class Category(val name: String) : LutCategoryTab() @@ -69,19 +70,22 @@ fun LutSelector( val scrollState = rememberLazyListState() val coroutineScope = rememberCoroutineScope() var showLutEditDialogState by remember { mutableStateOf(false) } + val favoriteText = stringResource(R.string.favorite) val builtInText = stringResource(R.string.built_in) val uncategorizedText = stringResource(R.string.uncategorized) // 分类逻辑 - val categoryTabs = remember(availableLuts, categoryOrder, builtInText, uncategorizedText) { + val categoryTabs = remember(availableLuts, categoryOrder, favoriteText, builtInText, uncategorizedText) { + val reservedCategoryNames = setOf(favoriteText, builtInText, uncategorizedText) val dynamicCategories = availableLuts.map { it.category } .distinct() - .filter { it.isNotEmpty() } + .filter { it.isNotEmpty() && it !in reservedCategoryNames } val hasUncategorizedLuts = availableLuts.any { !it.isBuiltIn && it.category.isEmpty() } val orderedEntries = categoryOrder.filter { it == builtInText || dynamicCategories.contains(it) } val remainingDynamic = dynamicCategories.filterNot { it in orderedEntries }.sorted() buildList { + add(LutCategoryTab.Favorite) if (orderedEntries.isEmpty()) { add(LutCategoryTab.BuiltIn) addAll(remainingDynamic.map(LutCategoryTab::Category)) @@ -101,22 +105,36 @@ fun LutSelector( } } } - var selectedCategory by remember(currentLutId, availableLuts) { - mutableStateOf( - availableLuts.find { it.id == currentLutId }?.let { lut -> - if (lut.isBuiltIn) { - LutCategoryTab.BuiltIn - } else if (lut.category.isNotEmpty()) { - LutCategoryTab.Category(lut.category) - } else { - LutCategoryTab.Uncategorized - } - } ?: LutCategoryTab.BuiltIn - ) + fun LutCategoryTab.contains(lut: LutInfo): Boolean = when (this) { + LutCategoryTab.Favorite -> lut.isFavorite + LutCategoryTab.BuiltIn -> lut.isBuiltIn + LutCategoryTab.Uncategorized -> !lut.isBuiltIn && lut.category.isEmpty() + is LutCategoryTab.Category -> lut.category == name + } + + fun preferredCategoryFor(lut: LutInfo): LutCategoryTab = when { + lut.isFavorite -> LutCategoryTab.Favorite + lut.category.isNotEmpty() -> LutCategoryTab.Category(lut.category) + lut.isBuiltIn -> LutCategoryTab.BuiltIn + else -> LutCategoryTab.Uncategorized + } + + var selectedCategory by remember { mutableStateOf(LutCategoryTab.BuiltIn) } + + LaunchedEffect(currentLutId, availableLuts, categoryTabs) { + val selectedLut = availableLuts.find { it.id == currentLutId } + selectedCategory = when { + selectedLut?.isFavorite == true -> LutCategoryTab.Favorite + selectedLut != null && selectedCategory.contains(selectedLut) -> selectedCategory + selectedLut != null -> preferredCategoryFor(selectedLut) + selectedCategory in categoryTabs -> selectedCategory + else -> LutCategoryTab.BuiltIn + } } val filteredLuts = remember(selectedCategory, availableLuts) { when (selectedCategory) { + LutCategoryTab.Favorite -> availableLuts.filter { it.isFavorite } LutCategoryTab.BuiltIn -> availableLuts.filter { it.isBuiltIn } LutCategoryTab.Uncategorized -> availableLuts.filter { !it.isBuiltIn && it.category.isEmpty() } is LutCategoryTab.Category -> { @@ -166,6 +184,7 @@ fun LutSelector( items(categoryTabs) { category -> val isSelected = selectedCategory == category val categoryName = when (category) { + LutCategoryTab.Favorite -> favoriteText LutCategoryTab.BuiltIn -> builtInText LutCategoryTab.Uncategorized -> uncategorizedText is LutCategoryTab.Category -> category.name diff --git a/app/src/main/java/com/hinnka/mycamera/ui/settings/FilterManagementScreen.kt b/app/src/main/java/com/hinnka/mycamera/ui/settings/FilterManagementScreen.kt index 400164b0..0bfd2ad1 100644 --- a/app/src/main/java/com/hinnka/mycamera/ui/settings/FilterManagementScreen.kt +++ b/app/src/main/java/com/hinnka/mycamera/ui/settings/FilterManagementScreen.kt @@ -57,11 +57,12 @@ private data class CategoryManagementItem( private fun sanitizeCustomLutCategoryInput( category: String, + favoriteText: String, builtInText: String, uncategorizedText: String ): String { val trimmedCategory = category.trim() - return if (trimmedCategory == builtInText || trimmedCategory == uncategorizedText) { + return if (trimmedCategory == favoriteText || trimmedCategory == builtInText || trimmedCategory == uncategorizedText) { "" } else { trimmedCategory @@ -193,23 +194,26 @@ fun FilterManagementScreen( val builtInText = stringResource(R.string.built_in) val uncategorizedText = stringResource(R.string.uncategorized) - val reservedCategoryNames = remember(builtInText, uncategorizedText) { - setOf(builtInText, uncategorizedText) + val favoriteText = stringResource(R.string.favorite) + val reservedCategoryNames = remember(favoriteText, builtInText, uncategorizedText) { + setOf(favoriteText, builtInText, uncategorizedText) } var selectedTabIndex by remember { mutableIntStateOf(0) } - val categories = remember(localLutList, categoryOrder, builtInText, uncategorizedText, reservedCategoryNames) { + val categories = remember(localLutList, categoryOrder, favoriteText, builtInText, uncategorizedText, reservedCategoryNames) { orderedLutCategoryTitles( luts = localLutList, categoryOrder = categoryOrder, builtInText = builtInText, - uncategorizedText = uncategorizedText + uncategorizedText = uncategorizedText, + favoriteText = favoriteText ) } val filteredLutList = remember(selectedTabIndex, localLutList, categories) { if (selectedTabIndex >= categories.size) return@remember localLutList when (val selectedCategory = categories[selectedTabIndex]) { + favoriteText -> localLutList.filter { it.isFavorite } builtInText -> localLutList.filter { it.isBuiltIn } uncategorizedText -> localLutList.filter { !it.isBuiltIn && it.category.isEmpty() } else -> localLutList.filter { it.category == selectedCategory } @@ -228,8 +232,9 @@ fun FilterManagementScreen( kotlinx.coroutines.delay(350) // 查找目标所属分类 - val categoryName = if (targetLut.isBuiltIn) builtInText - else if (targetLut.category.isEmpty()) uncategorizedText + val categoryName = if (targetLut.isFavorite) favoriteText + else if (targetLut.isBuiltIn) builtInText + else if (targetLut.category.isEmpty()) uncategorizedText else targetLut.category val categoryIndex = categories.indexOf(categoryName) @@ -241,6 +246,7 @@ fun FilterManagementScreen( // 重新获取当前分类下的列表并定位 val filteredLutsNow = when (categoryName) { + favoriteText -> localLutList.filter { it.isFavorite } builtInText -> localLutList.filter { it.isBuiltIn } uncategorizedText -> localLutList.filter { !it.isBuiltIn && it.category.isEmpty() } else -> localLutList.filter { it.category == categoryName } @@ -669,6 +675,20 @@ fun FilterManagementScreen( showCategoryDialog = true } } else null, + onToggleFavorite = if (!isSelectionMode) { + { + scope.launch { + val nextFavorite = !lutInfo.isFavorite + localLutList = localLutList.map { + if (it.id == lutInfo.id) it.copy(isFavorite = nextFavorite) else it + } + withContext(Dispatchers.IO) { + customImportManager.updateLutFavorite(lutInfo.id, nextFavorite) + } + viewModel.refreshCustomContent() + } + } + } else null, showCategory = categories.getOrNull(currentTabIndex) == builtInText && lutInfo.category.isNotEmpty(), dragModifier = if (isSelectionMode) Modifier else Modifier.draggableHandle() ) @@ -886,6 +906,7 @@ fun FilterManagementScreen( onClick = { val sanitizedCategory = sanitizeCustomLutCategoryInput( category = categoryText, + favoriteText = favoriteText, builtInText = builtInText, uncategorizedText = uncategorizedText ) @@ -1127,6 +1148,7 @@ fun FilterManagementScreen( onClick = { val targetCategory = sanitizeCustomLutCategoryInput( category = categoryText, + favoriteText = favoriteText, builtInText = builtInText, uncategorizedText = uncategorizedText ) @@ -1589,6 +1611,7 @@ private fun FilterManagementItem( onDelete: (() -> Unit)?, onExport: (() -> Unit)? = null, onEditCategory: (() -> Unit)? = null, + onToggleFavorite: (() -> Unit)? = null, showCategory: Boolean = false, dragModifier: Modifier = Modifier, modifier: Modifier = Modifier @@ -1695,6 +1718,16 @@ private fun FilterManagementItem( .padding(horizontal = 4.dp, vertical = 1.dp) ) } + + if (lutInfo.isFavorite) { + Spacer(modifier = Modifier.width(4.dp)) + Icon( + imageVector = Icons.Default.Star, + contentDescription = stringResource(R.string.favorite), + tint = Color(0xFFFFD700), + modifier = Modifier.size(14.dp) + ) + } } if (isDefault) { @@ -1748,6 +1781,30 @@ private fun FilterManagementItem( } ) + if (onToggleFavorite != null) { + DropdownMenuItem( + text = { + Text( + stringResource( + if (lutInfo.isFavorite) R.string.remove_from_favorites else R.string.add_to_favorites + ), + color = Color.White + ) + }, + leadingIcon = { + Icon( + if (lutInfo.isFavorite) Icons.Default.Star else Icons.Default.StarBorder, + null, + tint = Color(0xFFFFD700) + ) + }, + onClick = { + showMenu = false + onToggleFavorite() + } + ) + } + // 重命名 (仅自定义) if (onRename != null) { DropdownMenuItem( diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index e0922933..458f89eb 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -478,6 +478,9 @@ 已有分类 删除分类 确认删除分类 "%s"?该分类下的滤镜将被设为未分类。 + 收藏 + 加入收藏 + 取消收藏 内置 自定义 未分类 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 3a213abd..849ce573 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -362,6 +362,9 @@ 已有分類 刪除分類 確認刪除分類 "%s"?該分類下的濾鏡將被設為未分類。 + 收藏 + 加入收藏 + 取消收藏 內建 自訂 未分类 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4468c9ca..6b358a01 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -488,6 +488,9 @@ Common Categories Delete Category Are you sure you want to delete category \"%s\"? LUTs under this category will be reset to uncategorized. + Favorites + Add to Favorites + Remove from Favorites Built-in Custom Uncategorized