Creates default PaywallData#1261
Conversation
|
@tonidero do you mind giving this a quick look see if it makes sense so far? Specially the Colors related stuff |
tonidero
left a comment
There was a problem hiding this comment.
I think the color stuff makes sense 👍
| blurredBackgroundImage = true, | ||
| displayRestorePurchases = true, | ||
| ), | ||
| localization = mapOf(locale to PaywallData.defaultLocalization), // TODO-PAYWALLS: test this |
There was a problem hiding this comment.
Ok, I wasn't sure haha
It's basically taking the system one 🤷♂️
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ReportPatch coverage:
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
☔ View full report in Codecov by Sentry. |
| }, | ||
| ) | ||
|
|
||
| constructor(@ColorInt colorInt: Int) : this( |
There was a problem hiding this comment.
Can we add tests for this?
There was a problem hiding this comment.
Added a test for this constructor. I plan on adding a bunch of tests after this gets merged
NachoSoto
left a comment
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
This is duplicated in PaywallData.localizedConfiguration. Maybe we can add a property there to make sure we use the same default?
There was a problem hiding this comment.
I did this #1261 (comment) so this is not needed anymore
| config = PaywallData.Configuration( | ||
| packages = packageIdentifiers, | ||
| images = PaywallData.Configuration.Images( | ||
| background = PaywallData.defaultBackgroundImage, |
There was a problem hiding this comment.
Nice, does this work now?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Made the change in 6ce4758 and these are not composable anymore
tonidero
left a comment
There was a problem hiding this comment.
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`() { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
So then, it will work with RemoteImage when using a local resource for the background? Checking just to make sure.
There was a problem hiding this comment.
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/") |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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/") |
| .widthIn(max = Template2UIConstants.maxIconWidth) | ||
| .clip(RoundedCornerShape(Template2UIConstants.iconCornerRadius)) | ||
| if (uri.toString().contains(PaywallData.defaultAppIconPlaceholder)) { | ||
| AppIcon( |
| accent2 = currentColors.primary.asPaywallColor(), | ||
| ) | ||
| } | ||
|
|
There was a problem hiding this comment.
For a future PR: we could add a preview in this file that shows Template2() with this default data :)
There was a problem hiding this comment.
Creates a default PaywallData in case data doesn't pass validation