-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[move]
Paywalls
: created LoadingPaywallView
- Loading branch information
Showing
4 changed files
with
149 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
...venuecatui/src/main/kotlin/com/revenuecat/purchases/ui/revenuecatui/LoadingPaywallView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package com.revenuecat.purchases.ui.revenuecatui | ||
|
||
import android.content.Context | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.lifecycle.ViewModel | ||
import com.revenuecat.purchases.Offering | ||
import com.revenuecat.purchases.Package | ||
import com.revenuecat.purchases.PackageType | ||
import com.revenuecat.purchases.models.Period | ||
import com.revenuecat.purchases.models.Price | ||
import com.revenuecat.purchases.paywalls.PaywallData | ||
import com.revenuecat.purchases.ui.revenuecatui.data.MockApplicationContext | ||
import com.revenuecat.purchases.ui.revenuecatui.data.PaywallViewModel | ||
import com.revenuecat.purchases.ui.revenuecatui.data.PaywallViewState | ||
import com.revenuecat.purchases.ui.revenuecatui.data.TestStoreProduct | ||
import com.revenuecat.purchases.ui.revenuecatui.data.processed.TemplateConfiguration | ||
import com.revenuecat.purchases.ui.revenuecatui.data.processed.VariableDataProvider | ||
import com.revenuecat.purchases.ui.revenuecatui.helpers.toAndroidContext | ||
import com.revenuecat.purchases.ui.revenuecatui.helpers.toPaywallViewState | ||
import com.revenuecat.purchases.ui.revenuecatui.templates.Template2 | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import java.net.URL | ||
|
||
@Composable | ||
internal fun LoadingPaywallView(mode: PaywallViewMode) { | ||
val provider = VariableDataProvider(LocalContext.current.applicationContext.toAndroidContext()) | ||
val offering = LoadingPaywallConstants.offering | ||
|
||
Template2( | ||
state = offering.toPaywallViewState( | ||
provider, | ||
LoadingPaywallConstants.paywallData!!, | ||
mode | ||
), | ||
viewModel = LoadingViewModel(mode, offering) | ||
) | ||
} | ||
|
||
private object LoadingPaywallConstants { | ||
private const val offeringIdentifier = "loading_offering" | ||
|
||
// TODO: use .createDefault() | ||
val paywallData: PaywallData? = null | ||
|
||
val offering = Offering( | ||
identifier = this.offeringIdentifier, | ||
serverDescription = "Loading paywall", | ||
metadata = emptyMap(), | ||
availablePackages = listOf( | ||
Package( | ||
identifier = "weekly", | ||
packageType = PackageType.WEEKLY, | ||
offering = this.offeringIdentifier, | ||
product = TestStoreProduct( | ||
id = "com.revenuecat.weekly", | ||
title = "Weekly", | ||
price = Price(formatted = "$1.99", currencyCode = "USD", amountMicros = 1_990_000), | ||
description = "Weekly", | ||
period = Period(value = 1, unit = Period.Unit.WEEK, iso8601 = "P1W"), | ||
) | ||
), | ||
Package( | ||
identifier = "monthly", | ||
packageType = PackageType.MONTHLY, | ||
offering = this.offeringIdentifier, | ||
product = TestStoreProduct( | ||
id = "com.revenuecat.monthly", | ||
title = "Monthly", | ||
price = Price(formatted = "$5.99", currencyCode = "USD", amountMicros = 5_990_000), | ||
description = "Monthly", | ||
period = Period(value = 1, unit = Period.Unit.MONTH, iso8601 = "P1M"), | ||
) | ||
), | ||
Package( | ||
identifier = "annual", | ||
packageType = PackageType.ANNUAL, | ||
offering = this.offeringIdentifier, | ||
product = TestStoreProduct( | ||
id = "com.revenuecat.annual", | ||
title = "Annual", | ||
price = Price(formatted = "$15.99", currencyCode = "USD", amountMicros = 5_990_000), | ||
description = "Annual", | ||
period = Period(value = 1, unit = Period.Unit.YEAR, iso8601 = "P1Y"), | ||
) | ||
), | ||
), | ||
paywall = paywallData | ||
) | ||
} | ||
|
||
private class LoadingViewModel( | ||
mode: PaywallViewMode = PaywallViewMode.default, | ||
offering: Offering, | ||
) : ViewModel(), PaywallViewModel { | ||
override val state: StateFlow<PaywallViewState> | ||
get() = _state.asStateFlow() | ||
private val _state = | ||
MutableStateFlow(offering.toPaywallViewState(VariableDataProvider(MockApplicationContext()), mode)) | ||
|
||
override fun refreshState() = Unit | ||
|
||
override fun selectPackage(packageToSelect: TemplateConfiguration.PackageInfo) { | ||
error("Not supported") | ||
} | ||
|
||
override fun purchaseSelectedPackage(context: Context) { | ||
error("Can't purchase loading view model") | ||
} | ||
|
||
override fun restorePurchases() { | ||
error("Can't restore purchases") | ||
} | ||
|
||
override fun openURL(url: URL, context: Context) { | ||
error("Can't open URL") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters