[Paywalls V2] Adds ImageUrls and ColorInfo properties#1923
Conversation
| companion object { | ||
| private val rgbaColorRegex = Regex("^#([A-Fa-f0-9]{8})$") | ||
|
|
||
| @Suppress("MagicNumber") | ||
| @ColorInt | ||
| private fun parseRGBAColor(stringRepresentation: String): Int { | ||
| return if (stringRepresentation.matches(rgbaColorRegex)) { | ||
| val radix = 16 | ||
| val r = stringRepresentation.substring(1, 3).toInt(radix) | ||
| val g = stringRepresentation.substring(3, 5).toInt(radix) | ||
| val b = stringRepresentation.substring(5, 7).toInt(radix) | ||
| val a = stringRepresentation.substring(7, 9).toInt(radix) | ||
| Color.argb(a, r, g, b) | ||
| } else { | ||
| Color.parseColor(stringRepresentation) | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
This is moved to its own file (ColorUtils.kt) so it can be reused.
| internal fun parseRGBAColor(stringRepresentation: String): Int = | ||
| rgbaColorRegex.matchEntire(stringRepresentation)?.let { match -> | ||
| val radix = 16 | ||
| val (r, g, b) = match.destructured | ||
| val a = match.groupValues.getOrNull(4).takeUnless { it.isNullOrBlank() } ?: "FF" | ||
| colorInt( | ||
| alpha = a.toInt(radix), | ||
| red = r.toInt(radix), | ||
| green = g.toInt(radix), | ||
| blue = b.toInt(radix), | ||
| ) | ||
| } ?: Color.parseColor(stringRepresentation) |
There was a problem hiding this comment.
This is slightly adjusted from what it was like in PaywallColor. It now supports parsing RGBA and RGB colors without falling back to an Android platform method. This avoids having to use specific (Robolectric) test runners in unit tests.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1923 +/- ##
==========================================
- Coverage 82.17% 82.07% -0.11%
==========================================
Files 232 235 +3
Lines 8101 8128 +27
Branches 1146 1152 +6
==========================================
+ Hits 6657 6671 +14
- Misses 991 997 +6
- Partials 453 460 +7 ☔ View full report in Codecov by Sentry. 🚨 Try these New Features:
|
joshdholtz
left a comment
There was a problem hiding this comment.
Looks good! One comment about width and height on the image happening soon
| import java.net.URL | ||
|
|
||
| @Serializable | ||
| internal data class ImageUrls internal constructor( |
There was a problem hiding this comment.
I haven't added this to the API yet but I just added (last night) to the spec that this object will also have a width and height associated with it.
This will allow us to use those dimensions for correctly sizing images (if needed) without waiting for the image to fetch (if we don't have it yet).
So... you don't need to add this now but just wanted to let you know of this change 😇
So if you want you could add these now 😊
There was a problem hiding this comment.
Oh sounds great! Will add these in this PR. They're just integers I assume?
There was a problem hiding this comment.
And will they be optional, or guaranteed to be in the response?
There was a problem hiding this comment.
Right now they don't exist but they will be on all images uploaded after like... next week 😁
I'm was going to put them as required in the iOS SDK 🤷♂️
There was a problem hiding this comment.
Alright, will do the same! Are they integers, or SizeConstraints, or something else?
There was a problem hiding this comment.
They will be integers! They are the pixel width and height of the image
**This is an automatic release.** ## RevenueCat SDK ### 🐞 Bugfixes * Uses `Sequence` instead of `Stream` to avoid errors due to unavailable Java 8 APIs (#1943) via JayShortway (@JayShortway) ### 🔄 Other Changes * Increase integration test timeout (#1946) via Toni Rico (@tonidero) * Removes `@RequiresApi(N)` from `FileHelper` and related classes (#1944) via JayShortway (@JayShortway) * [Paywalls V2] Minimizes Java API (#1942) via JayShortway (@JayShortway) * [Paywalls V2] Makes `TextComponent` public (#1939) via JayShortway (@JayShortway) * Introduces an `@InternalRevenueCatAPI` annotation (#1938) via JayShortway (@JayShortway) * [Paywalls V2] Moves any non-component file to a new `common` package. (#1937) via JayShortway (@JayShortway) * [Paywalls V2] `LocalizationKey` is an inline value class now. (#1936) via JayShortway (@JayShortway) * [Paywalls V2] Adds `PaywallComponentsData` (#1935) via JayShortway (@JayShortway) * [Paywalls V2] Adds `StickyFooterComponent` (#1934) via JayShortway (@JayShortway) * [Paywalls V2] Adds `PurchaseButtonComponent` (#1933) via JayShortway (@JayShortway) * [Paywalls V2] Adds `PackageComponent` (#1932) via JayShortway (@JayShortway) * Ensure the correct error message is shown when failing to open a Uri in paywalls (#1922) via JayShortway (@JayShortway) * [Paywalls V2] Adds `ButtonComponent` (#1931) via JayShortway (@JayShortway) * [Paywalls V2] Adds `StackComponent` (#1930) via JayShortway (@JayShortway) * [Paywalls V2] Adds `ComponentOverrides` (#1929) via JayShortway (@JayShortway) * [Paywalls V2] Adds `ImageComponent` (#1928) via JayShortway (@JayShortway) * [Paywalls V2] Adds `TextComponent` (#1927) via JayShortway (@JayShortway) * [Paywalls V2] Adds all enum properties (#1926) via JayShortway (@JayShortway) * [Paywalls V2] Adds `SizeConstraints`, `Size`, `Padding` and `Shadow` properties (#1925) via JayShortway (@JayShortway) * [Paywalls V2] Adds `CornerRadiuses`, `Shape` and `MaskShape` properties (#1924) via JayShortway (@JayShortway) * [Paywalls V2] Adds `ImageUrls` and `ColorInfo` properties (#1923) via JayShortway (@JayShortway) Co-authored-by: revenuecat-ops <ops@revenuecat.com>
As the title says. This adds:
ImageUrlsandThemeImageUrlsColorInfoandColorSchemeand ensures they are deserialized correctly.