-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Paywalls
: decode empty images as null
Equivalent to RevenueCat/purchases-ios#3195
- Loading branch information
Showing
5 changed files
with
91 additions
and
18 deletions.
There are no files selected for viewing
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
33 changes: 33 additions & 0 deletions
33
purchases/src/main/kotlin/com/revenuecat/purchases/paywalls/EmptyStringToNullSerializer.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,33 @@ | ||
package com.revenuecat.purchases.paywalls | ||
|
||
import kotlinx.serialization.KSerializer | ||
import kotlinx.serialization.builtins.nullable | ||
import kotlinx.serialization.builtins.serializer | ||
import kotlinx.serialization.descriptors.PrimitiveKind | ||
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor | ||
import kotlinx.serialization.descriptors.SerialDescriptor | ||
import kotlinx.serialization.encoding.Decoder | ||
import kotlinx.serialization.encoding.Encoder | ||
|
||
/** | ||
* Decodes empty or blank strings as null | ||
*/ | ||
internal object EmptyStringToNullSerializer : KSerializer<String?> { | ||
private val delegate = String.serializer().nullable | ||
|
||
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor( | ||
"EmptyStringToNullSerializer", | ||
PrimitiveKind.STRING, | ||
) | ||
|
||
override fun deserialize(decoder: Decoder): String? { | ||
return delegate.deserialize(decoder)?.takeIf(String::isNotBlank) | ||
} | ||
|
||
override fun serialize(encoder: Encoder, value: String?) { | ||
when (value) { | ||
Check warning on line 28 in purchases/src/main/kotlin/com/revenuecat/purchases/paywalls/EmptyStringToNullSerializer.kt Codecov / codecov/patchpurchases/src/main/kotlin/com/revenuecat/purchases/paywalls/EmptyStringToNullSerializer.kt#L28
|
||
null -> encoder.encodeString("") | ||
else -> encoder.encodeString(value) | ||
Check warning on line 30 in purchases/src/main/kotlin/com/revenuecat/purchases/paywalls/EmptyStringToNullSerializer.kt Codecov / codecov/patchpurchases/src/main/kotlin/com/revenuecat/purchases/paywalls/EmptyStringToNullSerializer.kt#L30
|
||
} | ||
} | ||
} |
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
32 changes: 32 additions & 0 deletions
32
purchases/src/test/resources/paywalldata-empty-images.json
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,32 @@ | ||
{ | ||
"template_name": "1", | ||
"localized_strings": { | ||
"en_US": { | ||
"title": "Paywall", | ||
"subtitle": "Description", | ||
"call_to_action": "Purchase now", | ||
"call_to_action_with_intro_offer": "Purchase now", | ||
"offer_details": "{{ sub_price_per_month }} per month", | ||
"offer_details_with_intro_offer": "Start your {{ sub_offer_duration }} trial, then {{ sub_price_per_month }} per month" | ||
} | ||
}, | ||
"config": { | ||
"packages": ["$rc_monthly", "$rc_annual"], | ||
"images": { | ||
"header": "", | ||
"background": " ", | ||
"icon": null | ||
}, | ||
"colors": { | ||
"light": { | ||
"background": "#FFFFFF", | ||
"text_1": "#FFFFFF", | ||
"call_to_action_background": "#FFFFFF", | ||
"call_to_action_foreground": "#FFFFFF", | ||
"accent_1": "#FFFFFF" | ||
}, | ||
"dark": null | ||
} | ||
}, | ||
"asset_base_url": "https://rc-paywalls.s3.amazonaws.com" | ||
} |