Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Paywalls V2] Adds support to PaywallsTester #1978

Merged
merged 13 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
@file:OptIn(InternalRevenueCatAPI::class)

package com.revenuecat.paywallstester

import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import com.revenuecat.purchases.InternalRevenueCatAPI
import com.revenuecat.purchases.Offering
import com.revenuecat.purchases.Package
import com.revenuecat.purchases.PackageType
Expand All @@ -8,6 +13,30 @@ import com.revenuecat.purchases.models.Price
import com.revenuecat.purchases.models.TestStoreProduct
import com.revenuecat.purchases.paywalls.PaywallColor
import com.revenuecat.purchases.paywalls.PaywallData
import com.revenuecat.purchases.paywalls.components.StackComponent
import com.revenuecat.purchases.paywalls.components.TextComponent
import com.revenuecat.purchases.paywalls.components.common.Background
import com.revenuecat.purchases.paywalls.components.common.ComponentsConfig
import com.revenuecat.purchases.paywalls.components.common.LocaleId
import com.revenuecat.purchases.paywalls.components.common.LocalizationData
import com.revenuecat.purchases.paywalls.components.common.LocalizationKey
import com.revenuecat.purchases.paywalls.components.common.PaywallComponentsConfig
import com.revenuecat.purchases.paywalls.components.common.PaywallComponentsData
import com.revenuecat.purchases.paywalls.components.properties.ColorInfo
import com.revenuecat.purchases.paywalls.components.properties.ColorScheme
import com.revenuecat.purchases.paywalls.components.properties.Dimension.Vertical
import com.revenuecat.purchases.paywalls.components.properties.Dimension.ZLayer
import com.revenuecat.purchases.paywalls.components.properties.FlexDistribution.END
import com.revenuecat.purchases.paywalls.components.properties.FontSize
import com.revenuecat.purchases.paywalls.components.properties.FontWeight
import com.revenuecat.purchases.paywalls.components.properties.HorizontalAlignment.LEADING
import com.revenuecat.purchases.paywalls.components.properties.Padding
import com.revenuecat.purchases.paywalls.components.properties.Shape
import com.revenuecat.purchases.paywalls.components.properties.Size
import com.revenuecat.purchases.paywalls.components.properties.SizeConstraint.Fill
import com.revenuecat.purchases.paywalls.components.properties.SizeConstraint.Fit
import com.revenuecat.purchases.paywalls.components.properties.TwoDimensionalAlignment
import com.revenuecat.purchases.paywalls.components.properties.TwoDimensionalAlignment.BOTTOM
import java.net.URL

class SamplePaywallsLoader {
Expand All @@ -17,23 +46,31 @@ class SamplePaywallsLoader {
SamplePaywalls.offeringIdentifier,
emptyMap(),
SamplePaywalls.packages,
paywall = paywallForTemplate(template),
paywall = (paywallForTemplate(template) as? SampleData.Legacy)?.data,
paywallComponents = (paywallForTemplate(template) as? SampleData.Components)?.data,
)
}

private fun paywallForTemplate(template: SamplePaywalls.SampleTemplate): PaywallData {
private fun paywallForTemplate(template: SamplePaywalls.SampleTemplate): SampleData {
return when (template) {
SamplePaywalls.SampleTemplate.TEMPLATE_1 -> SamplePaywalls.template1()
SamplePaywalls.SampleTemplate.TEMPLATE_2 -> SamplePaywalls.template2()
SamplePaywalls.SampleTemplate.TEMPLATE_3 -> SamplePaywalls.template3()
SamplePaywalls.SampleTemplate.TEMPLATE_4 -> SamplePaywalls.template4()
SamplePaywalls.SampleTemplate.TEMPLATE_5 -> SamplePaywalls.template5()
SamplePaywalls.SampleTemplate.TEMPLATE_7 -> SamplePaywalls.template7()
SamplePaywalls.SampleTemplate.COMPONENTS_BLESS -> SamplePaywalls.bless()
SamplePaywalls.SampleTemplate.UNRECOGNIZED_TEMPLATE -> SamplePaywalls.unrecognizedTemplate()
}
}
}

sealed interface SampleData {
data class Legacy(val data: PaywallData) : SampleData

data class Components(val data: PaywallComponentsData) : SampleData
}

@SuppressWarnings("LongMethod", "LargeClass")
object SamplePaywalls {

Expand All @@ -44,6 +81,7 @@ object SamplePaywalls {
TEMPLATE_4("#4: Horizontal packages"),
TEMPLATE_5("#5: Minimalist with small banner"),
TEMPLATE_7("#7: Multi-tier"),
COMPONENTS_BLESS("#8: Components - bless."),
UNRECOGNIZED_TEMPLATE("Default template"),
}

Expand Down Expand Up @@ -186,8 +224,8 @@ object SamplePaywalls {
lifetimePackage,
)

fun template1(): PaywallData {
return PaywallData(
fun template1(): SampleData.Legacy = SampleData.Legacy(
data = PaywallData(
templateName = "1",
config = PaywallData.Configuration(
images = images,
Expand Down Expand Up @@ -224,11 +262,11 @@ object SamplePaywalls {
),
),
zeroDecimalPlaceCountries = zeroDecimalPlaceCountries,
)
}
),
)

fun template2(): PaywallData {
return PaywallData(
fun template2(): SampleData.Legacy = SampleData.Legacy(
data = PaywallData(
templateName = "2",
config = PaywallData.Configuration(
images = images,
Expand Down Expand Up @@ -279,11 +317,11 @@ object SamplePaywalls {
),
),
zeroDecimalPlaceCountries = zeroDecimalPlaceCountries,
)
}
),
)

fun template3(): PaywallData {
return PaywallData(
fun template3(): SampleData.Legacy = SampleData.Legacy(
data = PaywallData(
templateName = "3",
config = PaywallData.Configuration(
images = images,
Expand Down Expand Up @@ -343,11 +381,11 @@ object SamplePaywalls {
),
),
zeroDecimalPlaceCountries = zeroDecimalPlaceCountries,
)
}
),
)

fun template4(): PaywallData {
return PaywallData(
fun template4(): SampleData.Legacy = SampleData.Legacy(
data = PaywallData(
templateName = "4",
config = PaywallData.Configuration(
images = PaywallData.Configuration.Images(
Expand Down Expand Up @@ -385,11 +423,11 @@ object SamplePaywalls {
),
),
zeroDecimalPlaceCountries = zeroDecimalPlaceCountries,
)
}
),
)

fun template5(): PaywallData {
return PaywallData(
fun template5(): SampleData.Legacy = SampleData.Legacy(
data = PaywallData(
templateName = "5",
config = PaywallData.Configuration(
packageIds = listOf(
Expand Down Expand Up @@ -448,11 +486,11 @@ object SamplePaywalls {
),
),
zeroDecimalPlaceCountries = zeroDecimalPlaceCountries,
)
}
),
)

fun template7(): PaywallData {
return PaywallData(
fun template7(): SampleData.Legacy = SampleData.Legacy(
data = PaywallData(
templateName = "7",
config = PaywallData.Configuration(
packageIds = emptyList(),
Expand Down Expand Up @@ -675,18 +713,180 @@ object SamplePaywalls {
),
),
zeroDecimalPlaceCountries = zeroDecimalPlaceCountries,
)
}
),
)

fun unrecognizedTemplate(): PaywallData {
return PaywallData(
fun unrecognizedTemplate(): SampleData.Legacy = SampleData.Legacy(
data = PaywallData(
templateName = "unrecognized",
config = template4().config,
config = template4().data.config,
assetBaseURL = paywallAssetBaseURL,
localization = mapOf(
"en_US" to template4().localizedConfiguration.second,
"en_US" to template4().data.localizedConfiguration.second,
),
zeroDecimalPlaceCountries = zeroDecimalPlaceCountries,
),
)

/**
* [Inspiration](https://mobbin.com/screens/fd110266-4c8b-4673-9b51-48de70a4ae51)
*/
fun bless(): SampleData.Components {
val textColor = ColorScheme(
light = ColorInfo.Hex(Color.Black.toArgb()),
dark = ColorInfo.Hex(Color.White.toArgb()),
)
val backgroundColor = ColorScheme(
light = ColorInfo.Hex(Color.White.toArgb()),
dark = ColorInfo.Hex(Color.Black.toArgb()),
)

return SampleData.Components(
data = PaywallComponentsData(
templateName = "template",
assetBaseURL = URL("https://assets.pawwalls.com"),
componentsConfig = ComponentsConfig(
base = PaywallComponentsConfig(
stack = StackComponent(
components = listOf(
StackComponent(
components = emptyList(),
dimension = ZLayer(alignment = TwoDimensionalAlignment.CENTER),
size = Size(width = Fill, height = Fill),
backgroundColor = ColorScheme(
light = ColorInfo.Gradient.Linear(
degrees = 60f,
points = listOf(
ColorInfo.Gradient.Point(
color = Color(red = 0xFF, green = 0xFF, blue = 0xFF, alpha = 0xFF)
.toArgb(),
percent = 0.4f,
),
ColorInfo.Gradient.Point(
color = Color(red = 5, green = 124, blue = 91).toArgb(),
percent = 1f,
),
),
),
),
),
StackComponent(
components = listOf(
TextComponent(
text = LocalizationKey("title"),
color = textColor,
fontWeight = FontWeight.SEMI_BOLD,
fontSize = FontSize.HEADING_L,
horizontalAlignment = LEADING,
size = Size(width = Fill, height = Fit),
margin = Padding(top = 0.0, bottom = 40.0, leading = 0.0, trailing = 0.0),
),
TextComponent(
text = LocalizationKey("feature-1"),
color = textColor,
horizontalAlignment = LEADING,
size = Size(width = Fill, height = Fit),
margin = Padding(top = 8.0, bottom = 8.0, leading = 0.0, trailing = 0.0),
),
TextComponent(
text = LocalizationKey("feature-2"),
color = textColor,
horizontalAlignment = LEADING,
size = Size(width = Fill, height = Fit),
margin = Padding(top = 8.0, bottom = 8.0, leading = 0.0, trailing = 0.0),
),
TextComponent(
text = LocalizationKey("feature-3"),
color = textColor,
horizontalAlignment = LEADING,
size = Size(width = Fill, height = Fit),
margin = Padding(top = 8.0, bottom = 8.0, leading = 0.0, trailing = 0.0),
),
TextComponent(
text = LocalizationKey("feature-4"),
color = textColor,
horizontalAlignment = LEADING,
size = Size(width = Fill, height = Fit),
margin = Padding(top = 8.0, bottom = 8.0, leading = 0.0, trailing = 0.0),
),
TextComponent(
text = LocalizationKey("feature-5"),
color = textColor,
horizontalAlignment = LEADING,
size = Size(width = Fill, height = Fit),
margin = Padding(top = 8.0, bottom = 8.0, leading = 0.0, trailing = 0.0),
),
TextComponent(
text = LocalizationKey("feature-6"),
color = textColor,
horizontalAlignment = LEADING,
size = Size(width = Fill, height = Fit),
margin = Padding(top = 8.0, bottom = 8.0, leading = 0.0, trailing = 0.0),
),
TextComponent(
text = LocalizationKey("offer"),
color = textColor,
horizontalAlignment = LEADING,
size = Size(width = Fill, height = Fit),
margin = Padding(top = 48.0, bottom = 8.0, leading = 0.0, trailing = 0.0),
),
StackComponent(
components = listOf(
TextComponent(
text = LocalizationKey("cta"),
color = ColorScheme(
light = ColorInfo.Hex(Color.White.toArgb()),
),
fontWeight = FontWeight.BOLD,
),
),
dimension = ZLayer(alignment = TwoDimensionalAlignment.CENTER),
size = Size(width = Fit, height = Fit),
backgroundColor = ColorScheme(
light = ColorInfo.Hex(Color(red = 5, green = 124, blue = 91).toArgb()),
),
padding = Padding(top = 8.0, bottom = 8.0, leading = 32.0, trailing = 32.0),
margin = Padding(top = 8.0, bottom = 8.0, leading = 0.0, trailing = 0.0),
shape = Shape.Pill,
),
TextComponent(
text = LocalizationKey("terms"),
color = textColor,
),
),
dimension = Vertical(alignment = LEADING, distribution = END),
size = Size(width = Fill, height = Fill),
padding = Padding(top = 16.0, bottom = 16.0, leading = 32.0, trailing = 32.0),
),
),
dimension = ZLayer(alignment = BOTTOM),
size = Size(width = Fill, height = Fill),
backgroundColor = backgroundColor,
),
background = Background.Color(backgroundColor),
stickyFooter = null,
),
),
componentsLocalizations = mapOf(
LocaleId("en_US") to mapOf(
LocalizationKey("title") to LocalizationData.Text("Unlock bless."),
LocalizationKey("feature-1") to LocalizationData.Text("✓ Enjoy a 7 day trial"),
LocalizationKey("feature-2") to LocalizationData.Text("✓ Change currencies"),
LocalizationKey("feature-3") to LocalizationData.Text("✓ Access more trend charts"),
LocalizationKey("feature-4") to LocalizationData.Text("✓ Create custom categories"),
LocalizationKey("feature-5") to LocalizationData.Text("✓ Get a special premium icon"),
LocalizationKey("feature-6") to LocalizationData.Text(
"✓ Receive our love and gratitude for your support",
),
LocalizationKey("offer") to LocalizationData.Text(
"Try 7 days free, then $19.98/year. Cancel anytime.",
),
LocalizationKey("cta") to LocalizationData.Text("Continue"),
LocalizationKey("terms") to LocalizationData.Text("Privacy & Terms"),
),
),
defaultLocaleIdentifier = LocaleId("en_US"),
),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.DialogProperties
import androidx.lifecycle.viewmodel.compose.viewModel
import com.revenuecat.paywallstester.MainActivity
import com.revenuecat.purchases.InternalRevenueCatAPI
import com.revenuecat.purchases.Offering
import com.revenuecat.purchases.Offerings
import com.revenuecat.purchases.Purchases
Expand Down Expand Up @@ -84,6 +85,7 @@ private fun LoadingOfferingsScreen() {
}
}

@OptIn(InternalRevenueCatAPI::class)
@Suppress("LongMethod")
@Composable
private fun OfferingsListScreen(
Expand Down Expand Up @@ -138,11 +140,11 @@ private fun OfferingsListScreen(
Column {
Text(text = offering.identifier)

offering.paywall?.let {
offering.paywall?.also {
Text("Template ${it.templateName}")
} ?: run {
Text("No paywall")
}
} ?: offering.paywallComponents?.also {
Text("Components ${it.templateName}")
} ?: Text("No paywall")
}
}
Divider()
Expand Down
Loading