Shared Kotlin Features: - Complete subscription data models with kotlinx.serialization - SubscriptionApi client for all backend endpoints - SubscriptionCache for storing subscription state - SubscriptionHelper utility for checking user limits Models (Subscription.kt): - SubscriptionStatus (tier, usage, limits, master toggle flag) - UsageStats (current usage counts) - TierLimits (tier-specific limits, null = unlimited) - UpgradeTriggerData (configurable prompts) - FeatureBenefit (Free vs Pro comparison) - Promotion (seasonal campaigns) - ReceiptVerificationRequest/Response - PurchaseVerificationRequest/Response API Client (SubscriptionApi.kt): - getSubscriptionStatus() - fetch user subscription - getUpgradeTriggers() - fetch upgrade prompts - getFeatureBenefits() - fetch tier comparison - getActivePromotions() - fetch active promotions - verifyIOSReceipt() - verify Apple purchase - verifyAndroidPurchase() - verify Google purchase Cache (SubscriptionCache.kt): - Stores currentSubscription in mutableState - Stores upgradeTriggers, featureBenefits, promotions - Reactive state for UI observation - clear() method for logout Helper (SubscriptionHelper.kt): - canAddProperty() - check property limit - canAddTask() - check task limit - shouldShowUpgradePromptForContractors() - check if should show upgrade screen - shouldShowUpgradePromptForDocuments() - check if should show upgrade screen - Respects master toggle (limitationsEnabled) - Returns UsageCheck(allowed, triggerKey) Next: iOS StoreKit implementation (Phase 5) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
38 lines
1.2 KiB
Kotlin
38 lines
1.2 KiB
Kotlin
package com.example.mycrib.cache
|
|
|
|
import androidx.compose.runtime.mutableStateOf
|
|
import com.example.mycrib.models.FeatureBenefit
|
|
import com.example.mycrib.models.Promotion
|
|
import com.example.mycrib.models.SubscriptionStatus
|
|
import com.example.mycrib.models.UpgradeTriggerData
|
|
|
|
object SubscriptionCache {
|
|
val currentSubscription = mutableStateOf<SubscriptionStatus?>(null)
|
|
val upgradeTriggers = mutableStateOf<Map<String, UpgradeTriggerData>>(emptyMap())
|
|
val featureBenefits = mutableStateOf<List<FeatureBenefit>>(emptyList())
|
|
val promotions = mutableStateOf<List<Promotion>>(emptyList())
|
|
|
|
fun updateSubscriptionStatus(subscription: SubscriptionStatus) {
|
|
currentSubscription.value = subscription
|
|
}
|
|
|
|
fun updateUpgradeTriggers(triggers: Map<String, UpgradeTriggerData>) {
|
|
upgradeTriggers.value = triggers
|
|
}
|
|
|
|
fun updateFeatureBenefits(benefits: List<FeatureBenefit>) {
|
|
featureBenefits.value = benefits
|
|
}
|
|
|
|
fun updatePromotions(promos: List<Promotion>) {
|
|
promotions.value = promos
|
|
}
|
|
|
|
fun clear() {
|
|
currentSubscription.value = null
|
|
upgradeTriggers.value = emptyMap()
|
|
featureBenefits.value = emptyList()
|
|
promotions.value = emptyList()
|
|
}
|
|
}
|