Skip to content

Creates default PaywallData#1261

Merged
vegaro merged 21 commits into
paywallsfrom
cesar/pwl-192-create-default-paywalldata
Sep 22, 2023
Merged

Creates default PaywallData#1261
vegaro merged 21 commits into
paywallsfrom
cesar/pwl-192-create-default-paywalldata

Conversation

@vegaro

@vegaro vegaro commented Sep 19, 2023

Copy link
Copy Markdown
Member

Creates a default PaywallData in case data doesn't pass validation

@vegaro vegaro added the pr:feat A new feature label Sep 19, 2023
@vegaro

vegaro commented Sep 20, 2023

Copy link
Copy Markdown
Member Author

@tonidero do you mind giving this a quick look see if it makes sense so far? Specially the Colors related stuff

@tonidero tonidero left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the color stuff makes sense 👍

blurredBackgroundImage = true,
displayRestorePurchases = true,
),
localization = mapOf(locale to PaywallData.defaultLocalization), // TODO-PAYWALLS: test this

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I wasn't sure haha

It's basically taking the system one 🤷‍♂️

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So defaultLocalization is not currently localized right? I was wondering whether to hardcode the Locale.ENGLISH for now until that was localized. But if we are doing that soon, it should be ok to leave this.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that makes sense! to use Locale.ENGLISH

…ate-default-paywalldata

# Conflicts:
#	ui/revenuecatui/src/main/kotlin/com/revenuecat/purchases/ui/revenuecatui/templates/Template2.kt
@codecov

codecov Bot commented Sep 21, 2023

Copy link
Copy Markdown

Codecov Report

Patch coverage: 60.00% and project coverage change: -0.01% ⚠️

Comparison is base (a4ecd77) 85.47% compared to head (0f9e68a) 85.46%.
Report is 1 commits behind head on paywalls.

Additional details and impacted files
@@             Coverage Diff              @@
##           paywalls    #1261      +/-   ##
============================================
- Coverage     85.47%   85.46%   -0.01%     
============================================
  Files           190      190              
  Lines          6380     6385       +5     
  Branches        929      930       +1     
============================================
+ Hits           5453     5457       +4     
  Misses          568      568              
- Partials        359      360       +1     
Files Changed Coverage Δ
.../com/revenuecat/purchases/paywalls/PaywallColor.kt 68.42% <60.00%> (+4.13%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@vegaro vegaro marked this pull request as ready for review September 21, 2023 16:56
@vegaro vegaro requested review from a team, NachoSoto and tonidero September 21, 2023 16:56
@vegaro vegaro changed the title [WIP] Creates default PaywallData Creates default PaywallData Sep 21, 2023
},
)

constructor(@ColorInt colorInt: Int) : this(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add tests for this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a test for this constructor. I plan on adding a bunch of tests after this gets merged

@NachoSoto NachoSoto left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome 👏🏻 just a few comments.

@ReadOnlyComposable
private fun PaywallData.Companion.createDefaultForIdentifiers(packageIdentifiers: List<String>): PaywallData {
val context = LocalContext.current
val locale = LocaleListCompat.getDefault()[0].toString()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is duplicated in PaywallData.localizedConfiguration. Maybe we can add a property there to make sure we use the same default?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this #1261 (comment) so this is not needed anymore

config = PaywallData.Configuration(
packages = packageIdentifiers,
images = PaywallData.Configuration.Images(
background = PaywallData.defaultBackgroundImage,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, does this work now?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't. I created a https://linear.app/revenuecat/issue/PWL-274/support-default-background-image to make sure this works, for now it is just a placeholder. We need to do some refactor and change URL with URI for loading images from anywhere

blurredBackgroundImage = true,
displayRestorePurchases = true,
),
localization = mapOf(locale to PaywallData.defaultLocalization), // TODO-PAYWALLS: test this

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So defaultLocalization is not currently localized right? I was wondering whether to hardcode the Locale.ENGLISH for now until that was localized. But if we are doing that soon, it should be ok to leave this.

@Composable
@ReadOnlyComposable
private fun PaywallData.Companion.createDefaultForIdentifiers(packageIdentifiers: List<String>): PaywallData {
val context = LocalContext.current

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the fact that we have this in the same place that we calculate the PaywallData means that, whenever there is a configuration change, this and anything depending on this function will get recompositioned.

Additionally, I'm not totally sure how we're planning to use this, since the paywall data is currently obtained/stored by the view model, which can't access composable functions.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made the change in 6ce4758 and these are not composable anymore

@tonidero tonidero left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments. I'm wondering if the background image loads well... Other than that, nothing blocking

}

@Test
fun `paywall color can be created from a ColorInt`() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I was thinking whether we should move this test to a different file... But I think it's ok for now since it's indeed kinda related.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, let's create a new file that will only have this test for now. It was me being lazy

get() = -1

private val PaywallData.Companion.defaultBackgroundImage: String
get() = "R.drawable.default_background"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So then, it will work with RemoteImage when using a local resource for the background? Checking just to make sure.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will address the background image stuff in a future PR because it requires some refactoring and changing URL to URIs

https://linear.app/revenuecat/issue/PWL-274/support-default-background-image

)

private fun PaywallData.Companion.defaultTemplateBaseURL(packageName: String): URL =
URL("android.resource://$packageName/")

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this and it doesn't work, so I am just going to revert it to use a placeholder, same way we do in iOS. It requires less refactoring

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh looks like you never reverted this. It's making the app crash right now.

)

private fun PaywallData.Companion.defaultTemplateBaseURL(packageName: String): URL =
URL("android.resource://$packageName/")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

.widthIn(max = Template2UIConstants.maxIconWidth)
.clip(RoundedCornerShape(Template2UIConstants.iconCornerRadius))
if (uri.toString().contains(PaywallData.defaultAppIconPlaceholder)) {
AppIcon(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome

accent2 = currentColors.primary.asPaywallColor(),
)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a future PR: we could add a preview in this file that shows Template2() with this default data :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great idea

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vegaro vegaro merged commit af717d8 into paywalls Sep 22, 2023
@vegaro vegaro deleted the cesar/pwl-192-create-default-paywalldata branch September 22, 2023 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr:feat A new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants