Skip to content

Commit

Permalink
Paywalls: implemented template 5 (#1412)
Browse files Browse the repository at this point in the history
  • Loading branch information
NachoSoto authored and tonidero committed Oct 31, 2023
1 parent f60a412 commit 6463918
Show file tree
Hide file tree
Showing 6 changed files with 602 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,21 @@ class SamplePaywallsLoader {
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.UNRECOGNIZED_TEMPLATE -> SamplePaywalls.unrecognizedTemplate()
}
}
}

@SuppressWarnings("LongMethod")
object SamplePaywalls {

enum class SampleTemplate(val displayableName: String) {
TEMPLATE_1("#1: Minimalist"),
TEMPLATE_2("#2: Bold packages"),
TEMPLATE_3("#3: Feature list"),
TEMPLATE_4("#4: Horizontal packages"),
TEMPLATE_5("#5: Minimalist with small banner"),
UNRECOGNIZED_TEMPLATE("Default template"),
}

Expand Down Expand Up @@ -335,6 +338,68 @@ object SamplePaywalls {
)
}

fun template5(): PaywallData {
return PaywallData(
templateName = "5",
config = PaywallData.Configuration(
packageIds = listOf(
PackageType.ANNUAL.identifier!!,
PackageType.MONTHLY.identifier!!,
),
defaultPackage = PackageType.MONTHLY.identifier!!,
images = PaywallData.Configuration.Images(
header = "954459_1692992845.png",
),
displayRestorePurchases = true,
termsOfServiceURL = URL("https://revenuecat.com/tos"),
privacyURL = URL("https://revenuecat.com/privacy"),
colors = PaywallData.Configuration.ColorInformation(
light = PaywallData.Configuration.Colors(
background = PaywallColor(stringRepresentation = "#FFFFFF"),
text1 = PaywallColor(stringRepresentation = "#000000"),
text2 = PaywallColor(stringRepresentation = "#adf5c5"),
text3 = PaywallColor(stringRepresentation = "#b15d5d"),
callToActionBackground = PaywallColor(stringRepresentation = "#45c186"),
callToActionForeground = PaywallColor(stringRepresentation = "#ffffff"),
accent1 = PaywallColor(stringRepresentation = "#b24010"),
accent2 = PaywallColor(stringRepresentation = "#027424"),
accent3 = PaywallColor(stringRepresentation = "#D1D1D1"),
),
),
),
assetBaseURL = paywallAssetBaseURL,
localization = mapOf(
"en_US" to PaywallData.LocalizedConfiguration(
title = "Spice Up Your Kitchen - Go Pro for Exclusive Benefits!",
callToAction = "Continue",
callToActionWithIntroOffer = "Start your Free Trial",
offerDetails = "{{ total_price_and_per_month }}",
offerDetailsWithIntroOffer = "Free for {{ sub_offer_duration }}, " +
"then {{ total_price_and_per_month }}",
offerName = "{{ sub_period }}",
features = listOf(
PaywallData.LocalizedConfiguration.Feature(
title = "Unique gourmet recipes",
iconID = "tick",
),
PaywallData.LocalizedConfiguration.Feature(
title = "Advanced nutritional recipes",
iconID = "apple",
),
PaywallData.LocalizedConfiguration.Feature(
title = "Personalized support from our Chef",
iconID = "warning",
),
PaywallData.LocalizedConfiguration.Feature(
title = "Unlimited receipt collections",
iconID = "bookmark",
),
),
),
),
)
}

fun unrecognizedTemplate(): PaywallData {
return PaywallData(
templateName = "unrecognized",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import com.revenuecat.purchases.ui.revenuecatui.templates.Template1
import com.revenuecat.purchases.ui.revenuecatui.templates.Template2
import com.revenuecat.purchases.ui.revenuecatui.templates.Template3
import com.revenuecat.purchases.ui.revenuecatui.templates.Template4
import com.revenuecat.purchases.ui.revenuecatui.templates.Template5

@OptIn(ExperimentalPreviewRevenueCatUIPurchasesAPI::class)
@Composable
Expand Down Expand Up @@ -122,7 +123,7 @@ private fun TemplatePaywall(state: PaywallState.Loaded, viewModel: PaywallViewMo
PaywallTemplate.TEMPLATE_2 -> Template2(state = state, viewModel = viewModel)
PaywallTemplate.TEMPLATE_3 -> Template3(state = state, viewModel = viewModel)
PaywallTemplate.TEMPLATE_4 -> Template4(state = state, viewModel = viewModel)
PaywallTemplate.TEMPLATE_5 -> Text(text = "Error: Template 5 not supported")
PaywallTemplate.TEMPLATE_5 -> Template5(state = state, viewModel = viewModel)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ internal enum class PaywallTemplate(val id: String, val configurationType: Packa
TEMPLATE_2("2", PackageConfigurationType.MULTIPLE),
TEMPLATE_3("3", PackageConfigurationType.SINGLE),
TEMPLATE_4("4", PackageConfigurationType.MULTIPLE),
TEMPLATE_5("5_disabled", PackageConfigurationType.MULTIPLE),
TEMPLATE_5("5", PackageConfigurationType.MULTIPLE),
;

companion object {
@Suppress("UnusedParameter")
fun fromId(id: String): PaywallTemplate? {
return values().find { it.id == id }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.revenuecat.purchases.ui.revenuecatui.data.testdata.templates.template
import com.revenuecat.purchases.ui.revenuecatui.data.testdata.templates.template2
import com.revenuecat.purchases.ui.revenuecatui.data.testdata.templates.template3
import com.revenuecat.purchases.ui.revenuecatui.data.testdata.templates.template4
import com.revenuecat.purchases.ui.revenuecatui.data.testdata.templates.template5
import com.revenuecat.purchases.ui.revenuecatui.helpers.ApplicationContext
import com.revenuecat.purchases.ui.revenuecatui.helpers.toPaywallState
import kotlinx.coroutines.delay
Expand Down Expand Up @@ -145,6 +146,17 @@ internal object TestData {
serverDescription = "",
)

val template5Offering = Offering(
identifier = "Template5",
availablePackages = listOf(
Packages.monthly,
Packages.annual,
),
metadata = mapOf(),
paywall = template5,
serverDescription = "",
)

object Packages {
val weekly = Package(
packageType = PackageType.WEEKLY,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.revenuecat.purchases.ui.revenuecatui.data.testdata.templates

import com.revenuecat.purchases.PackageType
import com.revenuecat.purchases.paywalls.PaywallColor
import com.revenuecat.purchases.paywalls.PaywallData
import com.revenuecat.purchases.ui.revenuecatui.data.processed.PaywallTemplate
import com.revenuecat.purchases.ui.revenuecatui.data.testdata.TestData
import java.net.URL

internal val TestData.template5: PaywallData
get() = PaywallData(
templateName = PaywallTemplate.TEMPLATE_5.id,
config = PaywallData.Configuration(
packageIds = listOf(
PackageType.ANNUAL.identifier!!,
PackageType.MONTHLY.identifier!!,
),
defaultPackage = PackageType.ANNUAL.identifier!!,
images = PaywallData.Configuration.Images(
header = "954459_1692992845.png",
),
displayRestorePurchases = true,
privacyURL = URL("https://revenuecat.com/privacy"),
colors = PaywallData.Configuration.ColorInformation(
light = PaywallData.Configuration.Colors(
background = PaywallColor(stringRepresentation = "#FFFFFF"),
text1 = PaywallColor(stringRepresentation = "#000000"),
text2 = PaywallColor(stringRepresentation = "#adf5c5"),
text3 = PaywallColor(stringRepresentation = "#b15d5d"),
callToActionBackground = PaywallColor(stringRepresentation = "#45c186"),
callToActionForeground = PaywallColor(stringRepresentation = "#ffffff"),
accent1 = PaywallColor(stringRepresentation = "#b24010"),
accent2 = PaywallColor(stringRepresentation = "#027424"),
accent3 = PaywallColor(stringRepresentation = "#D1D1D1"),
),
),
),
localization = mapOf(
"en_US" to PaywallData.LocalizedConfiguration(
title = "Spice Up Your Kitchen - Go Pro for Exclusive Benefits!",
callToAction = "Continue",
callToActionWithIntroOffer = "Start your Free Trial",
offerDetails = "{{ total_price_and_per_month }}",
offerDetailsWithIntroOffer = "Free for {{ sub_offer_duration }}, then {{ total_price_and_per_month }}",
offerName = "{{ sub_period }}",
features = listOf(
PaywallData.LocalizedConfiguration.Feature(
title = "Unique gourmet recipes",
iconID = "tick",
),
PaywallData.LocalizedConfiguration.Feature(
title = "Advanced nutritional recipes",
iconID = "apple",
),
PaywallData.LocalizedConfiguration.Feature(
title = "Personalized support from our Chef",
iconID = "warning",
),
PaywallData.LocalizedConfiguration.Feature(
title = "Unlimited receipt collections",
iconID = "bookmark",
),
),
),
),
assetBaseURL = TestData.Constants.assetBaseURL,
)
Loading

0 comments on commit 6463918

Please sign in to comment.