feat: VIP purchase requirements and badges for premium editing tools

This commit is contained in:
Hinnka committed 2026-11-15 13:59:09 +08:00
1 parent f3449a1a82
commit bb8fbcab3b
7 files changed
+150 -71

No files matched your search

@@ -53,7 +53,8 @@ fun ApertureScaleSettingItem(
toggleValue: Boolean? = null,
onToggleChange: (Boolean) -> Unit = {},
enabled: Boolean = toggleValue ?: true,
modifier: Modifier = Modifier
modifier: Modifier = Modifier,
isVip: Boolean = false
) {
val shouldShowScale = enabled || toggleValue == null
val selectedIndex = closestApertureStopIndex(value)
@@ -83,10 +84,14 @@ fun ApertureScaleSettingItem(
Row(verticalAlignment = Alignment.CenterVertically) {
Text(
text = title,
modifier = Modifier.weight(1f, fill = false),
color = Color.White,
fontSize = 16.sp,
fontWeight = FontWeight.Normal
)
if (isVip) {
VipBadge(Modifier.padding(start = 8.dp))
}
if (shouldShowScale) {
Spacer(modifier = Modifier.width(8.dp))
Text(
@@ -748,7 +748,7 @@ private fun LutItem(
)
}
if (isVip) {
if (showVipBadges && isVip) {
Box(
modifier = Modifier
.align(Alignment.TopEnd)
@@ -21,7 +21,8 @@ fun SwitchSettingItem(
description: String? = null,
checked: Boolean,
onCheckedChange: (Boolean) -> Unit,
modifier: Modifier = Modifier
modifier: Modifier = Modifier,
isVip: Boolean = false
) {
Column(
modifier = modifier
@@ -34,12 +35,18 @@ fun SwitchSettingItem(
verticalAlignment = Alignment.CenterVertically
) {
Column(modifier = Modifier.weight(1f)) {
Text(
text = title,
color = Color.White,
fontSize = 16.sp,
fontWeight = FontWeight.Normal
)
Row(verticalAlignment = Alignment.CenterVertically) {
Text(
text = title,
modifier = Modifier.weight(1f, fill = false),
color = Color.White,
fontSize = 16.sp,
fontWeight = FontWeight.Normal
)
if (isVip) {
VipBadge(Modifier.padding(start = 8.dp))
}
}
description?.let {
Spacer(modifier = Modifier.height(2.dp))
Text(
@@ -0,0 +1,35 @@
package com.hinnka.mycamera.ui.components
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.hinnka.mycamera.BuildConfig
import com.hinnka.mycamera.R
import com.hinnka.mycamera.ui.theme.PremiumGold
internal val showVipBadges = BuildConfig.FLAVOR == "google"
@Composable
internal fun VipBadge(modifier: Modifier = Modifier) {
if (!showVipBadges) return
Text(
text = stringResource(R.string.billing_vip_tag),
modifier = modifier
.background(PremiumGold, RoundedCornerShape(4.dp))
.padding(horizontal = 4.dp),
color = Color.Black,
fontSize = 10.sp,
fontWeight = FontWeight.Bold,
lineHeight = 16.sp,
maxLines = 1
)
}
@@ -207,11 +207,11 @@ fun GalleryEditScreen(
modifier: Modifier = Modifier
) {
val context = LocalContext.current
val isPurchased by viewModel.isPurchased.collectAsState()
val depthModelState by remember(context.applicationContext) {
DepthModelManager.observe(context)
}.collectAsState()
val isDepthModelInstalled = DepthModelManager.isInstalled(context)
var showDepthModelDownloadDialog by remember { mutableStateOf(false) }
var pendingVirtualAperture by remember { mutableStateOf<Float?>(null) }
val colorFmModelState by remember(context.applicationContext) {
ColorFmModelManager.observe(context)
@@ -224,16 +224,16 @@ fun GalleryEditScreen(
val colorMatchReferenceLauncher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.PickVisualMedia()
) { uri ->
if (uri != null) pendingColorMatchReference = ColorMatchReferenceStore.Source.NewImage(uri)
if (uri != null && viewModel.requireEditPurchase()) {
pendingColorMatchReference = ColorMatchReferenceStore.Source.NewImage(uri)
}
}
LaunchedEffect(depthModelState, pendingVirtualAperture) {
val pendingAperture = pendingVirtualAperture
if (depthModelState is DepthModelDownloadState.Ready && pendingAperture != null) {
viewModel.setComputationalAperture(pendingAperture)
pendingVirtualAperture = null
showDepthModelDownloadDialog = false
}
LaunchedEffect(isPurchased, depthModelState, pendingVirtualAperture) {
val pendingAperture = pendingVirtualAperture ?: return@LaunchedEffect
if (isPurchased && depthModelState !is DepthModelDownloadState.Ready) return@LaunchedEffect
pendingVirtualAperture = null
if (isPurchased) viewModel.setComputationalAperture(pendingAperture)
}
val userPreferencesRepository = remember {
@@ -257,7 +257,6 @@ fun GalleryEditScreen(
val lutSwipeState = rememberLutSwipeState()
val density = LocalDensity.current
val showPaymentDialog = viewModel.showPaymentDialog
val isPurchased by viewModel.isPurchased.collectAsState()
val categoryOrder by preferenceValue { it.categoryOrder }
val hasCopiedEditSettings by viewModel.hasCopiedEditSettings.collectAsState()
@@ -649,8 +648,12 @@ fun GalleryEditScreen(
}
}
}
LaunchedEffect(aiDenoiseModelState, pendingAiDenoise) {
if (aiDenoiseModelState is HfModelState.Ready && pendingAiDenoise) {
LaunchedEffect(isPurchased, aiDenoiseModelState, pendingAiDenoise) {
if (!pendingAiDenoise) return@LaunchedEffect
if (!isPurchased) {
pendingAiDenoise = false
viewModel.revertAiDenoiseEnabled()
} else if (aiDenoiseModelState is HfModelState.Ready) {
pendingAiDenoise = false
startAiDenoise()
}
@@ -1023,7 +1026,7 @@ fun GalleryEditScreen(
toggleEditControls()
} else if (
editTab == EDIT_TAB_DETAIL &&
viewModel.editComputationalAperture.value != null &&
viewModel.editComputationalAperture.value?.let { it > 0f } == true &&
previewBitmap != null
) {
val tapPosition = upEvent.changes[0].position
@@ -1593,13 +1596,17 @@ fun GalleryEditScreen(
references = colorMatchReferences,
enabled = !isAiColorMatching,
onAddReference = {
colorMatchReferenceLauncher.launch(
PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)
)
if (viewModel.requireEditPurchase()) {
colorMatchReferenceLauncher.launch(
PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)
)
}
},
onReuseReference = {
pendingColorMatchReference =
ColorMatchReferenceStore.Source.Saved(it)
if (viewModel.requireEditPurchase()) {
pendingColorMatchReference =
ColorMatchReferenceStore.Source.Saved(it)
}
},
onDeleteReference = { colorMatchReferenceToDelete = it },
onRemove = { viewModel.setEditLut(null) },
@@ -1789,8 +1796,12 @@ fun GalleryEditScreen(
aiDenoiseProgress * 100
) else stringResource(R.string.ai_denoise_description),
checked = editAiDenoiseEnabled,
isVip = true,
onCheckedChange = { enabled ->
if (isAiDenoising) return@SwitchSettingItem
if (enabled && !viewModel.requireEditPurchase()) {
return@SwitchSettingItem
}
viewModel.setAiDenoiseEnabled(enabled)
if (enabled) {
if (AiDenoiseModelManager.isInstalled(context)) {
@@ -1811,6 +1822,8 @@ fun GalleryEditScreen(
Spacer(modifier = Modifier.height(8.dp))
// 细节处理调整 (锐化, 降噪, 杂色降噪)
val aperture = editComputationalAperture
val bokehEnabled = aperture != null && aperture > 0f
val canAdjustBokeh = isPurchased && isDepthModelInstalled && bokehEnabled
ApertureScaleSettingItem(
title = stringResource(
R.string.gallery_large_aperture_blur_title
@@ -1818,17 +1831,16 @@ fun GalleryEditScreen(
description = stringResource(
R.string.gallery_large_aperture_blur_description
),
value = editComputationalAperture
?: DEFAULT_COMPUTATIONAL_APERTURE,
onValueChange = { viewModel.setComputationalAperture(it) },
toggleValue = isDepthModelInstalled &&
aperture != null &&
aperture > 0f,
enabled = isDepthModelInstalled &&
aperture != null &&
aperture > 0f,
value = aperture ?: DEFAULT_COMPUTATIONAL_APERTURE,
onValueChange = viewModel::setComputationalAperture,
toggleValue = bokehEnabled,
enabled = canAdjustBokeh,
isVip = true,
onToggleChange = { checked ->
if (checked) {
if (!viewModel.requireEditPurchase()) {
return@ApertureScaleSettingItem
}
val requestedAperture = aperture
?.takeIf { it > 0f }
?: DEFAULT_COMPUTATIONAL_APERTURE
@@ -1836,18 +1848,13 @@ fun GalleryEditScreen(
viewModel.setComputationalAperture(requestedAperture)
} else {
pendingVirtualAperture = requestedAperture
showDepthModelDownloadDialog = true
}
} else {
viewModel.setComputationalAperture(null)
}
}
)
if (
isDepthModelInstalled &&
aperture != null &&
aperture > 0f
) {
if (canAdjustBokeh) {
BokehStyleSelector(
selectedStyle = editBokehStyle,
onStyleSelected = viewModel::setBokehStyle,
@@ -1884,9 +1891,11 @@ fun GalleryEditScreen(
value = editChromaNoiseReduction,
valueRange = DenoiseStrength.valueRange,
resetValue = 0f,
enabled = isPurchased || !editAiDenoiseEnabled,
onValueChange = { viewModel.setChromaNoiseReduction(it) },
onValueChangeFinished = {
if (viewModel.hasAppliedAiDenoise()) {
if (!viewModel.requireEditPurchase()) return@SliderSettingItem
// Color noise is reduced before AI denoise: run AI denoise again.
if (isRaw) {
viewModel.persistCurrentRawEditMetadata(currentEditSourcePhoto) { success ->
@@ -2174,8 +2183,12 @@ fun GalleryEditScreen(
}
// AI color match: download the model first if needed, then run once it is Ready.
LaunchedEffect(pendingColorMatchReference, colorFmModelState) {
LaunchedEffect(isPurchased, pendingColorMatchReference, colorFmModelState) {
val reference = pendingColorMatchReference ?: return@LaunchedEffect
if (!isPurchased) {
pendingColorMatchReference = null
return@LaunchedEffect
}
if (colorFmModelState !is HfModelState.Ready) return@LaunchedEffect
pendingColorMatchReference = null
val photo = editSourcePhoto ?: return@LaunchedEffect
@@ -2185,7 +2198,7 @@ fun GalleryEditScreen(
}
}
}
if (pendingColorMatchReference != null && colorFmModelState !is HfModelState.Ready) {
if (isPurchased && pendingColorMatchReference != null && colorFmModelState !is HfModelState.Ready) {
var colorFmModelSource by remember { mutableStateOf(HfModelSource.preferred(context)) }
HfModelDownloadDialog(
title = stringResource(R.string.ai_color_match_model_title),
@@ -2232,7 +2245,7 @@ fun GalleryEditScreen(
)
}
if (pendingAiDenoise) {
if (isPurchased && pendingAiDenoise) {
var aiDenoiseModelSource by remember { mutableStateOf(HfModelSource.preferred(context)) }
HfModelDownloadDialog(
title = stringResource(R.string.ai_denoise_model_title),
@@ -2248,17 +2261,14 @@ fun GalleryEditScreen(
)
}
if (showDepthModelDownloadDialog) {
if (isPurchased && pendingVirtualAperture != null) {
var depthModelSource by remember { mutableStateOf(HfModelSource.preferred(context)) }
DepthModelDownloadDialog(
source = depthModelSource,
onSourceChange = { depthModelSource = it },
state = depthModelState,
onDownload = { DepthModelManager.download(context, depthModelSource) },
onDismiss = {
showDepthModelDownloadDialog = false
pendingVirtualAperture = null
}
onDismiss = { pendingVirtualAperture = null }
)
}
}
@@ -2519,7 +2529,7 @@ private fun FrameOption(
}
}
if (isVip) {
if (showVipBadges && isVip) {
Box(
modifier = Modifier
.align(Alignment.TopEnd)
@@ -2784,12 +2794,18 @@ private fun AiColorMatchRow(
.padding(horizontal = 12.dp, vertical = 10.dp)
) {
Row(verticalAlignment = Alignment.CenterVertically) {
Text(
text = stringResource(if (active) R.string.ai_color_match_active else R.string.ai_color_match_action),
color = if (active) AccentColor else Color.White,
style = MaterialTheme.typography.titleSmall,
modifier = Modifier.weight(1f)
)
Row(
modifier = Modifier.weight(1f),
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = stringResource(if (active) R.string.ai_color_match_active else R.string.ai_color_match_action),
modifier = Modifier.weight(1f, fill = false),
color = if (active) AccentColor else Color.White,
style = MaterialTheme.typography.titleSmall
)
VipBadge(Modifier.padding(start = 8.dp))
}
if (active) {
TextButton(
onClick = onRemove,
@@ -54,6 +54,7 @@ import com.hinnka.mycamera.ui.camera.autoRotate
import com.hinnka.mycamera.ui.camera.LutEditBottomSheet
import com.hinnka.mycamera.utils.PLog
import com.hinnka.mycamera.ui.components.PaymentDialog
import com.hinnka.mycamera.ui.components.showVipBadges
import com.hinnka.mycamera.viewmodel.CameraViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@@ -1858,7 +1859,7 @@ private fun FilterManagementItem(
)
// VIP 标签
if (lutInfo.isVip) {
if (showVipBadges && lutInfo.isVip) {
Spacer(modifier = Modifier.width(4.dp))
Text(
text = stringResource(R.string.billing_vip_tag),
@@ -519,18 +519,26 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
private val _isBokehProcessing = MutableStateFlow(false)
val isBokehProcessing = _isBokehProcessing.asStateFlow()
fun requireEditPurchase(): Boolean {
if (isPurchased.value) return true
showPaymentDialog = true
return false
}
fun setComputationalAperture(value: Float?) {
if (value != null && value > 0f && !requireEditPurchase()) return
editComputationalAperture.value = value
updateBokehPhoto()
}
fun setBokehStyle(value: BokehStyle) {
if (editBokehStyle.value == value) return
if (editBokehStyle.value == value || !requireEditPurchase()) return
editBokehStyle.value = value
updateBokehPhoto()
}
fun setFocusPoint(x: Float, y: Float) {
if (!requireEditPurchase()) return
val cropRect = editCropRect.value
val croppedX = cropRect?.let { it.left + x * it.width() } ?: x
val croppedY = cropRect?.let { it.top + y * it.height() } ?: y
@@ -647,6 +655,10 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
fun applyAiDenoise(photo: MediaData, onComplete: (Boolean) -> Unit) {
if (_isAiDenoising.value) return
if (!requireEditPurchase()) {
revertAiDenoiseEnabled()
return
}
_isAiDenoising.value = true
_aiDenoiseProgress.value = 0f
@@ -2477,7 +2489,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
* with the id of the reference record it was made from, not in the filter library.
*/
fun applyAiColorMatch(photo: MediaData, source: ColorMatchReferenceStore.Source, onComplete: (Boolean) -> Unit) {
if (_isAiColorMatching.value) return
if (_isAiColorMatching.value || !requireEditPurchase()) return
_isAiColorMatching.value = true
viewModelScope.launch {
val lutId = withContext(Dispatchers.IO) {
@@ -2846,6 +2858,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
fun pasteCopiedEditSettingsToCurrentEdit(): Map<String, String>? {
val copied = copiedEditSettings ?: return null
val settings = copied.metadata
val canPasteBokeh = isPurchased.value
viewModelScope.launch {
flushPendingEditLutRecipeSync()
@@ -2867,12 +2880,12 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
editChromaNoiseReduction.value = DenoiseStrength.clamp(it)
}
}
editComputationalAperture.value = settings.computationalAperture
editBokehStyle.value = BokehStyle.fromPersistedName(
settings.computationalBokehStyle
)
editFocusPointX.value = settings.focusPointX
editFocusPointY.value = settings.focusPointY
if (canPasteBokeh) {
editComputationalAperture.value = settings.computationalAperture
editBokehStyle.value = BokehStyle.fromPersistedName(settings.computationalBokehStyle)
editFocusPointX.value = settings.focusPointX
editFocusPointY.value = settings.focusPointY
}
editRotationDegrees.value =
PostEditGeometry.normalizeRotation(settings.postRotationDegrees)
editStraightenDegrees.value =
@@ -2898,7 +2911,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
} ?: run {
editLutConfig = null
}
updateBokehPhoto()
if (canPasteBokeh) updateBokehPhoto()
return settings.customProperties.toMap()
}
@@ -2929,6 +2942,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
* 设置减少杂色强度
*/
fun setChromaNoiseReduction(value: Float) {
if (hasAppliedAiDenoise() && !requireEditPurchase()) return
editChromaNoiseReduction.value = DenoiseStrength.clamp(value)
}
@@ -4362,6 +4376,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
copyDetailProcessing: Boolean
): MediaMetadata {
val settings = copied.metadata
val canPasteBokeh = isPurchased.value
val (cropWidth, cropHeight) = PostEditGeometry.editedDimensions(
current.width,
current.height,
@@ -4402,10 +4417,10 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
} else {
current.chromaNoiseReduction
},
computationalAperture = settings.computationalAperture,
computationalBokehStyle = settings.computationalBokehStyle,
focusPointX = settings.focusPointX,
focusPointY = settings.focusPointY,
computationalAperture = if (canPasteBokeh) settings.computationalAperture else current.computationalAperture,
computationalBokehStyle = if (canPasteBokeh) settings.computationalBokehStyle else current.computationalBokehStyle,
focusPointX = if (canPasteBokeh) settings.focusPointX else current.focusPointX,
focusPointY = if (canPasteBokeh) settings.focusPointY else current.focusPointY,
postCropRegion = cropRegion,
postRotationDegrees =
PostEditGeometry.normalizeRotation(settings.postRotationDegrees),