diff --git a/app/src/main/java/com/hinnka/mycamera/gallery/PhotoManager.kt b/app/src/main/java/com/hinnka/mycamera/gallery/PhotoManager.kt index e6977966..b1ed82e6 100644 --- a/app/src/main/java/com/hinnka/mycamera/gallery/PhotoManager.kt +++ b/app/src/main/java/com/hinnka/mycamera/gallery/PhotoManager.kt @@ -29,6 +29,7 @@ import com.hinnka.mycamera.utils.BitmapUtils import com.hinnka.mycamera.utils.PLog import com.hinnka.mycamera.utils.RawProcessor import com.hinnka.mycamera.utils.YuvProcessor +import com.hinnka.mycamera.viewmodel.GalleryViewModel import kotlinx.coroutines.* import java.io.ByteArrayOutputStream import java.io.File @@ -105,9 +106,8 @@ object PhotoManager { chromaNoiseReductionValue: Float, photoQuality: Int = 95, suffix: String? = null, - onComplete: (Boolean) -> Unit = {} - ) { - withContext(Dispatchers.IO) { + ): Boolean { + return withContext(Dispatchers.IO) { val tempExportFile = File(context.cacheDir, "temp_export_${System.nanoTime()}.jpg") try { // 读取照片 @@ -119,7 +119,7 @@ object PhotoManager { } ?: photoProcessor.process( context, id, metadata, sharpeningValue, noiseReductionValue, chromaNoiseReductionValue - ) ?: return@withContext + ) ?: return@withContext false PLog.d(TAG, "processedBitmap = ${processedBitmap.colorSpace?.name}") @@ -242,21 +242,18 @@ object PhotoManager { ) saveMetadata(context, id, updatedMetadata) PLog.d(TAG, "Exported URI saved: $uri for photo $id") + + return@withContext true } processedBitmap.recycle() - withContext(Dispatchers.Main) { - onComplete(uri != null) - } - } catch (e: Exception) { PLog.e(TAG, "Failed to export photo", e) - withContext(Dispatchers.Main) { - onComplete(false) - } } finally { tempExportFile.delete() } + + false } } 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 334d7ce9..d48f5ce4 100644 --- a/app/src/main/java/com/hinnka/mycamera/lut/LutManager.kt +++ b/app/src/main/java/com/hinnka/mycamera/lut/LutManager.kt @@ -50,6 +50,8 @@ class LutManager(private val context: Context) { private fun bleachBypassKey(lutId: String) = floatPreferencesKey("${lutId}_bleachBypass") private fun halationKey(lutId: String) = floatPreferencesKey("${lutId}_halation") private fun lutIntensityKey(lutId: String) = floatPreferencesKey("${lutId}_lutIntensity") + private fun remarksKey(lutId: String) = + androidx.datastore.preferences.core.stringPreferencesKey("${lutId}_remarks") } // LUT 缓存 @@ -80,7 +82,8 @@ class LutManager(private val context: Context) { vignette = preferences[vignetteKey(lutId)] ?: 0f, bleachBypass = preferences[bleachBypassKey(lutId)] ?: 0f, halation = preferences[halationKey(lutId)] ?: 0f, - lutIntensity = preferences[lutIntensityKey(lutId)] ?: 1f + lutIntensity = preferences[lutIntensityKey(lutId)] ?: 1f, + remarks = preferences[remarksKey(lutId)] ?: "" ) } } @@ -219,6 +222,7 @@ class LutManager(private val context: Context) { preferences[bleachBypassKey(lutId)] = params.bleachBypass preferences[halationKey(lutId)] = params.halation preferences[lutIntensityKey(lutId)] = params.lutIntensity + preferences[remarksKey(lutId)] = params.remarks } PLog.d(TAG, "Color recipe params saved for LUT [$lutId]: $params") } @@ -245,7 +249,8 @@ class LutManager(private val context: Context) { vignette = preferences[vignetteKey(lutId)] ?: 0f, bleachBypass = preferences[bleachBypassKey(lutId)] ?: 0f, halation = preferences[halationKey(lutId)] ?: 0f, - lutIntensity = preferences[lutIntensityKey(lutId)] ?: 1f + lutIntensity = preferences[lutIntensityKey(lutId)] ?: 1f, + remarks = preferences[remarksKey(lutId)] ?: "" ) }.firstOrNull() ?: ColorRecipeParams.DEFAULT } @@ -281,6 +286,7 @@ class LutManager(private val context: Context) { preferences.remove(bleachBypassKey(lutId)) preferences.remove(halationKey(lutId)) preferences.remove(lutIntensityKey(lutId)) + preferences.remove(remarksKey(lutId)) } PLog.d(TAG, "Color recipe params deleted for LUT [$lutId]") } diff --git a/app/src/main/java/com/hinnka/mycamera/model/ColorRecipe.kt b/app/src/main/java/com/hinnka/mycamera/model/ColorRecipe.kt index 552cf0f6..233dc78d 100644 --- a/app/src/main/java/com/hinnka/mycamera/model/ColorRecipe.kt +++ b/app/src/main/java/com/hinnka/mycamera/model/ColorRecipe.kt @@ -22,6 +22,7 @@ data class ColorRecipeParams( val bleachBypass: Float = 0f, // 0.0 ~ 1.0 (留银冲洗强度,0为无效果) val halation: Float = 0f, // 0.0 ~ 1.0 (光晕/高光扩散强度,0为无效果,模拟 GR3 HDF) val lutIntensity: Float = 1f, // 0.0 ~ 1.0 (LUT强度,1为完全应用) + val remarks: String = "", // 用户备注 ) { /** * 检查参数是否为默认值(无任何调整) @@ -39,7 +40,8 @@ data class ColorRecipeParams( filmGrain == 0f && vignette == 0f && bleachBypass == 0f && - halation == 0f + halation == 0f && + remarks.isEmpty() } /** @@ -59,7 +61,8 @@ data class ColorRecipeParams( vignette == other.vignette && bleachBypass == other.bleachBypass && halation == other.halation && - lutIntensity == other.lutIntensity + lutIntensity == other.lutIntensity && + remarks == other.remarks } companion object { diff --git a/app/src/main/java/com/hinnka/mycamera/ui/camera/LutEditScreen.kt b/app/src/main/java/com/hinnka/mycamera/ui/camera/LutEditScreen.kt index 2effe397..ba5f059d 100644 --- a/app/src/main/java/com/hinnka/mycamera/ui/camera/LutEditScreen.kt +++ b/app/src/main/java/com/hinnka/mycamera/ui/camera/LutEditScreen.kt @@ -54,6 +54,16 @@ fun LutEditBottomSheet( .fillMaxWidth() .navigationBarsPadding() ) { + // 备注栏 (最上面单独起一行) + com.hinnka.mycamera.ui.components.ColorRecipeRemarksBar( + remarks = editingParams.remarks, + onRemarksChange = { + editingParams = editingParams.copy(remarks = it) + viewModel.saveLutColorRecipe(lutId, editingParams) + }, + modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp) + ) + LutIntensitySlider( intensity = editingParams.lutIntensity, onIntensityChange = { diff --git a/app/src/main/java/com/hinnka/mycamera/ui/components/ColorRecipePanel.kt b/app/src/main/java/com/hinnka/mycamera/ui/components/ColorRecipePanel.kt index dd4a5762..a04232de 100644 --- a/app/src/main/java/com/hinnka/mycamera/ui/components/ColorRecipePanel.kt +++ b/app/src/main/java/com/hinnka/mycamera/ui/components/ColorRecipePanel.kt @@ -2,6 +2,7 @@ package com.hinnka.mycamera.ui.components import androidx.compose.animation.animateColorAsState import androidx.compose.foundation.background +import androidx.compose.foundation.border import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.* import androidx.compose.foundation.shape.CircleShape @@ -17,6 +18,20 @@ import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.compose.ui.res.stringResource +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Edit +import androidx.compose.material.icons.filled.Check +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton +import androidx.compose.foundation.text.BasicTextField +import androidx.compose.ui.graphics.SolidColor +import androidx.compose.ui.text.TextStyle +import androidx.compose.foundation.text.KeyboardActions +import androidx.compose.foundation.text.KeyboardOptions +import androidx.compose.ui.focus.FocusRequester +import androidx.compose.ui.focus.focusRequester +import androidx.compose.ui.platform.LocalFocusManager +import androidx.compose.ui.text.input.ImeAction import com.hinnka.mycamera.R import com.hinnka.mycamera.model.ColorRecipeParams import com.hinnka.mycamera.model.RecipeParam @@ -134,6 +149,116 @@ fun ColorRecipePanel( } } +/** + * 色彩配方备注栏 + */ +@Composable +fun ColorRecipeRemarksBar( + remarks: String, + onRemarksChange: (String) -> Unit, + modifier: Modifier = Modifier +) { + var isEditing by remember { mutableStateOf(false) } + var text by remember(remarks) { mutableStateOf(remarks) } + val focusRequester = remember { FocusRequester() } + val focusManager = LocalFocusManager.current + + LaunchedEffect(isEditing) { + if (isEditing) { + focusRequester.requestFocus() + } + } + + Row( + modifier = modifier + .fillMaxWidth() + .clip(RoundedCornerShape(12.dp)) + .background(Color.White.copy(alpha = 0.05f)) // 极简半透明白 + .border( + width = 0.5.dp, + color = if (isEditing) Color(0xFFFFD700).copy(alpha = 0.5f) else Color.White.copy(alpha = 0.1f), + shape = RoundedCornerShape(12.dp) + ) + .clickable(enabled = !isEditing) { isEditing = true } + .padding(horizontal = 14.dp, vertical = 10.dp), + verticalAlignment = Alignment.CenterVertically + ) { + // 左侧提示图标 + Icon( + imageVector = Icons.Default.Edit, + contentDescription = null, + tint = Color.White.copy(alpha = 0.3f), + modifier = Modifier.size(14.dp) + ) + + Spacer(modifier = Modifier.width(10.dp)) + + Box(modifier = Modifier.weight(1f)) { + if (isEditing) { + BasicTextField( + value = text, + onValueChange = { text = it }, + modifier = Modifier + .fillMaxWidth() + .focusRequester(focusRequester), + textStyle = TextStyle( + color = Color.White, + fontSize = 13.sp, + fontWeight = FontWeight.Medium + ), + cursorBrush = SolidColor(Color.White), + keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done), + keyboardActions = KeyboardActions( + onDone = { + onRemarksChange(text) + isEditing = false + focusManager.clearFocus() + } + ), + decorationBox = { innerTextField -> + if (text.isEmpty()) { + Text( + text = stringResource(R.string.recipe_placeholder_remarks), + color = Color.White.copy(alpha = 0.25f), + fontSize = 13.sp + ) + } + innerTextField() + } + ) + } else { + Text( + text = if (remarks.isEmpty()) stringResource(R.string.recipe_placeholder_remarks) else remarks, + color = if (remarks.isEmpty()) Color.White.copy(alpha = 0.3f) else Color.White, + fontSize = 13.sp, + fontWeight = FontWeight.Medium, + maxLines = 1, + overflow = androidx.compose.ui.text.style.TextOverflow.Ellipsis + ) + } + } + + // 状态切换按钮 + IconButton( + onClick = { + if (isEditing) { + onRemarksChange(text) + focusManager.clearFocus() + } + isEditing = !isEditing + }, + modifier = Modifier.size(20.dp) + ) { + Icon( + imageVector = if (isEditing) Icons.Default.Check else Icons.Default.Edit, + contentDescription = null, + tint = if (isEditing) Color(0xFFFFD700) else Color.White.copy(alpha = 0.5f), + modifier = Modifier.size(16.dp) + ) + } + } +} + /** * 色彩配方参数滑块 */ diff --git a/app/src/main/java/com/hinnka/mycamera/viewmodel/GalleryViewModel.kt b/app/src/main/java/com/hinnka/mycamera/viewmodel/GalleryViewModel.kt index c419ca39..6df24230 100644 --- a/app/src/main/java/com/hinnka/mycamera/viewmodel/GalleryViewModel.kt +++ b/app/src/main/java/com/hinnka/mycamera/viewmodel/GalleryViewModel.kt @@ -1444,6 +1444,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application) context, photo.uri, editLutId.value, + photo.uri.lastPathSegment, sourceUri = photo.uri.toString() ) } else { @@ -1545,20 +1546,23 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application) onComplete: (Boolean) -> Unit = {} ) { viewModelScope.launch { - val metadata = PhotoManager.loadMetadata(getApplication(), photo.id) ?: photo.metadata + var photoId = photo.id + if (selectedTab == GalleryTab.SYSTEM) { + photoId = _photos.value.find { it.metadata?.sourceUri == photo.uri.toString() }?.id ?: photoId + } + val metadata = PhotoManager.loadMetadata(getApplication(), photoId) ?: photo.metadata ?: PhotoMetadata() val context = getApplication() - PhotoManager.exportPhoto( - context, photo.id, bitmap, contentRepository.photoProcessor, metadata, + val success = PhotoManager.exportPhoto( + context, photoId, bitmap, contentRepository.photoProcessor, metadata, sharpening.value, noiseReduction.value, chromaNoiseReduction.value, photoQuality.firstOrNull() ?: 95, suffix - ) { success -> - if (success) { - exitEditMode() - loadPhotos() - } - onComplete(success) + ) + if (success) { + exitEditMode() + loadPhotos() } + onComplete(success) } } diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 85b613f0..80120261 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -227,6 +227,8 @@ 亮度 效果 细节 + 备注 + 点击添加备注信息… 锐化 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index db33c70b..cc2efff1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -232,6 +232,8 @@ Light Texture Post + Notes + Tap to add notes… Sharpening