feat: google play billing
This commit is contained in:
1 parent
bbfeaece67
commit
68c547b912
17 files changed
+641
-18
No files matched your search
@@ -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)
|
||||
|
||||
@@ -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<Boolean> = _isPurchased.asStateFlow()
|
||||
|
||||
override fun purchase(activity: Activity) {
|
||||
// China version might use other billing methods or be free
|
||||
}
|
||||
|
||||
override fun refresh() {
|
||||
}
|
||||
}
|
||||
@@ -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<Boolean> = _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()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.hinnka.mycamera.billing
|
||||
|
||||
import android.app.Activity
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
||||
/**
|
||||
* 计费管理器接口
|
||||
*/
|
||||
interface BillingManager {
|
||||
/**
|
||||
* 是否已付费(永久会员)
|
||||
*/
|
||||
val isPurchased: StateFlow<Boolean>
|
||||
|
||||
/**
|
||||
* 发起购买
|
||||
*/
|
||||
fun purchase(activity: Activity)
|
||||
|
||||
/**
|
||||
* 刷新购买状态
|
||||
*/
|
||||
fun refresh()
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
@@ -118,7 +118,8 @@ data class LutInfo(
|
||||
val nameMap: Map<String, String>, // 多语言名称映射
|
||||
val fileName: String,
|
||||
val isBuiltIn: Boolean = true,
|
||||
val isDefault: Boolean = false // 是否为默认 LUT
|
||||
val isDefault: Boolean = false, // 是否为默认 LUT
|
||||
val isVip: Boolean = false // 是否为 VIP LUT
|
||||
) {
|
||||
/**
|
||||
* 获取显示名称(优先当前系统语言)
|
||||
|
||||
@@ -116,7 +116,8 @@ object LutParser {
|
||||
nameMap = nameMap,
|
||||
fileName = "$folder/$path",
|
||||
isBuiltIn = true,
|
||||
isDefault = (i == 0) // 第一个作为默认
|
||||
isDefault = (i == 0), // 第一个作为默认
|
||||
isVip = id != "standard"
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -101,6 +102,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
|
||||
.fillMaxSize()
|
||||
@@ -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
|
||||
}
|
||||
@@ -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))
|
||||
|
||||
@@ -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
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -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))
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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)
|
||||
@@ -109,6 +113,9 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
|
||||
var zoomRatioByMain by mutableFloatStateOf(1f)
|
||||
|
||||
// 付费弹窗状态
|
||||
var showPaymentDialog by mutableStateOf(false)
|
||||
|
||||
// 新增设置项 StateFlow
|
||||
val showLevelIndicator: Flow<Boolean> = userPreferencesRepository.userPreferences.map { it.showLevelIndicator }
|
||||
val shutterSoundEnabled: Flow<Boolean> = userPreferencesRepository.userPreferences.map { it.shutterSoundEnabled }
|
||||
@@ -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 相关方法 ====================
|
||||
|
||||
/**
|
||||
|
||||
@@ -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<List<PhotoData>>(emptyList())
|
||||
val photos: StateFlow<List<PhotoData>> = _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<Application>()
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
@@ -102,4 +102,17 @@
|
||||
<string name="lut_intensity_high">高</string>
|
||||
<string name="filters_panel">滤镜面板</string>
|
||||
<string name="toggle_display_mode">切换显示模式</string>
|
||||
|
||||
<!-- Billing & Premium -->
|
||||
<string name="billing_vip_tag">VIP</string>
|
||||
<string name="billing_premium_unlock_title">解锁全部 VIP 滤镜</string>
|
||||
<string name="billing_premium_unlock_description">一次支付,永久使用目前及未来增加的所有高级 LUT 滤镜和 Pro 功能。</string>
|
||||
<string name="billing_feature_all_luts">访问所有专业级 LUT</string>
|
||||
<string name="billing_feature_support_dev">支持独立软件开发</string>
|
||||
<string name="billing_feature_lifetime">一次购买,永久使用</string>
|
||||
<string name="billing_premium_get_access">获取 Pro 权益</string>
|
||||
<string name="billing_price_region_notice">具体价格以所在地区为准</string>
|
||||
<string name="settings_premium_title">PhotonCamera Pro</string>
|
||||
<string name="settings_premium_description">解锁全部高级滤镜并支持我们的开发工作</string>
|
||||
</resources>
|
||||
|
||||
@@ -102,4 +102,16 @@
|
||||
<string name="lut_intensity_high">High</string>
|
||||
<string name="filters_panel">Filters</string>
|
||||
<string name="toggle_display_mode">Toggle Display Mode</string>
|
||||
|
||||
<!-- Billing & Premium -->
|
||||
<string name="billing_vip_tag">VIP</string>
|
||||
<string name="billing_premium_unlock_title">Unlock All VIP Filters</string>
|
||||
<string name="billing_premium_unlock_description">One-time payment for lifetime access to all premium LUT filters and future pro features.</string>
|
||||
<string name="billing_feature_all_luts">Access all specialized LUTs</string>
|
||||
<string name="billing_feature_support_dev">Support independent development</string>
|
||||
<string name="billing_feature_lifetime">One-time purchase, lifetime use</string>
|
||||
<string name="billing_premium_get_access">Get Premium Access</string>
|
||||
<string name="billing_price_region_notice">Price varies by region</string>
|
||||
<string name="settings_premium_title">PhotonCamera Pro</string>
|
||||
<string name="settings_premium_description">Unlock all premium filters and support us.</string>
|
||||
</resources>
|
||||
@@ -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" }
|
||||
|
||||
Reference in new issue
Block a user