Skip to content

[Paywalls V2] Adds ImageUrls and ColorInfo properties#1923

Merged
JayShortway merged 8 commits into
mainfrom
pw2-properties-images-colors
Nov 22, 2024
Merged

[Paywalls V2] Adds ImageUrls and ColorInfo properties#1923
JayShortway merged 8 commits into
mainfrom
pw2-properties-images-colors

Conversation

@JayShortway

Copy link
Copy Markdown
Member

As the title says. This adds:

  • ImageUrls and ThemeImageUrls
  • ColorInfo and ColorScheme

and ensures they are deserialized correctly.

Comment on lines -71 to -88
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)
}
}
}

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.

This is moved to its own file (ColorUtils.kt) so it can be reused.

Comment on lines +26 to +37
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)

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.

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

codecov Bot commented Nov 20, 2024

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 63.88889% with 13 lines in your changes missing coverage. Please review.

Project coverage is 82.07%. Comparing base (46a9e0e) to head (64d92ed).

Files with missing lines Patch % Lines
...chases/paywalls/components/properties/ColorInfo.kt 61.53% 2 Missing and 3 partials ⚠️
...chases/paywalls/components/properties/ImageUrls.kt 54.54% 3 Missing and 2 partials ⚠️
...in/com/revenuecat/purchases/paywalls/ColorUtils.kt 75.00% 1 Missing and 2 partials ⚠️
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.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@JayShortway JayShortway requested a review from a team November 20, 2024 13:51

@joshdholtz joshdholtz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good! One comment about width and height on the image happening soon

import java.net.URL

@Serializable
internal data class ImageUrls internal constructor(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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 😊

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.

Oh sounds great! Will add these in this PR. They're just integers I assume?

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.

And will they be optional, or guaranteed to be in the response?

@joshdholtz joshdholtz Nov 20, 2024

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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 🤷‍♂️

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.

Alright, will do the same! Are they integers, or SizeConstraints, or something else?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

They will be integers! They are the pixel width and height of the image

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.

Thanks! Added here: 64d92ed.

@joshdholtz joshdholtz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

:shipit:

@JayShortway JayShortway merged commit a93881d into main Nov 22, 2024
@JayShortway JayShortway deleted the pw2-properties-images-colors branch November 22, 2024 08:04
This was referenced Nov 28, 2024
JayShortway pushed a commit that referenced this pull request Dec 2, 2024
**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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants