-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Paywalls V2] LocalizationKey
is an inline value class now.
#1936
Merged
Merged
Changes from 92 commits
Commits
Show all changes
93 commits
Select commit
Hold shift + click to select a range
aaa66b6
Adds ImageUrls and tests.
JayShortway e41629c
Adds ColorInfo and tests.
JayShortway ff61b28
Moves and adjusts parseRGBAColor() from PaywallColor so it can be use…
JayShortway 0891b50
ColorInfo.Hex contains a ColorInt now instead of a string.
JayShortway 31fde3e
Adjusts a comment.
JayShortway 4153ef3
Adds CornerRadiuses and tests.
JayShortway 1f25a47
Adds Shape and tests.
JayShortway 584fd0a
Adds MaskShape and tests.
JayShortway 740b124
Adds Padding and tests.
JayShortway 7d5152a
Adds Size, SizeConstraint and tests.
JayShortway c1992b5
Adds Shadow and tests.
JayShortway 9fbf37f
Adds FlexDistribution and tests.
JayShortway ab136d6
Adds Alignment and tests.
JayShortway 2390dcc
Adds Font and tests.
JayShortway 5e4c618
Adds FitMode and tests.
JayShortway 64d92ed
Adds with and height properties to ImageUrls.
JayShortway 03c4990
Adds TextComponent and tests.
JayShortway f7b1aeb
ColorInfo is now a sealed interface instead of a sealed class.
JayShortway 21f9a72
Shape and MaskShape are now sealed interfaces instead of a sealed cla…
JayShortway a7e6ba7
SizeConstraint is now a sealed interface instead of a sealed class.
JayShortway d474209
Merge branch 'pw2-properties-images-colors' into pw2-properties-shapes
JayShortway 8ce7f2e
Merge branch 'pw2-properties-shapes' into pw2-properties-size-padding
JayShortway 7ab6cee
Merge branch 'pw2-properties-size-padding' into pw2-properties-enums
JayShortway 0586214
Merge branch 'pw2-properties-enums' into pw2-textcomponent
JayShortway 6c1a8c5
Adds ImageComponent and tests.
JayShortway 40ac835
Adds Linear and Radial gradients to ColorInfo.
JayShortway d2eba36
Merge branch 'pw2-properties-images-colors' into pw2-properties-shapes
JayShortway c77b8d9
Merge branch 'pw2-properties-shapes' into pw2-properties-size-padding
JayShortway 25422b4
Merge branch 'pw2-properties-size-padding' into pw2-properties-enums
JayShortway 199e962
Merge branch 'pw2-properties-enums' into pw2-textcomponent
JayShortway 6f51252
Merge branch 'pw2-textcomponent' into pw2-imagecomponent
JayShortway faa0bfd
Adds ComponentOverrides.
JayShortway f121f4e
Adds PartialTextComponent and PartialImageComponent.
JayShortway 84024d1
Adds tests for PartialTextComponent and PartialImageComponent.
JayShortway 81cc4c9
Adds ComponentOverridesTests.
JayShortway 6da048a
Adds Dimension and tests.
JayShortway ad85fdd
Adds Border and tests.
JayShortway 2d42d98
Adds StackComponent and tests.
JayShortway 6894d50
Merge branch 'main' into pw2-properties-shapes
JayShortway fc970b8
Merge branch 'pw2-properties-shapes' into pw2-properties-size-padding
JayShortway 1ae2f89
Merge branch 'pw2-properties-size-padding' into pw2-properties-enums
JayShortway 38def75
Merge branch 'pw2-properties-enums' into pw2-textcomponent
JayShortway 9491eeb
Merge branch 'pw2-textcomponent' into pw2-imagecomponent
JayShortway ca6d5dc
Merge branch 'pw2-imagecomponent' into pw2-overrides
JayShortway bdf7fc9
Merge branch 'pw2-overrides' into pw2-stackcomponent
JayShortway e3153e3
Merge branch 'main' into pw2-properties-size-padding
JayShortway b03c253
Merge branch 'pw2-properties-size-padding' into pw2-properties-enums
JayShortway f5be3cb
Merge branch 'pw2-properties-enums' into pw2-textcomponent
JayShortway 66041c2
Merge branch 'pw2-textcomponent' into pw2-imagecomponent
JayShortway 6ceea3b
Merge branch 'pw2-imagecomponent' into pw2-overrides
JayShortway fae7d40
Merge branch 'pw2-overrides' into pw2-stackcomponent
JayShortway 3174a94
Adds ButtonComponent and tests.
JayShortway 6d1caf0
Updates a comment.
JayShortway 9e69018
Merge branch 'main' into pw2-properties-enums
JayShortway 1e4a7d3
Adds PackageComponent and tests.
JayShortway 3f4ec6f
Merge branch 'pw2-properties-enums' into pw2-textcomponent
JayShortway e7a047b
Merge branch 'pw2-textcomponent' into pw2-imagecomponent
JayShortway 577fba8
Merge branch 'pw2-imagecomponent' into pw2-overrides
JayShortway bf26c54
Merge branch 'pw2-overrides' into pw2-stackcomponent
JayShortway 7fc7476
Merge branch 'pw2-stackcomponent' into pw2-buttoncomponent
JayShortway 8f008bc
Merge branch 'pw2-buttoncomponent' into pw2-packagecomponent
JayShortway 0d4fe06
Merge branch 'main' into pw2-textcomponent
JayShortway ee3fcc7
Adds PurchaseButtonComponent and tests.
JayShortway 4d8e616
Merge branch 'pw2-textcomponent' into pw2-imagecomponent
JayShortway c464fc4
Merge branch 'pw2-imagecomponent' into pw2-overrides
JayShortway 47430db
Merge branch 'pw2-overrides' into pw2-stackcomponent
JayShortway 881fe64
Merge branch 'pw2-stackcomponent' into pw2-buttoncomponent
JayShortway 287e471
Merge branch 'pw2-buttoncomponent' into pw2-packagecomponent
JayShortway 422ddc9
Merge branch 'pw2-packagecomponent' into pw2-purchasebuttoncomponent
JayShortway 20dea35
Adds StickyFooterComponent and tests.
JayShortway 68c5091
Merge branch 'main' into pw2-imagecomponent
JayShortway 8942966
Merge branch 'pw2-imagecomponent' into pw2-overrides
JayShortway 6808659
Merge branch 'pw2-overrides' into pw2-stackcomponent
JayShortway aef40eb
Merge branch 'pw2-stackcomponent' into pw2-buttoncomponent
JayShortway 3cd711c
Merge branch 'pw2-buttoncomponent' into pw2-packagecomponent
JayShortway 426930e
Merge branch 'pw2-packagecomponent' into pw2-purchasebuttoncomponent
JayShortway 1c6a7e1
Merge branch 'pw2-purchasebuttoncomponent' into pw2-stickyfootercompo…
JayShortway fa3b7ad
Adds ComponentsConfig and tests.
JayShortway a509254
Adds LocalizationData and tests.
JayShortway fb91be8
Adds PaywallComponentsData and tests.
JayShortway cbc6747
Adds Background and tests.
JayShortway 1f4451f
Merge branch 'main' into pw2-buttoncomponent
JayShortway 9c915db
Merge branch 'pw2-buttoncomponent' into pw2-packagecomponent
JayShortway f0a6724
Merge branch 'pw2-packagecomponent' into pw2-purchasebuttoncomponent
JayShortway c9fcf24
Merge branch 'pw2-purchasebuttoncomponent' into pw2-stickyfootercompo…
JayShortway 5b7031a
Merge branch 'pw2-stickyfootercomponent' into pw2-paywallcomponentsdata
JayShortway 83bdc71
LocalizationKey is an inline value class now.
JayShortway 8d24d9a
Merge branch 'main' into pw2-stickyfootercomponent
JayShortway ae085c5
Merge branch 'pw2-stickyfootercomponent' into pw2-paywallcomponentsdata
JayShortway 420b236
Merge branch 'pw2-paywallcomponentsdata' into pw2-localizationkey
JayShortway 3176104
Merge branch 'main' into pw2-paywallcomponentsdata
JayShortway 938fc43
Merge branch 'pw2-paywallcomponentsdata' into pw2-localizationkey
JayShortway 586b7c6
Merge branch 'main' into pw2-localizationkey
JayShortway File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
purchases/src/main/kotlin/com/revenuecat/purchases/paywalls/components/Background.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.revenuecat.purchases.paywalls.components | ||
|
||
import com.revenuecat.purchases.paywalls.components.properties.ColorScheme | ||
import com.revenuecat.purchases.paywalls.components.properties.ThemeImageUrls | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
internal sealed interface Background { | ||
@Serializable | ||
@SerialName("color") | ||
data class Color(val value: ColorScheme) : Background | ||
|
||
@Serializable | ||
@SerialName("image") | ||
data class Image(val value: ThemeImageUrls) : Background | ||
} |
17 changes: 17 additions & 0 deletions
17
purchases/src/main/kotlin/com/revenuecat/purchases/paywalls/components/ComponentsConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.revenuecat.purchases.paywalls.components | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
internal data class ComponentsConfig( | ||
val base: PaywallComponentsConfig, | ||
) | ||
|
||
@Serializable | ||
internal data class PaywallComponentsConfig( | ||
val stack: StackComponent, | ||
val background: Background, | ||
@SerialName("sticky_footer") | ||
val stickyFooter: StickyFooterComponent? = null, | ||
) |
60 changes: 60 additions & 0 deletions
60
purchases/src/main/kotlin/com/revenuecat/purchases/paywalls/components/Localization.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.revenuecat.purchases.paywalls.components | ||
|
||
import com.revenuecat.purchases.paywalls.components.properties.ThemeImageUrls | ||
import kotlinx.serialization.ExperimentalSerializationApi | ||
import kotlinx.serialization.InternalSerializationApi | ||
import kotlinx.serialization.KSerializer | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.SerializationException | ||
import kotlinx.serialization.descriptors.PolymorphicKind | ||
import kotlinx.serialization.descriptors.SerialDescriptor | ||
import kotlinx.serialization.descriptors.buildSerialDescriptor | ||
import kotlinx.serialization.encoding.Decoder | ||
import kotlinx.serialization.encoding.Encoder | ||
|
||
@Serializable | ||
@JvmInline | ||
internal value class LocaleId(val value: String) | ||
|
||
@Serializable | ||
@JvmInline | ||
internal value class LocalizationKey(val value: String) | ||
|
||
internal typealias LocalizationDictionary = Map<LocalizationKey, LocalizationData> | ||
|
||
/** | ||
* A make-shift union type. LocalizationData is either a plain String or a ThemeImageUrls object. | ||
*/ | ||
@Serializable(with = LocalizationDataSerializer::class) | ||
internal sealed interface LocalizationData { | ||
@Serializable | ||
@JvmInline | ||
value class Text(val value: String) : LocalizationData | ||
|
||
@Serializable | ||
@JvmInline | ||
value class Image(val value: ThemeImageUrls) : LocalizationData | ||
} | ||
|
||
private object LocalizationDataSerializer : KSerializer<LocalizationData> { | ||
// Documentation says to use either PrimitiveSerialDescriptor or buildClassSerialDescriptor. However, we need a | ||
// polymorphic descriptor that's either a primitive (string) or a class. So neither of those options fit the bill. | ||
@OptIn(InternalSerializationApi::class, ExperimentalSerializationApi::class) | ||
override val descriptor: SerialDescriptor = buildSerialDescriptor( | ||
serialName = "LocalizationData", | ||
kind = PolymorphicKind.SEALED, | ||
) | ||
|
||
override fun serialize(encoder: Encoder, value: LocalizationData) { | ||
error("Serialization is not implemented as it is not (yet) needed.") | ||
} | ||
|
||
@Suppress("SwallowedException") | ||
override fun deserialize(decoder: Decoder): LocalizationData = | ||
// We have no `type` descriptor field, so we resort to trial and error. | ||
try { | ||
decoder.decodeSerializableValue(LocalizationData.Text.serializer()) | ||
} catch (e: SerializationException) { | ||
decoder.decodeSerializableValue(LocalizationData.Image.serializer()) | ||
} | ||
} |
3 changes: 0 additions & 3 deletions
3
purchases/src/main/kotlin/com/revenuecat/purchases/paywalls/components/LocalizationKey.kt
This file was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
...ses/src/main/kotlin/com/revenuecat/purchases/paywalls/components/PaywallComponentsData.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.revenuecat.purchases.paywalls.components | ||
|
||
import com.revenuecat.purchases.utils.serializers.URLSerializer | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
import java.net.URL | ||
|
||
@Serializable | ||
internal data class PaywallComponentsData( | ||
@SerialName("template_name") | ||
val templateName: String, | ||
@Serializable(with = URLSerializer::class) | ||
@SerialName("asset_base_url") | ||
val assetBaseURL: URL, | ||
@SerialName("components_config") | ||
val componentsConfig: ComponentsConfig, | ||
@SerialName("components_localizations") | ||
val componentsLocalizations: Map<LocaleId, LocalizationDictionary>, | ||
@SerialName("default_locale") | ||
val defaultLocaleIdentifier: LocaleId, | ||
val revision: Int = 0, | ||
) |
93 changes: 93 additions & 0 deletions
93
purchases/src/test/java/com/revenuecat/purchases/paywalls/components/BackgroundTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package com.revenuecat.purchases.paywalls.components | ||
|
||
import com.revenuecat.purchases.common.OfferingParser | ||
import com.revenuecat.purchases.paywalls.components.properties.ColorInfo | ||
import com.revenuecat.purchases.paywalls.components.properties.ColorScheme | ||
import com.revenuecat.purchases.paywalls.components.properties.ImageUrls | ||
import com.revenuecat.purchases.paywalls.components.properties.ThemeImageUrls | ||
import org.intellij.lang.annotations.Language | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.junit.runners.Parameterized | ||
import java.net.URL | ||
|
||
@RunWith(Parameterized::class) | ||
internal class BackgroundTests(@Suppress("UNUSED_PARAMETER") name: String, private val args: Args) { | ||
|
||
class Args( | ||
@Language("json") | ||
val json: String, | ||
val expected: Background, | ||
) | ||
|
||
companion object { | ||
|
||
@Suppress("LongMethod") | ||
@JvmStatic | ||
@Parameterized.Parameters(name = "{0}") | ||
fun parameters(): Collection<*> = listOf( | ||
arrayOf( | ||
"String", | ||
Args( | ||
json = """ | ||
{ | ||
"type": "color", | ||
"value": { | ||
"light": { | ||
"type": "alias", | ||
"value": "primary" | ||
} | ||
} | ||
} | ||
""".trimIndent(), | ||
expected = Background.Color( | ||
value = ColorScheme( | ||
light = ColorInfo.Alias("primary") | ||
) | ||
), | ||
), | ||
), | ||
arrayOf( | ||
"ThemeImageUrls", | ||
Args( | ||
json = """ | ||
{ | ||
"type": "image", | ||
"value": { | ||
"light": { | ||
"heic": "https://assets.pawwalls.com/1151049_1732039548.heic", | ||
"heic_low_res": "https://assets.pawwalls.com/1151049_low_res_1732039548.heic", | ||
"original": "https://assets.pawwalls.com/1151049_1732039548.png", | ||
"webp": "https://assets.pawwalls.com/1151049_1732039548.webp", | ||
"webp_low_res": "https://assets.pawwalls.com/1151049_low_res_1732039548.webp", | ||
"width": 2345, | ||
"height": 1234 | ||
} | ||
} | ||
} | ||
""".trimIndent(), | ||
expected = Background.Image( | ||
value = ThemeImageUrls( | ||
light = ImageUrls( | ||
original = URL("https://assets.pawwalls.com/1151049_1732039548.png"), | ||
webp = URL("https://assets.pawwalls.com/1151049_1732039548.webp"), | ||
webpLowRes = URL("https://assets.pawwalls.com/1151049_low_res_1732039548.webp"), | ||
width = 2345.toUInt(), | ||
height = 1234.toUInt(), | ||
) | ||
) | ||
), | ||
), | ||
), | ||
) | ||
} | ||
|
||
@Test | ||
fun `Should properly deserialize Background`() { | ||
// Arrange, Act | ||
val actual = OfferingParser.json.decodeFromString<Background>(args.json) | ||
|
||
// Assert | ||
assert(actual == args.expected) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I totally know what a
@JvmInline
is... yup yup yup 😅There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha, this instructs the Kotlin compiler to make it a
value class
from a Java perspective.