feat: preset state & save
This commit is contained in:
1 parent
c773600dfa
commit
5ef12b1679
11 files changed
+195
-159
No files matched your search
@@ -232,6 +232,7 @@ fun CameraScreen(
|
|||||||
val currentRecipeParams by viewModel.currentRecipeParams.collectAsState()
|
val currentRecipeParams by viewModel.currentRecipeParams.collectAsState()
|
||||||
val lutSelectorMode by viewModel.lutSelectorMode.collectAsState()
|
val lutSelectorMode by viewModel.lutSelectorMode.collectAsState()
|
||||||
val activePresetId by viewModel.activePresetId.collectAsState()
|
val activePresetId by viewModel.activePresetId.collectAsState()
|
||||||
|
val activePresetModified by viewModel.isActivePresetModified.collectAsState()
|
||||||
val customPresets by viewModel.customPresets.collectAsState()
|
val customPresets by viewModel.customPresets.collectAsState()
|
||||||
val currentBaselineRecipeParams by viewModel.currentBaselineRecipeParams.collectAsState()
|
val currentBaselineRecipeParams by viewModel.currentBaselineRecipeParams.collectAsState()
|
||||||
val categoryOrder by viewModel.categoryOrder.collectAsState(emptyList())
|
val categoryOrder by viewModel.categoryOrder.collectAsState(emptyList())
|
||||||
@@ -1717,7 +1718,6 @@ fun CameraScreen(
|
|||||||
contentAlignment = Alignment.BottomCenter
|
contentAlignment = Alignment.BottomCenter
|
||||||
) {
|
) {
|
||||||
val allPresets by viewModel.allPresets.collectAsState()
|
val allPresets by viewModel.allPresets.collectAsState()
|
||||||
val activePresetId by viewModel.activePresetId.collectAsState()
|
|
||||||
val defaultPresetName = stringResource(R.string.preset_new_preset_default)
|
val defaultPresetName = stringResource(R.string.preset_new_preset_default)
|
||||||
|
|
||||||
// LUT 选择器 (内嵌 Presets 列表与统一控制,无多余背景遮挡)
|
// LUT 选择器 (内嵌 Presets 列表与统一控制,无多余背景遮挡)
|
||||||
@@ -1729,6 +1729,7 @@ fun CameraScreen(
|
|||||||
allPresets = allPresets,
|
allPresets = allPresets,
|
||||||
presetModeEnabled = true,
|
presetModeEnabled = true,
|
||||||
activePresetId = activePresetId,
|
activePresetId = activePresetId,
|
||||||
|
activePresetModified = activePresetModified,
|
||||||
selectedMode = lutSelectorMode,
|
selectedMode = lutSelectorMode,
|
||||||
onModeSelected = { viewModel.setLutSelectorMode(it) },
|
onModeSelected = { viewModel.setLutSelectorMode(it) },
|
||||||
availableFrames = viewModel.availableFrameList,
|
availableFrames = viewModel.availableFrameList,
|
||||||
@@ -1750,6 +1751,16 @@ fun CameraScreen(
|
|||||||
viewModel.prepareCurrentSettingsPresetDraft(defaultPresetName)
|
viewModel.prepareCurrentSettingsPresetDraft(defaultPresetName)
|
||||||
onPresetEditClick(null)
|
onPresetEditClick(null)
|
||||||
},
|
},
|
||||||
|
onResetPresetClick = {
|
||||||
|
discardTransientLookEdits()
|
||||||
|
val preset = allPresets.firstOrNull { it.id == activePresetId }
|
||||||
|
if (presetRequiresPreviewTransition(preset)) {
|
||||||
|
runPreviewTransition { viewModel.resetActivePreset() }
|
||||||
|
} else {
|
||||||
|
viewModel.resetActivePreset()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onSavePresetClick = viewModel::saveCurrentSettingsToActivePreset,
|
||||||
onPresetManagementClick = onPresetManagementClick,
|
onPresetManagementClick = onPresetManagementClick,
|
||||||
onEditClick = {
|
onEditClick = {
|
||||||
activePanel = ActivePanel.EDIT
|
activePanel = ActivePanel.EDIT
|
||||||
@@ -1774,7 +1785,6 @@ fun CameraScreen(
|
|||||||
showEffects = true,
|
showEffects = true,
|
||||||
onDismiss = {
|
onDismiss = {
|
||||||
previewRecipeParamsOverride = null
|
previewRecipeParamsOverride = null
|
||||||
viewModel.refreshActivePresetMatch()
|
|
||||||
activePanel = ActivePanel.FILTERS
|
activePanel = ActivePanel.FILTERS
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -133,8 +133,10 @@ private fun LutPanelIconButton(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun LutPanelNewPresetButton(
|
private fun LutPanelPresetActionButton(
|
||||||
|
text: String,
|
||||||
onClick: () -> Unit,
|
onClick: () -> Unit,
|
||||||
|
showAddIcon: Boolean = true,
|
||||||
modifier: Modifier = Modifier
|
modifier: Modifier = Modifier
|
||||||
) {
|
) {
|
||||||
val shape = RoundedCornerShape(12.dp)
|
val shape = RoundedCornerShape(12.dp)
|
||||||
@@ -148,14 +150,16 @@ private fun LutPanelNewPresetButton(
|
|||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
horizontalArrangement = Arrangement.spacedBy(3.dp)
|
horizontalArrangement = Arrangement.spacedBy(3.dp)
|
||||||
) {
|
) {
|
||||||
Icon(
|
if (showAddIcon) {
|
||||||
imageVector = Icons.Default.Add,
|
Icon(
|
||||||
contentDescription = null,
|
imageVector = Icons.Default.Add,
|
||||||
tint = Color.White,
|
contentDescription = null,
|
||||||
modifier = Modifier.size(12.dp)
|
tint = Color.White,
|
||||||
)
|
modifier = Modifier.size(12.dp)
|
||||||
|
)
|
||||||
|
}
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(R.string.preset_new),
|
text = text,
|
||||||
color = Color.White,
|
color = Color.White,
|
||||||
fontSize = 11.sp,
|
fontSize = 11.sp,
|
||||||
fontWeight = FontWeight.Medium,
|
fontWeight = FontWeight.Medium,
|
||||||
@@ -179,6 +183,7 @@ fun LutSelector(
|
|||||||
allPresets: List<CameraPreset> = emptyList(),
|
allPresets: List<CameraPreset> = emptyList(),
|
||||||
presetModeEnabled: Boolean = allPresets.isNotEmpty(),
|
presetModeEnabled: Boolean = allPresets.isNotEmpty(),
|
||||||
activePresetId: String? = null,
|
activePresetId: String? = null,
|
||||||
|
activePresetModified: Boolean = false,
|
||||||
selectedMode: LutSelectorMode = LutSelectorMode.Style,
|
selectedMode: LutSelectorMode = LutSelectorMode.Style,
|
||||||
onModeSelected: (LutSelectorMode) -> Unit = {},
|
onModeSelected: (LutSelectorMode) -> Unit = {},
|
||||||
availableFrames: List<FrameInfo> = emptyList(),
|
availableFrames: List<FrameInfo> = emptyList(),
|
||||||
@@ -187,6 +192,8 @@ fun LutSelector(
|
|||||||
onFrameManagementClick: (() -> Unit)? = null,
|
onFrameManagementClick: (() -> Unit)? = null,
|
||||||
onPresetSelected: (CameraPreset?) -> Unit = {},
|
onPresetSelected: (CameraPreset?) -> Unit = {},
|
||||||
onCreatePresetClick: () -> Unit = {},
|
onCreatePresetClick: () -> Unit = {},
|
||||||
|
onResetPresetClick: () -> Unit = {},
|
||||||
|
onSavePresetClick: () -> Unit = {},
|
||||||
onPresetManagementClick: () -> Unit = {},
|
onPresetManagementClick: () -> Unit = {},
|
||||||
onEditClick: (() -> Unit)? = null,
|
onEditClick: (() -> Unit)? = null,
|
||||||
onManageClick: ((String) -> Unit)? = null,
|
onManageClick: ((String) -> Unit)? = null,
|
||||||
@@ -389,7 +396,11 @@ fun LutSelector(
|
|||||||
}
|
}
|
||||||
} ?: ""
|
} ?: ""
|
||||||
Text(
|
Text(
|
||||||
text = currentName,
|
text = if (currentPreset != null && activePresetModified) {
|
||||||
|
"$currentName*"
|
||||||
|
} else {
|
||||||
|
currentName
|
||||||
|
},
|
||||||
color = Color.White,
|
color = Color.White,
|
||||||
fontSize = 13.sp,
|
fontSize = 13.sp,
|
||||||
fontWeight = FontWeight.Bold,
|
fontWeight = FontWeight.Bold,
|
||||||
@@ -403,7 +414,27 @@ fun LutSelector(
|
|||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
horizontalArrangement = Arrangement.spacedBy(6.dp)
|
horizontalArrangement = Arrangement.spacedBy(6.dp)
|
||||||
) {
|
) {
|
||||||
LutPanelNewPresetButton(onClick = onCreatePresetClick)
|
if (currentPreset != null && activePresetModified) {
|
||||||
|
LutPanelPresetActionButton(
|
||||||
|
text = stringResource(R.string.preset_reset),
|
||||||
|
onClick = onResetPresetClick,
|
||||||
|
showAddIcon = false
|
||||||
|
)
|
||||||
|
LutPanelPresetActionButton(
|
||||||
|
text = stringResource(R.string.preset_update),
|
||||||
|
onClick = onSavePresetClick,
|
||||||
|
showAddIcon = false
|
||||||
|
)
|
||||||
|
LutPanelPresetActionButton(
|
||||||
|
text = stringResource(R.string.preset_save_as),
|
||||||
|
onClick = onCreatePresetClick
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
LutPanelPresetActionButton(
|
||||||
|
text = stringResource(R.string.preset_new),
|
||||||
|
onClick = onCreatePresetClick
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
LutPanelIconButton(
|
LutPanelIconButton(
|
||||||
imageVector = Icons.Default.Settings,
|
imageVector = Icons.Default.Settings,
|
||||||
@@ -440,7 +471,8 @@ fun LutSelector(
|
|||||||
LutSelectorModeTab(
|
LutSelectorModeTab(
|
||||||
text = presetText,
|
text = presetText,
|
||||||
isSelected = actualMode == LutSelectorMode.Presets,
|
isSelected = actualMode == LutSelectorMode.Presets,
|
||||||
onClick = { onModeSelected(LutSelectorMode.Presets) }
|
onClick = { onModeSelected(LutSelectorMode.Presets) },
|
||||||
|
badgeText = if (activePresetModified) "*" else null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -536,6 +568,7 @@ fun LutSelector(
|
|||||||
// 预设列表
|
// 预设列表
|
||||||
PresetsPanel(
|
PresetsPanel(
|
||||||
activePresetId = activePresetId,
|
activePresetId = activePresetId,
|
||||||
|
activePresetModified = activePresetModified,
|
||||||
allPresets = allPresets,
|
allPresets = allPresets,
|
||||||
onPresetSelected = onPresetSelected,
|
onPresetSelected = onPresetSelected,
|
||||||
onManagePresets = onPresetManagementClick,
|
onManagePresets = onPresetManagementClick,
|
||||||
@@ -583,13 +616,11 @@ private fun LutSelectorModeTab(
|
|||||||
if (badgeText != null) {
|
if (badgeText != null) {
|
||||||
Text(
|
Text(
|
||||||
text = badgeText,
|
text = badgeText,
|
||||||
color = Color.Black,
|
color = LutPanelAccent,
|
||||||
fontSize = 8.sp,
|
fontSize = 12.sp,
|
||||||
|
lineHeight = 12.sp,
|
||||||
fontWeight = FontWeight.Bold,
|
fontWeight = FontWeight.Bold,
|
||||||
modifier = Modifier
|
modifier = Modifier.offset(y = 1.dp)
|
||||||
.clip(RoundedCornerShape(4.dp))
|
|
||||||
.background(Color(0xFFFFD700))
|
|
||||||
.padding(horizontal = 4.dp, vertical = 1.dp)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -614,7 +645,7 @@ private fun LutItem(
|
|||||||
modifier: Modifier = Modifier
|
modifier: Modifier = Modifier
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val itemShape = RoundedCornerShape(8.dp)
|
val itemShape = RoundedCornerShape(6.dp)
|
||||||
val borderColor by animateColorAsState(
|
val borderColor by animateColorAsState(
|
||||||
targetValue = if (isSelected) LutPanelAccent else Color.White.copy(alpha = 0.15f),
|
targetValue = if (isSelected) LutPanelAccent else Color.White.copy(alpha = 0.15f),
|
||||||
label = "lutItemBorder"
|
label = "lutItemBorder"
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ import com.hinnka.mycamera.ui.camera.ViewfinderTextShadow
|
|||||||
@Composable
|
@Composable
|
||||||
fun PresetsPanel(
|
fun PresetsPanel(
|
||||||
activePresetId: String?,
|
activePresetId: String?,
|
||||||
|
activePresetModified: Boolean,
|
||||||
allPresets: List<CameraPreset>,
|
allPresets: List<CameraPreset>,
|
||||||
onPresetSelected: (CameraPreset?) -> Unit,
|
onPresetSelected: (CameraPreset?) -> Unit,
|
||||||
onManagePresets: () -> Unit,
|
onManagePresets: () -> Unit,
|
||||||
@@ -112,7 +113,7 @@ fun PresetsPanel(
|
|||||||
) {
|
) {
|
||||||
// 预设名
|
// 预设名
|
||||||
Text(
|
Text(
|
||||||
text = displayName,
|
text = if (isSelected && activePresetModified) "$displayName*" else displayName,
|
||||||
color = Color.White,
|
color = Color.White,
|
||||||
fontSize = 10.sp,
|
fontSize = 10.sp,
|
||||||
fontWeight = FontWeight.SemiBold,
|
fontWeight = FontWeight.SemiBold,
|
||||||
|
|||||||
@@ -96,6 +96,7 @@ fun PresetManagementScreen(
|
|||||||
) {
|
) {
|
||||||
val allPresets by viewModel.allPresets.collectAsState()
|
val allPresets by viewModel.allPresets.collectAsState()
|
||||||
val activePresetId by viewModel.activePresetId.collectAsState()
|
val activePresetId by viewModel.activePresetId.collectAsState()
|
||||||
|
val activePresetModified by viewModel.isActivePresetModified.collectAsState()
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
var localPresets by remember { mutableStateOf(allPresets) }
|
var localPresets by remember { mutableStateOf(allPresets) }
|
||||||
@@ -278,6 +279,7 @@ fun PresetManagementScreen(
|
|||||||
preset = preset,
|
preset = preset,
|
||||||
displayName = displayName,
|
displayName = displayName,
|
||||||
isActive = activePresetId == preset.id,
|
isActive = activePresetId == preset.id,
|
||||||
|
isModified = activePresetModified && activePresetId == preset.id,
|
||||||
isDragging = isDragging,
|
isDragging = isDragging,
|
||||||
isExporting = exportingPresetId == preset.id,
|
isExporting = exportingPresetId == preset.id,
|
||||||
dragModifier = Modifier.draggableHandle(),
|
dragModifier = Modifier.draggableHandle(),
|
||||||
@@ -364,6 +366,7 @@ private fun PresetManagementItem(
|
|||||||
preset: CameraPreset,
|
preset: CameraPreset,
|
||||||
displayName: String,
|
displayName: String,
|
||||||
isActive: Boolean,
|
isActive: Boolean,
|
||||||
|
isModified: Boolean,
|
||||||
isDragging: Boolean,
|
isDragging: Boolean,
|
||||||
isExporting: Boolean,
|
isExporting: Boolean,
|
||||||
dragModifier: Modifier,
|
dragModifier: Modifier,
|
||||||
@@ -407,7 +410,7 @@ private fun PresetManagementItem(
|
|||||||
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = displayName,
|
text = if (isModified) "$displayName*" else displayName,
|
||||||
color = if (isActive) Color(0xFFFFD700) else Color.White,
|
color = if (isActive) Color(0xFFFFD700) else Color.White,
|
||||||
fontSize = 15.sp,
|
fontSize = 15.sp,
|
||||||
fontWeight = FontWeight.SemiBold,
|
fontWeight = FontWeight.SemiBold,
|
||||||
|
|||||||
@@ -574,6 +574,11 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
rawMaxSharpening = saved.rawMaxSharpening,
|
rawMaxSharpening = saved.rawMaxSharpening,
|
||||||
rawMaxNoiseReduction = saved.rawMaxNoiseReduction,
|
rawMaxNoiseReduction = saved.rawMaxNoiseReduction,
|
||||||
rawMaxChromaNoiseReduction = saved.rawMaxChromaNoiseReduction,
|
rawMaxChromaNoiseReduction = saved.rawMaxChromaNoiseReduction,
|
||||||
|
rawExposureCompensation = saved.rawExposureCompensation,
|
||||||
|
rawHighlightsAdjustment = saved.rawHighlightsAdjustment,
|
||||||
|
rawShadowsAdjustment = saved.rawShadowsAdjustment,
|
||||||
|
rawBlackPointCorrection = saved.rawBlackPointCorrection,
|
||||||
|
rawWhitePointCorrection = saved.rawWhitePointCorrection,
|
||||||
rawOppoMasterToneMap = saved.rawOppoMasterToneMap,
|
rawOppoMasterToneMap = saved.rawOppoMasterToneMap,
|
||||||
rawSpectralFilmStock = saved.rawSpectralFilmStock,
|
rawSpectralFilmStock = saved.rawSpectralFilmStock,
|
||||||
rawSpectralFilmPrint = saved.rawSpectralFilmPrint,
|
rawSpectralFilmPrint = saved.rawSpectralFilmPrint,
|
||||||
@@ -609,10 +614,58 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
.map { it.activePresetId }
|
.map { it.activePresetId }
|
||||||
.stateIn(viewModelScope, SharingStarted.Eagerly, null)
|
.stateIn(viewModelScope, SharingStarted.Eagerly, null)
|
||||||
|
|
||||||
|
private val activePresetMatchState: StateFlow<ActivePresetMatchState?> = combine(
|
||||||
|
combine(
|
||||||
|
userPreferencesRepository.userPreferences,
|
||||||
|
allPresets,
|
||||||
|
isInitialized
|
||||||
|
) { prefs, presets, initialized ->
|
||||||
|
if (initialized) prefs to presets else null
|
||||||
|
},
|
||||||
|
state.map { it.aspectRatio.name }.distinctUntilChanged(),
|
||||||
|
currentLutId.flatMapLatest { lutId ->
|
||||||
|
contentRepository.lutManager.getColorRecipeParams(lutId).map { recipe ->
|
||||||
|
lutId to recipe
|
||||||
|
}
|
||||||
|
}
|
||||||
|
) { inputs, aspectRatio, (lutId, recipe) ->
|
||||||
|
inputs?.let { (prefs, presets) ->
|
||||||
|
ActivePresetMatchState(
|
||||||
|
prefs = prefs,
|
||||||
|
presets = presets,
|
||||||
|
aspectRatio = aspectRatio,
|
||||||
|
lutId = lutId,
|
||||||
|
recipe = recipe,
|
||||||
|
effects = recipe.toEffectParams()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}.stateIn(viewModelScope, SharingStarted.Eagerly, null)
|
||||||
|
|
||||||
|
private val presetApplyInProgress = MutableStateFlow(false)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the settings currently in use differ from the selected preset.
|
||||||
|
* Selection and matching are deliberately independent: editing a setting keeps the preset
|
||||||
|
* selected and only marks it as modified.
|
||||||
|
*/
|
||||||
|
val isActivePresetModified: StateFlow<Boolean> = combine(
|
||||||
|
activePresetMatchState,
|
||||||
|
presetApplyInProgress
|
||||||
|
) { matchState, applyingPreset ->
|
||||||
|
if (applyingPreset) {
|
||||||
|
false
|
||||||
|
} else {
|
||||||
|
val presetId = matchState?.prefs?.activePresetId ?: return@combine false
|
||||||
|
val preset = matchState.presets.firstOrNull { it.id == presetId }
|
||||||
|
?: return@combine false
|
||||||
|
!matchState.toPresetMatchSnapshot().matches(preset)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.distinctUntilChanged()
|
||||||
|
.stateIn(viewModelScope, SharingStarted.Eagerly, false)
|
||||||
|
|
||||||
var draftPreset: com.hinnka.mycamera.model.CameraPreset? = null
|
var draftPreset: com.hinnka.mycamera.model.CameraPreset? = null
|
||||||
|
|
||||||
@Volatile
|
|
||||||
private var isApplyingPreset = false
|
|
||||||
private val presetApplyMutex = Mutex()
|
private val presetApplyMutex = Mutex()
|
||||||
private val presetMutationMutex = Mutex()
|
private val presetMutationMutex = Mutex()
|
||||||
private var presetApplyGeneration = 0L
|
private var presetApplyGeneration = 0L
|
||||||
@@ -620,9 +673,23 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
private var lutLoadGeneration = 0L
|
private var lutLoadGeneration = 0L
|
||||||
|
|
||||||
fun prepareCurrentSettingsPresetDraft(name: String): com.hinnka.mycamera.model.CameraPreset {
|
fun prepareCurrentSettingsPresetDraft(name: String): com.hinnka.mycamera.model.CameraPreset {
|
||||||
return com.hinnka.mycamera.model.CameraPreset(
|
return createPresetFromCurrentSettings(
|
||||||
id = UUID.randomUUID().toString(),
|
id = UUID.randomUUID().toString(),
|
||||||
name = name,
|
name = name,
|
||||||
|
isBuiltIn = false
|
||||||
|
).also {
|
||||||
|
draftPreset = it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createPresetFromCurrentSettings(
|
||||||
|
id: String,
|
||||||
|
name: String,
|
||||||
|
isBuiltIn: Boolean
|
||||||
|
): com.hinnka.mycamera.model.CameraPreset {
|
||||||
|
return com.hinnka.mycamera.model.CameraPreset(
|
||||||
|
id = id,
|
||||||
|
name = name,
|
||||||
lutId = CameraPreset.normalizeLutId(currentLutId.value),
|
lutId = CameraPreset.normalizeLutId(currentLutId.value),
|
||||||
colorRecipe = currentRecipeParams.value.withoutIndependentEffects(),
|
colorRecipe = currentRecipeParams.value.withoutIndependentEffects(),
|
||||||
effects = currentRecipeParams.value.toEffectParams(),
|
effects = currentRecipeParams.value.toEffectParams(),
|
||||||
@@ -648,10 +715,8 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
rawSpectralFilmPrint = rawSpectralFilmPrint.value,
|
rawSpectralFilmPrint = rawSpectralFilmPrint.value,
|
||||||
rawDROMode = droMode.value,
|
rawDROMode = droMode.value,
|
||||||
rawBaselineLutId = rawBaselineLutId.value,
|
rawBaselineLutId = rawBaselineLutId.value,
|
||||||
isBuiltIn = false
|
isBuiltIn = isBuiltIn
|
||||||
).also {
|
)
|
||||||
draftPreset = it
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getMergedRecipeParams(recipe: ColorRecipeParams = currentRecipeParams.value): ColorRecipeParams {
|
fun getMergedRecipeParams(recipe: ColorRecipeParams = currentRecipeParams.value): ColorRecipeParams {
|
||||||
@@ -660,13 +725,14 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
|
|
||||||
fun applyPreset(preset: com.hinnka.mycamera.model.CameraPreset?) {
|
fun applyPreset(preset: com.hinnka.mycamera.model.CameraPreset?) {
|
||||||
val applyGeneration = ++presetApplyGeneration
|
val applyGeneration = ++presetApplyGeneration
|
||||||
isApplyingPreset = true
|
presetApplyInProgress.value = true
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
presetApplyMutex.withLock {
|
var applied = false
|
||||||
if (presetApplyGeneration != applyGeneration) {
|
try {
|
||||||
return@withLock
|
presetApplyMutex.withLock {
|
||||||
}
|
if (presetApplyGeneration != applyGeneration) {
|
||||||
try {
|
return@withLock
|
||||||
|
}
|
||||||
val currentState = state.value
|
val currentState = state.value
|
||||||
val includePhotoSettings = currentState.captureMode == CaptureMode.PHOTO
|
val includePhotoSettings = currentState.captureMode == CaptureMode.PHOTO
|
||||||
val includeProfessionalSettings = includePhotoSettings &&
|
val includeProfessionalSettings = includePhotoSettings &&
|
||||||
@@ -680,14 +746,21 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
preset.toCameraFeatureUpdate(
|
preset.toCameraFeatureUpdate(
|
||||||
includePhotoSettings = includePhotoSettings,
|
includePhotoSettings = includePhotoSettings,
|
||||||
includeProfessionalSettings = includeProfessionalSettings
|
includeProfessionalSettings = includeProfessionalSettings
|
||||||
).copy(activePresetId = SettingValue(preset?.id)),
|
).copy(activePresetId = SettingValue(preset?.id))
|
||||||
clearActivePresetOnMismatch = false
|
|
||||||
)
|
)
|
||||||
} finally {
|
applied = true
|
||||||
if (presetApplyGeneration == applyGeneration) {
|
}
|
||||||
isApplyingPreset = false
|
|
||||||
|
if (applied && presetApplyGeneration == applyGeneration) {
|
||||||
|
activePresetMatchState.filterNotNull().first { matchState ->
|
||||||
|
matchState.prefs.activePresetId == preset?.id &&
|
||||||
|
(preset == null || matchState.toPresetMatchSnapshot().matches(preset))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
if (presetApplyGeneration == applyGeneration) {
|
||||||
|
presetApplyInProgress.value = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -754,10 +827,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun applyCameraFeatureUpdate(
|
private suspend fun applyCameraFeatureUpdate(update: CameraFeatureUpdate) {
|
||||||
update: CameraFeatureUpdate,
|
|
||||||
clearActivePresetOnMismatch: Boolean = true
|
|
||||||
) {
|
|
||||||
val prefs = userPreferencesRepository.userPreferences.first()
|
val prefs = userPreferencesRepository.userPreferences.first()
|
||||||
var desiredUseRaw = prefs.useRaw
|
var desiredUseRaw = prefs.useRaw
|
||||||
var desiredUseJpgMax = prefs.useJpgMax
|
var desiredUseJpgMax = prefs.useJpgMax
|
||||||
@@ -977,9 +1047,6 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
if (needsCameraReopen) {
|
if (needsCameraReopen) {
|
||||||
reopenCamera()
|
reopenCamera()
|
||||||
}
|
}
|
||||||
if (clearActivePresetOnMismatch) {
|
|
||||||
clearActivePresetIfCurrentSettingsMismatch()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun resolveCaptureRawRenderingEngine(userPrefs: UserPreferences?): RawRenderingEngine {
|
private fun resolveCaptureRawRenderingEngine(userPrefs: UserPreferences?): RawRenderingEngine {
|
||||||
@@ -1014,6 +1081,24 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun resetActivePreset() {
|
||||||
|
val presetId = activePresetId.value ?: return
|
||||||
|
val preset = allPresets.value.firstOrNull { it.id == presetId } ?: return
|
||||||
|
applyPreset(preset)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun saveCurrentSettingsToActivePreset() {
|
||||||
|
val presetId = activePresetId.value ?: return
|
||||||
|
val preset = allPresets.value.firstOrNull { it.id == presetId } ?: return
|
||||||
|
savePreset(
|
||||||
|
createPresetFromCurrentSettings(
|
||||||
|
id = preset.id,
|
||||||
|
name = preset.name,
|
||||||
|
isBuiltIn = preset.isBuiltIn
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun exportPresetPackage(
|
suspend fun exportPresetPackage(
|
||||||
preset: com.hinnka.mycamera.model.CameraPreset,
|
preset: com.hinnka.mycamera.model.CameraPreset,
|
||||||
displayName: String,
|
displayName: String,
|
||||||
@@ -1102,83 +1187,6 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun refreshActivePresetMatch() {
|
|
||||||
viewModelScope.launch {
|
|
||||||
clearActivePresetIfCurrentSettingsMismatch()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun clearActivePresetIfCurrentSettingsMismatch() {
|
|
||||||
if (isApplyingPreset) return
|
|
||||||
val presetId = activePresetId.value ?: return
|
|
||||||
val preset = allPresets.value.firstOrNull { it.id == presetId }
|
|
||||||
if (preset == null) {
|
|
||||||
userPreferencesRepository.saveActivePresetId(null)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
val snapshot = currentPresetMatchSnapshot()
|
|
||||||
if (!snapshot.matches(preset)) {
|
|
||||||
PLog.d(
|
|
||||||
TAG,
|
|
||||||
"Active preset [$presetId] no longer matches current settings; " +
|
|
||||||
"mismatch=${snapshot.mismatchSummary(preset)}; showing default preset"
|
|
||||||
)
|
|
||||||
userPreferencesRepository.saveActivePresetId(null)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun clearActivePresetIfCurrentSettingsMismatch(matchState: ActivePresetMatchState) {
|
|
||||||
if (isApplyingPreset) return
|
|
||||||
val presetId = matchState.prefs.activePresetId ?: return
|
|
||||||
val preset = matchState.presets.firstOrNull { it.id == presetId }
|
|
||||||
if (preset == null) {
|
|
||||||
userPreferencesRepository.saveActivePresetId(null)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
val snapshot = matchState.toPresetMatchSnapshot()
|
|
||||||
if (!snapshot.matches(preset)) {
|
|
||||||
PLog.d(
|
|
||||||
TAG,
|
|
||||||
"Active preset [$presetId] no longer matches current settings; " +
|
|
||||||
"mismatch=${snapshot.mismatchSummary(preset)}; showing default preset"
|
|
||||||
)
|
|
||||||
userPreferencesRepository.saveActivePresetId(null)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun currentPresetMatchSnapshot(): PresetMatchSnapshot {
|
|
||||||
return PresetMatchSnapshot(
|
|
||||||
lutId = CameraPreset.normalizeLutId(currentLutId.value),
|
|
||||||
colorRecipe = currentRecipeParams.value,
|
|
||||||
effects = currentEffectParams.value,
|
|
||||||
captureMode = state.value.captureMode,
|
|
||||||
aspectRatio = state.value.aspectRatio.name,
|
|
||||||
isProfessionalMode = state.value.captureMode == CaptureMode.PHOTO &&
|
|
||||||
useRaw.value && useRawMax.value && !useJpgMax.value,
|
|
||||||
ultraHdrGainMapEnabled = ultraHdrGainMapEnabled.value,
|
|
||||||
frameId = currentFrameId,
|
|
||||||
rawDcpId = rawDcpId.value,
|
|
||||||
rawDcpIdsByLens = rawDcpIdsByLens.value,
|
|
||||||
rawHncsProfileId = rawHncsProfileId.value,
|
|
||||||
rawHncsRenderIntent = rawHncsRenderIntent.value,
|
|
||||||
rawHncsFilmCurveMode = rawHncsFilmCurveMode.value,
|
|
||||||
rawRenderingEngine = rawRenderingEngine.value,
|
|
||||||
rawMaxSharpening = userPreferences.value.rawMaxSharpening,
|
|
||||||
rawMaxNoiseReduction = userPreferences.value.rawMaxNoiseReduction,
|
|
||||||
rawMaxChromaNoiseReduction = userPreferences.value.rawMaxChromaNoiseReduction,
|
|
||||||
rawExposureCompensation = userPreferences.value.rawExposureCompensation,
|
|
||||||
rawHighlightsAdjustment = userPreferences.value.rawHighlightsAdjustment,
|
|
||||||
rawShadowsAdjustment = userPreferences.value.rawShadowsAdjustment,
|
|
||||||
rawBlackPointCorrection = userPreferences.value.rawBlackPointCorrection,
|
|
||||||
rawWhitePointCorrection = userPreferences.value.rawWhitePointCorrection,
|
|
||||||
rawOppoMasterToneMap = rawToneMappingParameters.value.useOppoMasterToneMap,
|
|
||||||
rawSpectralFilmStock = rawSpectralFilmStock.value,
|
|
||||||
rawSpectralFilmPrint = rawSpectralFilmPrint.value,
|
|
||||||
rawDROMode = droMode.value,
|
|
||||||
rawBaselineLutId = rawBaselineLutId.value
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun ActivePresetMatchState.toPresetMatchSnapshot(): PresetMatchSnapshot {
|
private fun ActivePresetMatchState.toPresetMatchSnapshot(): PresetMatchSnapshot {
|
||||||
return PresetMatchSnapshot(
|
return PresetMatchSnapshot(
|
||||||
lutId = CameraPreset.normalizeLutId(lutId),
|
lutId = CameraPreset.normalizeLutId(lutId),
|
||||||
@@ -2178,38 +2186,6 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
viewModelScope.launch {
|
|
||||||
val presetInputs = combine(
|
|
||||||
userPreferencesRepository.userPreferences,
|
|
||||||
allPresets,
|
|
||||||
isInitialized
|
|
||||||
) { prefs, presets, initialized ->
|
|
||||||
if (initialized) prefs to presets else null
|
|
||||||
}
|
|
||||||
|
|
||||||
combine(
|
|
||||||
presetInputs,
|
|
||||||
state.map { it.aspectRatio.name }.distinctUntilChanged(),
|
|
||||||
currentLutId.flatMapLatest { lutId -> contentRepository.lutManager.getColorRecipeParams(lutId) },
|
|
||||||
currentEffectParams
|
|
||||||
) { inputs, aspectRatio, recipe, effects ->
|
|
||||||
inputs?.let { (prefs, presets) ->
|
|
||||||
ActivePresetMatchState(
|
|
||||||
prefs = prefs,
|
|
||||||
presets = presets,
|
|
||||||
aspectRatio = aspectRatio,
|
|
||||||
lutId = currentLutId.value,
|
|
||||||
recipe = recipe,
|
|
||||||
effects = effects
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}.collect { matchState ->
|
|
||||||
if (matchState != null) {
|
|
||||||
clearActivePresetIfCurrentSettingsMismatch(matchState)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 加载用户偏好设置
|
// 加载用户偏好设置
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
val prefs = userPreferencesRepository.userPreferences.firstOrNull()
|
val prefs = userPreferencesRepository.userPreferences.firstOrNull()
|
||||||
@@ -2442,7 +2418,6 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
if (selection != null && selection.id == previousStock) {
|
if (selection != null && selection.id == previousStock) {
|
||||||
userPreferencesRepository.saveRawSpectralFilmTuning(selection.id, selection.tuning)
|
userPreferencesRepository.saveRawSpectralFilmTuning(selection.id, selection.tuning)
|
||||||
}
|
}
|
||||||
clearActivePresetIfCurrentSettingsMismatch()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fun setRawToneMappingParameters(value: RawToneMappingParameters) {
|
fun setRawToneMappingParameters(value: RawToneMappingParameters) {
|
||||||
@@ -3902,7 +3877,6 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
userPreferencesRepository.saveVideoLutConfig(normalizedLutId)
|
userPreferencesRepository.saveVideoLutConfig(normalizedLutId)
|
||||||
} else {
|
} else {
|
||||||
userPreferencesRepository.saveLutConfig(normalizedLutId)
|
userPreferencesRepository.saveLutConfig(normalizedLutId)
|
||||||
clearActivePresetIfCurrentSettingsMismatch()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3931,7 +3905,6 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
}
|
}
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
userPreferencesRepository.saveLutConfig(normalizedLutId)
|
userPreferencesRepository.saveLutConfig(normalizedLutId)
|
||||||
clearActivePresetIfCurrentSettingsMismatch()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1148,6 +1148,9 @@
|
|||||||
<string name="preset_builtin_cinematic">電影寬幅</string>
|
<string name="preset_builtin_cinematic">電影寬幅</string>
|
||||||
<string name="preset_builtin_leica_m9_moment">徠卡一瞬</string>
|
<string name="preset_builtin_leica_m9_moment">徠卡一瞬</string>
|
||||||
<string name="preset_save">儲存</string>
|
<string name="preset_save">儲存</string>
|
||||||
|
<string name="preset_reset">重設</string>
|
||||||
|
<string name="preset_update">同步儲存</string>
|
||||||
|
<string name="preset_save_as">另存新檔</string>
|
||||||
<string name="preset_editor_title">編輯拍攝預設</string>
|
<string name="preset_editor_title">編輯拍攝預設</string>
|
||||||
<string name="preset_new_preset_default">新預設</string>
|
<string name="preset_new_preset_default">新預設</string>
|
||||||
<string name="preset_name_label">預設名稱</string>
|
<string name="preset_name_label">預設名稱</string>
|
||||||
|
|||||||
@@ -878,6 +878,9 @@
|
|||||||
<string name="preset_builtin_cinematic">ภาพยนตร์กว้าง</string>
|
<string name="preset_builtin_cinematic">ภาพยนตร์กว้าง</string>
|
||||||
<string name="preset_builtin_leica_m9_moment">ช่วงเวลาไลก้า</string>
|
<string name="preset_builtin_leica_m9_moment">ช่วงเวลาไลก้า</string>
|
||||||
<string name="preset_save">บันทึก</string>
|
<string name="preset_save">บันทึก</string>
|
||||||
|
<string name="preset_reset">รีเซ็ต</string>
|
||||||
|
<string name="preset_update">อัปเดต</string>
|
||||||
|
<string name="preset_save_as">บันทึกเป็น</string>
|
||||||
<string name="preset_editor_title">แก้ไขการตั้งค่าการถ่ายภาพล่วงหน้า</string>
|
<string name="preset_editor_title">แก้ไขการตั้งค่าการถ่ายภาพล่วงหน้า</string>
|
||||||
<string name="preset_new_preset_default">ค่าที่ตั้งล่วงหน้าใหม่</string>
|
<string name="preset_new_preset_default">ค่าที่ตั้งล่วงหน้าใหม่</string>
|
||||||
<string name="preset_name_label">ชื่อเริ่มต้น</string>
|
<string name="preset_name_label">ชื่อเริ่มต้น</string>
|
||||||
|
|||||||
@@ -1167,6 +1167,9 @@
|
|||||||
<string name="preset_builtin_cinematic">电影宽幅</string>
|
<string name="preset_builtin_cinematic">电影宽幅</string>
|
||||||
<string name="preset_builtin_leica_m9_moment">徕卡一瞬</string>
|
<string name="preset_builtin_leica_m9_moment">徕卡一瞬</string>
|
||||||
<string name="preset_save">保存</string>
|
<string name="preset_save">保存</string>
|
||||||
|
<string name="preset_reset">重置</string>
|
||||||
|
<string name="preset_update">同步保存</string>
|
||||||
|
<string name="preset_save_as">另存为</string>
|
||||||
<string name="preset_editor_title">编辑拍摄预设</string>
|
<string name="preset_editor_title">编辑拍摄预设</string>
|
||||||
<string name="preset_new_preset_default">新预设</string>
|
<string name="preset_new_preset_default">新预设</string>
|
||||||
<string name="preset_name_label">预设名称</string>
|
<string name="preset_name_label">预设名称</string>
|
||||||
|
|||||||
@@ -1144,6 +1144,9 @@
|
|||||||
<string name="preset_builtin_cinematic">電影寬幅</string>
|
<string name="preset_builtin_cinematic">電影寬幅</string>
|
||||||
<string name="preset_builtin_leica_m9_moment">徠卡一瞬</string>
|
<string name="preset_builtin_leica_m9_moment">徠卡一瞬</string>
|
||||||
<string name="preset_save">儲存</string>
|
<string name="preset_save">儲存</string>
|
||||||
|
<string name="preset_reset">重設</string>
|
||||||
|
<string name="preset_update">同步儲存</string>
|
||||||
|
<string name="preset_save_as">另存新檔</string>
|
||||||
<string name="preset_editor_title">編輯拍攝預設</string>
|
<string name="preset_editor_title">編輯拍攝預設</string>
|
||||||
<string name="preset_new_preset_default">新預設</string>
|
<string name="preset_new_preset_default">新預設</string>
|
||||||
<string name="preset_name_label">預設名稱</string>
|
<string name="preset_name_label">預設名稱</string>
|
||||||
|
|||||||
@@ -1148,6 +1148,9 @@
|
|||||||
<string name="preset_builtin_cinematic">電影寬幅</string>
|
<string name="preset_builtin_cinematic">電影寬幅</string>
|
||||||
<string name="preset_builtin_leica_m9_moment">徠卡一瞬</string>
|
<string name="preset_builtin_leica_m9_moment">徠卡一瞬</string>
|
||||||
<string name="preset_save">儲存</string>
|
<string name="preset_save">儲存</string>
|
||||||
|
<string name="preset_reset">重設</string>
|
||||||
|
<string name="preset_update">同步儲存</string>
|
||||||
|
<string name="preset_save_as">另存新檔</string>
|
||||||
<string name="preset_editor_title">編輯拍攝預設</string>
|
<string name="preset_editor_title">編輯拍攝預設</string>
|
||||||
<string name="preset_new_preset_default">新預設</string>
|
<string name="preset_new_preset_default">新預設</string>
|
||||||
<string name="preset_name_label">預設名稱</string>
|
<string name="preset_name_label">預設名稱</string>
|
||||||
|
|||||||
@@ -1169,6 +1169,9 @@
|
|||||||
<string name="preset_builtin_cinematic">Cinematic</string>
|
<string name="preset_builtin_cinematic">Cinematic</string>
|
||||||
<string name="preset_builtin_leica_m9_moment">Leica Moment</string>
|
<string name="preset_builtin_leica_m9_moment">Leica Moment</string>
|
||||||
<string name="preset_save">Save</string>
|
<string name="preset_save">Save</string>
|
||||||
|
<string name="preset_reset">Reset</string>
|
||||||
|
<string name="preset_update">Update</string>
|
||||||
|
<string name="preset_save_as">Save As</string>
|
||||||
|
|
||||||
<!-- Preset Editor & Management Extensions -->
|
<!-- Preset Editor & Management Extensions -->
|
||||||
<string name="preset_editor_title">Edit Preset</string>
|
<string name="preset_editor_title">Edit Preset</string>
|
||||||
|
|||||||
Reference in new issue
Block a user