Skip to content

Commit

Permalink
Implement dev version of SubscriptionDev
Browse files Browse the repository at this point in the history
  • Loading branch information
abdrasulov committed Feb 17, 2025
1 parent 87487eb commit b877ac5
Showing 1 changed file with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import io.horizontalsystems.subscriptions.core.Subscription
import io.horizontalsystems.subscriptions.core.SubscriptionService
import io.horizontalsystems.subscriptions.core.UserSubscription
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.update
import java.util.UUID

class SubscriptionServiceDev(private val context: Context) : SubscriptionService {
Expand All @@ -19,16 +20,31 @@ class SubscriptionServiceDev(private val context: Context) : SubscriptionService
}

override var predefinedSubscriptions: List<Subscription> = listOf()
override val activeSubscriptionStateFlow = MutableStateFlow(null)
set(value) {
field = value

activeSubscriptionStateFlow.update {
getActiveSubscriptions().firstOrNull()
}
}
override val activeSubscriptionStateFlow = MutableStateFlow(getActiveSubscriptions().firstOrNull())

override fun launchManageSubscriptionScreen(context: Context) {
setActiveSubscription(null)
}

override suspend fun onResume() = Unit

override fun isActionAllowed(paidAction: IPaidAction): Boolean {
return prefs.getString(KEY_ACTIVE_SUBSCRIPTION, null) != null
}

private fun setActiveSubscription(subscription: String?) {
prefs.edit().putString(KEY_ACTIVE_SUBSCRIPTION, subscription).commit()
private fun setActiveSubscription(subscriptionId: String?) {
prefs.edit().putString(KEY_ACTIVE_SUBSCRIPTION, subscriptionId).apply()

activeSubscriptionStateFlow.update {
getActiveSubscriptions().firstOrNull()
}
}

override fun getBasePlans(subscriptionId: String): List<BasePlan> =
Expand Down

0 comments on commit b877ac5

Please sign in to comment.