From 68c547b91292a133c6d65784e56c47b3b9468c60 Mon Sep 17 00:00:00 2001 From: zhoubinjia Date: Thu, 8 Jan 2026 17:17:45 +0800 Subject: [PATCH] feat: google play billing --- app/build.gradle.kts | 11 +- .../mycamera/billing/BillingManagerImpl.kt | 21 +++ .../mycamera/billing/BillingManagerImpl.kt | 143 +++++++++++++++ .../hinnka/mycamera/billing/BillingManager.kt | 24 +++ .../com/hinnka/mycamera/lut/CubeLutParser.kt | 3 +- .../java/com/hinnka/mycamera/lut/LutConfig.kt | 3 +- .../java/com/hinnka/mycamera/lut/LutParser.kt | 3 +- .../hinnka/mycamera/ui/camera/CameraScreen.kt | 23 +++ .../mycamera/ui/components/LutSelector.kt | 24 ++- .../mycamera/ui/components/PaymentDialog.kt | 170 ++++++++++++++++++ .../mycamera/ui/gallery/PhotoEditScreen.kt | 50 ++++++ .../mycamera/ui/settings/SettingsScreen.kt | 79 ++++++++ .../mycamera/viewmodel/CameraViewModel.kt | 23 +++ .../mycamera/viewmodel/GalleryViewModel.kt | 36 ++++ app/src/main/res/values-zh/strings.xml | 13 ++ app/src/main/res/values/strings.xml | 12 ++ gradle/libs.versions.toml | 21 ++- 17 files changed, 641 insertions(+), 18 deletions(-) create mode 100644 app/src/china/java/com/hinnka/mycamera/billing/BillingManagerImpl.kt create mode 100644 app/src/google/java/com/hinnka/mycamera/billing/BillingManagerImpl.kt create mode 100644 app/src/main/java/com/hinnka/mycamera/billing/BillingManager.kt create mode 100644 app/src/main/java/com/hinnka/mycamera/ui/components/PaymentDialog.kt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index f4fce941..1f5da747 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -47,11 +47,8 @@ android { } compileOptions { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 - } - kotlinOptions { - jvmTarget = "11" + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 } buildFeatures { compose = true @@ -97,6 +94,10 @@ dependencies { // Bugly for china flavor "chinaImplementation"("com.tencent.bugly:crashreport:latest.release") + // Billing for google flavor + "googleImplementation"(libs.google.billing) + "googleImplementation"(libs.google.billing.ktx) + testImplementation(libs.junit) androidTestImplementation(libs.androidx.junit) androidTestImplementation(libs.androidx.espresso.core) diff --git a/app/src/china/java/com/hinnka/mycamera/billing/BillingManagerImpl.kt b/app/src/china/java/com/hinnka/mycamera/billing/BillingManagerImpl.kt new file mode 100644 index 00000000..7b5bf65a --- /dev/null +++ b/app/src/china/java/com/hinnka/mycamera/billing/BillingManagerImpl.kt @@ -0,0 +1,21 @@ +package com.hinnka.mycamera.billing + +import android.app.Activity +import android.content.Context +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.asStateFlow + +class BillingManagerImpl(private val context: Context) : BillingManager { + // 默认已付费或不需要付费逻辑,这里根据中国版本需求通常可能对内免费或使用其他计费方式 + // 暂时设为 true 以便测试,或者设为 false + private val _isPurchased = MutableStateFlow(true) + override val isPurchased: StateFlow = _isPurchased.asStateFlow() + + override fun purchase(activity: Activity) { + // China version might use other billing methods or be free + } + + override fun refresh() { + } +} diff --git a/app/src/google/java/com/hinnka/mycamera/billing/BillingManagerImpl.kt b/app/src/google/java/com/hinnka/mycamera/billing/BillingManagerImpl.kt new file mode 100644 index 00000000..2b0a6d91 --- /dev/null +++ b/app/src/google/java/com/hinnka/mycamera/billing/BillingManagerImpl.kt @@ -0,0 +1,143 @@ +package com.hinnka.mycamera.billing + +import android.app.Activity +import android.content.Context +import android.util.Log +import com.android.billingclient.api.* +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.SupervisorJob +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.launch + +class BillingManagerImpl(private val context: Context) : BillingManager { + companion object { + private const val TAG = "BillingManager" + private const val PRODUCT_ID = "full_version_permanent" + } + + private val scope = CoroutineScope(SupervisorJob() + Dispatchers.Main) + + private val _isPurchased = MutableStateFlow(false) + override val isPurchased: StateFlow = _isPurchased.asStateFlow() + + private val purchasesUpdatedListener = PurchasesUpdatedListener { billingResult, purchases -> + if (billingResult.responseCode == BillingClient.BillingResponseCode.OK && purchases != null) { + for (purchase in purchases) { + handlePurchase(purchase) + } + } else if (billingResult.responseCode == BillingClient.BillingResponseCode.USER_CANCELED) { + Log.d(TAG, "User canceled the purchase") + } else { + Log.e(TAG, "Purchase error: ${billingResult.debugMessage}") + } + } + + private val billingClient = BillingClient.newBuilder(context) + .setListener(purchasesUpdatedListener) + .enablePendingPurchases(PendingPurchasesParams.newBuilder().enableOneTimeProducts().build()) + .build() + + init { + startConnection() + } + + private fun startConnection() { + billingClient.startConnection(object : BillingClientStateListener { + override fun onBillingSetupFinished(billingResult: BillingResult) { + if (billingResult.responseCode == BillingClient.BillingResponseCode.OK) { + Log.d(TAG, "Billing setup finished") + queryPurchases() + } + } + + override fun onBillingServiceDisconnected() { + Log.d(TAG, "Billing service disconnected, retrying...") + // Retry logic if needed + } + }) + } + + private fun queryPurchases() { + val params = QueryPurchasesParams.newBuilder() + .setProductType(BillingClient.ProductType.INAPP) + .build() + + billingClient.queryPurchasesAsync(params) { billingResult, purchases -> + if (billingResult.responseCode == BillingClient.BillingResponseCode.OK) { + val purchased = purchases.any { it.purchaseState == Purchase.PurchaseState.PURCHASED } + _isPurchased.value = purchased + Log.d(TAG, "Purchases queried: $purchased") + + // If purchased but not acknowledged, acknowledge it + purchases.forEach { purchase -> + if (purchase.purchaseState == Purchase.PurchaseState.PURCHASED && !purchase.isAcknowledged) { + acknowledgePurchase(purchase) + } + } + } + } + } + + private fun acknowledgePurchase(purchase: Purchase) { + val params = AcknowledgePurchaseParams.newBuilder() + .setPurchaseToken(purchase.purchaseToken) + .build() + billingClient.acknowledgePurchase(params) { billingResult -> + if (billingResult.responseCode == BillingClient.BillingResponseCode.OK) { + Log.d(TAG, "Purchase acknowledged") + _isPurchased.value = true + } + } + } + + override fun purchase(activity: Activity) { + val productList = listOf( + QueryProductDetailsParams.Product.newBuilder() + .setProductId(PRODUCT_ID) + .setProductType(BillingClient.ProductType.INAPP) + .build() + ) + val params = QueryProductDetailsParams.newBuilder() + .setProductList(productList) + .build() + + billingClient.queryProductDetailsAsync(params) { billingResult, productDetailsList -> + if (billingResult.responseCode == BillingClient.BillingResponseCode.OK && productDetailsList.productDetailsList.isNotEmpty()) { + val productDetails = productDetailsList.productDetailsList[0] + val flowParams = BillingFlowParams.newBuilder() + .setProductDetailsParamsList( + listOf( + BillingFlowParams.ProductDetailsParams.newBuilder() + .setProductDetails(productDetails) + .build() + ) + ) + .build() + billingClient.launchBillingFlow(activity, flowParams) + } else { + Log.e(TAG, "Failed to query product details: ${billingResult.debugMessage}") + } + } + } + + private fun handlePurchase(purchase: Purchase) { + if (purchase.purchaseState == Purchase.PurchaseState.PURCHASED) { + if (!purchase.isAcknowledged) { + acknowledgePurchase(purchase) + } else { + _isPurchased.value = true + } + } + } + + override fun refresh() { + if (billingClient.isReady) { + queryPurchases() + } else { + startConnection() + } + } +} diff --git a/app/src/main/java/com/hinnka/mycamera/billing/BillingManager.kt b/app/src/main/java/com/hinnka/mycamera/billing/BillingManager.kt new file mode 100644 index 00000000..b1420fa1 --- /dev/null +++ b/app/src/main/java/com/hinnka/mycamera/billing/BillingManager.kt @@ -0,0 +1,24 @@ +package com.hinnka.mycamera.billing + +import android.app.Activity +import kotlinx.coroutines.flow.StateFlow + +/** + * 计费管理器接口 + */ +interface BillingManager { + /** + * 是否已付费(永久会员) + */ + val isPurchased: StateFlow + + /** + * 发起购买 + */ + fun purchase(activity: Activity) + + /** + * 刷新购买状态 + */ + fun refresh() +} diff --git a/app/src/main/java/com/hinnka/mycamera/lut/CubeLutParser.kt b/app/src/main/java/com/hinnka/mycamera/lut/CubeLutParser.kt index d957ac79..c2a8f17a 100644 --- a/app/src/main/java/com/hinnka/mycamera/lut/CubeLutParser.kt +++ b/app/src/main/java/com/hinnka/mycamera/lut/CubeLutParser.kt @@ -132,7 +132,8 @@ object CubeLutParser { nameMap = mapOf("en" to name, "zh" to name), fileName = "$folder/$fileName", isBuiltIn = true, - isDefault = false + isDefault = false, + isVip = id != "standard" ) } } catch (e: Exception) { 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 99253cb2..a672e2eb 100644 --- a/app/src/main/java/com/hinnka/mycamera/lut/LutConfig.kt +++ b/app/src/main/java/com/hinnka/mycamera/lut/LutConfig.kt @@ -118,7 +118,8 @@ data class LutInfo( val nameMap: Map, // 多语言名称映射 val fileName: String, val isBuiltIn: Boolean = true, - val isDefault: Boolean = false // 是否为默认 LUT + val isDefault: Boolean = false, // 是否为默认 LUT + val isVip: Boolean = false // 是否为 VIP LUT ) { /** * 获取显示名称(优先当前系统语言) 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 b6b19b71..707e7f9c 100644 --- a/app/src/main/java/com/hinnka/mycamera/lut/LutParser.kt +++ b/app/src/main/java/com/hinnka/mycamera/lut/LutParser.kt @@ -116,7 +116,8 @@ object LutParser { nameMap = nameMap, fileName = "$folder/$path", isBuiltIn = true, - isDefault = (i == 0) // 第一个作为默认 + isDefault = (i == 0), // 第一个作为默认 + isVip = id != "standard" ) ) } diff --git a/app/src/main/java/com/hinnka/mycamera/ui/camera/CameraScreen.kt b/app/src/main/java/com/hinnka/mycamera/ui/camera/CameraScreen.kt index 51d441e0..a37f2edc 100644 --- a/app/src/main/java/com/hinnka/mycamera/ui/camera/CameraScreen.kt +++ b/app/src/main/java/com/hinnka/mycamera/ui/camera/CameraScreen.kt @@ -38,6 +38,7 @@ import com.hinnka.mycamera.camera.CameraUtils import com.hinnka.mycamera.ui.components.GalleryThumbnail import com.hinnka.mycamera.ui.components.HistogramView import com.hinnka.mycamera.ui.components.LutControlPanel +import com.hinnka.mycamera.ui.components.PaymentDialog import com.hinnka.mycamera.utils.OrientationObserver import com.hinnka.mycamera.viewmodel.CameraViewModel import com.hinnka.mycamera.viewmodel.GalleryViewModel @@ -100,6 +101,19 @@ fun CameraScreen( } val previewSize by remember(state) { mutableStateOf(CameraUtils.getFixedPreviewSize(context, state.currentCameraId, state.aspectRatio)) } + + if (viewModel.showPaymentDialog) { + val activity = context.findActivity() + PaymentDialog( + onDismiss = { viewModel.showPaymentDialog = false }, + onPurchase = { + if (activity != null) { + viewModel.purchase(activity) + } + viewModel.showPaymentDialog = false + } + ) + } Column( modifier = modifier @@ -493,3 +507,12 @@ fun CornerOverlay( drawPath(path, color) } } + +private fun android.content.Context.findActivity(): android.app.Activity? { + var context = this + while (context is android.content.ContextWrapper) { + if (context is android.app.Activity) return context + context = context.baseContext + } + return null +} 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 2aa6a265..e6425434 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 @@ -52,6 +52,7 @@ fun LutSelector( name = lut.getName(), previewBitmap = lutPreviewBitmaps[lut.id], isSelected = currentLutId == lut.id, + isVip = lut.isVip, onClick = { onLutSelected(lut.id) } ) } @@ -66,6 +67,7 @@ private fun LutItem( name: String, previewBitmap: Bitmap?, isSelected: Boolean, + isVip: Boolean, onClick: () -> Unit, isNone: Boolean = false, modifier: Modifier = Modifier @@ -150,12 +152,32 @@ private fun LutItem( ) { Icon( imageVector = Icons.Default.Check, - contentDescription = "Selected", + contentDescription = stringResource(R.string.selected), tint = Color.White, modifier = Modifier.size(24.dp) ) } } + + if (isVip) { + Box( + modifier = Modifier + .align(Alignment.TopEnd) + .background( + color = Color(0xFFFFD700), + shape = RoundedCornerShape(bottomStart = 4.dp) + ) + .padding(horizontal = 4.dp, vertical = 2.dp) + ) { + Text( + text = stringResource(R.string.billing_vip_tag), + color = Color.Black, + fontSize = 8.sp, + fontWeight = FontWeight.Bold, + lineHeight = 8.sp + ) + } + } } Spacer(modifier = Modifier.height(4.dp)) diff --git a/app/src/main/java/com/hinnka/mycamera/ui/components/PaymentDialog.kt b/app/src/main/java/com/hinnka/mycamera/ui/components/PaymentDialog.kt new file mode 100644 index 00000000..2996df1f --- /dev/null +++ b/app/src/main/java/com/hinnka/mycamera/ui/components/PaymentDialog.kt @@ -0,0 +1,170 @@ +package com.hinnka.mycamera.ui.components + +import androidx.compose.foundation.background +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Close +import androidx.compose.material.icons.filled.Star +import androidx.compose.material3.* +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.graphics.Brush +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import androidx.compose.ui.window.Dialog +import com.hinnka.mycamera.R + +@Composable +fun PaymentDialog( + onDismiss: () -> Unit, + onPurchase: () -> Unit +) { + Dialog(onDismissRequest = onDismiss) { + Card( + modifier = Modifier + .fillMaxWidth() + .padding(16.dp), + shape = RoundedCornerShape(24.dp), + colors = CardDefaults.cardColors(containerColor = Color(0xFF1A1A1A)) + ) { + Box( + modifier = Modifier + .fillMaxWidth() + .background( + Brush.verticalGradient( + listOf(Color(0xFF2C2C2C), Color(0xFF1A1A1A)) + ) + ) + ) { + Column( + modifier = Modifier + .padding(24.dp) + .fillMaxWidth(), + horizontalAlignment = Alignment.CenterHorizontally + ) { + // Close button + Box(modifier = Modifier.fillMaxWidth()) { + Icon( + imageVector = Icons.Default.Close, + contentDescription = stringResource(R.string.cancel), + tint = Color.Gray, + modifier = Modifier + .align(Alignment.TopEnd) + .clickable { onDismiss() } + .padding(4.dp) + ) + } + + // VIP Badge/Icon + Box( + modifier = Modifier + .size(64.dp) + .clip(RoundedCornerShape(16.dp)) + .background( + Brush.linearGradient( + listOf(Color(0xFFFFD700), Color(0xFFFFA000)) + ) + ), + contentAlignment = Alignment.Center + ) { + Icon( + imageVector = Icons.Default.Star, + contentDescription = null, + tint = Color.Black, + modifier = Modifier.size(32.dp) + ) + } + + Spacer(modifier = Modifier.height(16.dp)) + + Text( + text = stringResource(R.string.billing_premium_unlock_title), + color = Color.White, + fontSize = 22.sp, + fontWeight = FontWeight.Bold, + textAlign = TextAlign.Center + ) + + Spacer(modifier = Modifier.height(8.dp)) + + Text( + text = stringResource(R.string.billing_premium_unlock_description), + color = Color.LightGray, + fontSize = 14.sp, + textAlign = TextAlign.Center, + lineHeight = 20.sp + ) + + Spacer(modifier = Modifier.height(24.dp)) + + // Feature list + Column( + modifier = Modifier.fillMaxWidth(), + verticalArrangement = Arrangement.spacedBy(12.dp) + ) { + FeatureItem(stringResource(R.string.billing_feature_all_luts)) + FeatureItem(stringResource(R.string.billing_feature_support_dev)) + FeatureItem(stringResource(R.string.billing_feature_lifetime)) + } + + Spacer(modifier = Modifier.height(32.dp)) + + Button( + onClick = onPurchase, + modifier = Modifier + .fillMaxWidth() + .height(56.dp), + shape = RoundedCornerShape(28.dp), + colors = ButtonDefaults.buttonColors( + containerColor = Color(0xFFFFD700), + contentColor = Color.Black + ) + ) { + Text( + text = stringResource(R.string.billing_premium_get_access), + fontSize = 16.sp, + fontWeight = FontWeight.Bold + ) + } + + Spacer(modifier = Modifier.height(16.dp)) + + Text( + text = stringResource(R.string.billing_price_region_notice), + color = Color.DarkGray, + fontSize = 12.sp + ) + } + } + } + } +} + +@Composable +private fun FeatureItem(text: String) { + Row( + verticalAlignment = Alignment.CenterVertically, + modifier = Modifier.fillMaxWidth() + ) { + Icon( + imageVector = Icons.Default.Star, + contentDescription = null, + tint = Color(0xFFFFD700), + modifier = Modifier.size(16.dp) + ) + Spacer(modifier = Modifier.width(12.dp)) + Text( + text = text, + color = Color.White, + fontSize = 14.sp + ) + } +} diff --git a/app/src/main/java/com/hinnka/mycamera/ui/gallery/PhotoEditScreen.kt b/app/src/main/java/com/hinnka/mycamera/ui/gallery/PhotoEditScreen.kt index abf5a8e0..a6dc7792 100644 --- a/app/src/main/java/com/hinnka/mycamera/ui/gallery/PhotoEditScreen.kt +++ b/app/src/main/java/com/hinnka/mycamera/ui/gallery/PhotoEditScreen.kt @@ -40,6 +40,11 @@ import com.hinnka.mycamera.ui.theme.AccentOrange import com.hinnka.mycamera.viewmodel.GalleryViewModel import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext +import com.hinnka.mycamera.ui.components.PaymentDialog +import android.app.Activity +import android.content.Context +import android.content.ContextWrapper +import androidx.compose.ui.text.font.FontWeight /** * 照片编辑界面 @@ -59,6 +64,7 @@ fun PhotoEditScreen( val editLutIntensity = viewModel.editLutIntensity val editLutConfig = viewModel.editLutConfig val availableLuts = viewModel.availableLuts + val showPaymentDialog = viewModel.showPaymentDialog var isSaving by remember { mutableStateOf(false) } var showExportDialog by remember { mutableStateOf(false) } @@ -258,6 +264,7 @@ fun PhotoEditScreen( name = lut.getName(), previewBitmap = lutPreviews.getOrNull(index), isSelected = editLutId == lut.id, + isVip = lut.isVip, onClick = { viewModel.setEditLut(lut.id) } ) } @@ -365,6 +372,28 @@ fun PhotoEditScreen( textContentColor = Color.White ) } + + if (showPaymentDialog) { + val activity = context.findActivity() + PaymentDialog( + onDismiss = { viewModel.showPaymentDialog = false }, + onPurchase = { + if (activity != null) { + viewModel.purchase(activity) + } + viewModel.showPaymentDialog = false + } + ) + } +} + +private fun Context.findActivity(): Activity? { + var context = this + while (context is ContextWrapper) { + if (context is Activity) return context + context = context.baseContext + } + return null } /** @@ -375,6 +404,7 @@ private fun LutOption( name: String, previewBitmap: Bitmap? = null, isSelected: Boolean, + isVip: Boolean = false, onClick: () -> Unit ) { Column( @@ -411,6 +441,26 @@ private fun LutOption( fontSize = 16.sp ) } + + if (isVip) { + Box( + modifier = Modifier + .align(Alignment.TopEnd) + .background( + color = Color(0xFFFFD700), + shape = RoundedCornerShape(bottomStart = 4.dp) + ) + .padding(horizontal = 4.dp, vertical = 2.dp) + ) { + Text( + text = stringResource(R.string.billing_vip_tag), + color = Color.Black, + fontSize = 8.sp, + fontWeight = FontWeight.Bold, + lineHeight = 8.sp + ) + } + } } Spacer(modifier = Modifier.height(4.dp)) diff --git a/app/src/main/java/com/hinnka/mycamera/ui/settings/SettingsScreen.kt b/app/src/main/java/com/hinnka/mycamera/ui/settings/SettingsScreen.kt index 5915bba2..36580b00 100644 --- a/app/src/main/java/com/hinnka/mycamera/ui/settings/SettingsScreen.kt +++ b/app/src/main/java/com/hinnka/mycamera/ui/settings/SettingsScreen.kt @@ -2,6 +2,7 @@ package com.hinnka.mycamera.ui.settings import androidx.compose.foundation.* import androidx.compose.foundation.layout.* +import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.automirrored.filled.ArrowBack @@ -42,6 +43,9 @@ fun SettingsScreen( val shutterSoundEnabled by viewModel.shutterSoundEnabled.collectAsState(initial = true) val volumeKeyCapture by viewModel.volumeKeyCapture.collectAsState(initial = false) val autoSaveAfterCapture by viewModel.autoSaveAfterCapture.collectAsState(initial = true) + val isPurchased by viewModel.isPurchased.collectAsState() + + val context = androidx.compose.ui.platform.LocalContext.current val backgroundColor = Color(0xFF434A5D) @@ -87,6 +91,18 @@ fun SettingsScreen( ) { Spacer(modifier = Modifier.height(8.dp)) + if (!isPurchased) { + PremiumCard( + onClick = { + val activity = context.findActivity() + if (activity != null) { + viewModel.purchase(activity) + } + } + ) + Spacer(modifier = Modifier.height(24.dp)) + } + // 画面比例设置 SettingsSection(title = stringResource(R.string.settings_section_capture)) { AspectRatioSetting( @@ -482,3 +498,66 @@ private fun FrameItem( ) } } +@Composable +private fun PremiumCard( + onClick: () -> Unit, + modifier: Modifier = Modifier +) { + Card( + modifier = modifier + .fillMaxWidth() + .clip(RoundedCornerShape(16.dp)) + .clickable(onClick = onClick), + colors = CardDefaults.cardColors(containerColor = Color.Transparent) + ) { + Box( + modifier = Modifier + .fillMaxWidth() + .background( + androidx.compose.ui.graphics.Brush.linearGradient( + listOf(Color(0xFFFFD700), Color(0xFFFFA000)) + ) + ) + .padding(20.dp) + ) { + Row( + modifier = Modifier.fillMaxWidth(), + verticalAlignment = Alignment.CenterVertically + ) { + Column(modifier = Modifier.weight(1f)) { + Text( + text = stringResource(R.string.settings_premium_title), + color = Color.Black, + fontSize = 18.sp, + fontWeight = FontWeight.Bold + ) + Spacer(modifier = Modifier.height(4.dp)) + Text( + text = stringResource(R.string.settings_premium_description), + color = Color.Black.copy(alpha = 0.7f), + fontSize = 13.sp + ) + } + + Icon( + imageVector = Icons.Default.Check, // Reuse an icon or add Star + contentDescription = null, + tint = Color.Black, + modifier = Modifier + .size(40.dp) + .background(Color.Black.copy(alpha = 0.1f), CircleShape) + .padding(8.dp) + ) + } + } + } +} + +private fun android.content.Context.findActivity(): android.app.Activity? { + var context = this + while (context is android.content.ContextWrapper) { + if (context is android.app.Activity) return context + context = context.baseContext + } + return null +} diff --git a/app/src/main/java/com/hinnka/mycamera/viewmodel/CameraViewModel.kt b/app/src/main/java/com/hinnka/mycamera/viewmodel/CameraViewModel.kt index b8586c70..7dbf2bb0 100644 --- a/app/src/main/java/com/hinnka/mycamera/viewmodel/CameraViewModel.kt +++ b/app/src/main/java/com/hinnka/mycamera/viewmodel/CameraViewModel.kt @@ -60,6 +60,10 @@ class CameraViewModel(application: Application) : AndroidViewModel(application) private val lutManager = LutManager(application) private val lutImageProcessor = LutImageProcessor() + // 计费管理器 + private val billingManager = com.hinnka.mycamera.billing.BillingManagerImpl(application) + val isPurchased = billingManager.isPurchased + // 边框管理器 private val frameManager = FrameManager(application) private val frameRenderer = FrameRenderer(application) @@ -108,6 +112,9 @@ class CameraViewModel(application: Application) : AndroidViewModel(application) private set var zoomRatioByMain by mutableFloatStateOf(1f) + + // 付费弹窗状态 + var showPaymentDialog by mutableStateOf(false) // 新增设置项 StateFlow val showLevelIndicator: Flow = userPreferencesRepository.userPreferences.map { it.showLevelIndicator } @@ -223,6 +230,13 @@ class CameraViewModel(application: Application) : AndroidViewModel(application) fun capture() { val timerSeconds = state.value.timerSeconds + // 检查 VIP 权限 + val currentLut = getLutInfo(currentLutId ?: "") + if (currentLut?.isVip == true && !isPurchased.value) { + showPaymentDialog = true + return + } + if (timerSeconds > 0) { // 延时拍摄:开始倒计时 viewModelScope.launch { @@ -366,6 +380,15 @@ class CameraViewModel(application: Application) : AndroidViewModel(application) cameraController.setAwbTemperature(kelvin) } + // ==================== 计费相关方法 ==================== + + /** + * 发起购买 + */ + fun purchase(activity: android.app.Activity) { + billingManager.purchase(activity) + } + // ==================== LUT 相关方法 ==================== /** 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 d9a1b68b..555383f2 100644 --- a/app/src/main/java/com/hinnka/mycamera/viewmodel/GalleryViewModel.kt +++ b/app/src/main/java/com/hinnka/mycamera/viewmodel/GalleryViewModel.kt @@ -51,6 +51,13 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application) private val frameRenderer = FrameRenderer(application) private val photoProcessor = PhotoProcessor(lutManager, lutImageProcessor, frameManager, frameRenderer) + // 计费管理器 + private val billingManager = com.hinnka.mycamera.billing.BillingManagerImpl(application) + val isPurchased = billingManager.isPurchased + + // 付费弹窗状态 + var showPaymentDialog by mutableStateOf(false) + // 照片列表 private val _photos = MutableStateFlow>(emptyList()) val photos: StateFlow> = _photos.asStateFlow() @@ -636,6 +643,14 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application) * 保存编辑(只更新元数据,不修改原图) */ fun saveEditMetadata(photo: PhotoData, onComplete: (Boolean) -> Unit = {}) { + // 检查 VIP 权限 + val currentLut = availableLuts.find { it.id == editLutId } + if (currentLut?.isVip == true && !isPurchased.value) { + showPaymentDialog = true + onComplete(false) + return + } + viewModelScope.launch { try { val context = getApplication() @@ -681,6 +696,13 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application) * 保存编辑(导出烘焙后的图片) */ fun saveEdit(photo: PhotoData, onComplete: (Boolean) -> Unit = {}) { + // 检查 VIP 权限 + val currentLut = availableLuts.find { it.id == editLutId } + if (currentLut?.isVip == true && !isPurchased.value) { + showPaymentDialog = true + return + } + val metadata = (photo.metadata ?: PhotoMetadata()).copy( lutId = editLutId, lutIntensity = editLutIntensity, @@ -827,4 +849,18 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application) lutImageProcessor.release() lutManager.clearCache() } + + /** + * 发起购买 + */ + fun purchase(activity: android.app.Activity) { + billingManager.purchase(activity) + } + + /** + * 刷新购买状态 + */ + fun refreshPurchases() { + billingManager.refresh() + } } diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 8b84dc17..eb6ada24 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -102,4 +102,17 @@ 高 滤镜面板 切换显示模式 + + + VIP + 解锁全部 VIP 滤镜 + 一次支付,永久使用目前及未来增加的所有高级 LUT 滤镜和 Pro 功能。 + 访问所有专业级 LUT + 支持独立软件开发 + 一次购买,永久使用 + 获取 Pro 权益 + 具体价格以所在地区为准 + PhotonCamera Pro + 解锁全部高级滤镜并支持我们的开发工作 + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a98a2cd8..ca907894 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -102,4 +102,16 @@ High Filters Toggle Display Mode + + + VIP + Unlock All VIP Filters + One-time payment for lifetime access to all premium LUT filters and future pro features. + Access all specialized LUTs + Support independent development + One-time purchase, lifetime use + Get Premium Access + Price varies by region + PhotonCamera Pro + Unlock all premium filters and support us. \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 42a732b6..f0212a93 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,21 +1,24 @@ [versions] -agp = "8.12.0" -kotlin = "2.0.21" +agp = "8.12.3" +kotlin = "2.3.0" coreKtx = "1.17.0" junit = "4.13.2" junitVersion = "1.3.0" espressoCore = "3.7.0" lifecycleRuntimeKtx = "2.10.0" -activityCompose = "1.11.0" -composeBom = "2024.09.00" +activityCompose = "1.12.2" +composeBom = "2025.12.01" lifecycleViewmodelCompose = "2.10.0" -materialIconsExtended = "1.7.0" -coil = "2.5.0" -navigationCompose = "2.8.5" -exifinterface = "1.4.1" - +materialIconsExtended = "1.7.8" +coil = "2.7.0" +navigationCompose = "2.9.6" +exifinterface = "1.4.2" +billing = "8.3.0" [libraries] +google-billing = { group = "com.android.billingclient", name = "billing", version.ref = "billing" } +google-billing-ktx = { group = "com.android.billingclient", name = "billing-ktx", version.ref = "billing" } + androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" } junit = { group = "junit", name = "junit", version.ref = "junit" } androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }