Skip to content
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

Update API where getParcelableExtra method is used #1197

Merged
merged 4 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## unreleased

* GooglePay
* Fix a crash being caused on API 33 devices. It is recommended that merchants not use 5.1.0 for GooglePay.
* Shopper Insights (BETA)
* For analytics, send `experiment` as a parameter to `getRecommendedPaymentMethods` method
* For analytics, send `experiment` and `paymentMethodsDisplayed` analytic metrics to FPTI via the button presented event methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,27 @@ import java.io.Serializable

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
object IntentExtensions {

/** Although the newer getParcelableExtra(key, T::class.java) was introduced in Tiramisu (API 33),
* there seems to be an issue that throws NPE. See: https://issuetracker.google.com/issues/240585930#comment6
* Suggestion is to use the older APIs for Tiramisu (API 33) instead.
*/
inline fun <reified T : Parcelable> Intent.parcelable(key: String): T? = when {
SDK_INT >= Build.VERSION_CODES.TIRAMISU -> getParcelableExtra(key, T::class.java)
SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE -> getParcelableExtra(key, T::class.java)
else -> @Suppress("DEPRECATION") getParcelableExtra(key) as? T
}

inline fun <reified T : Parcelable> Bundle.parcelable(key: String): T? = when {
SDK_INT >= Build.VERSION_CODES.TIRAMISU -> getParcelable(key, T::class.java)
SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE -> getParcelable(key, T::class.java)
else -> @Suppress("DEPRECATION") getParcelable(key) as? T
}

inline fun <reified T : Serializable> Intent.serializable(key: String): T? = when {
SDK_INT >= Build.VERSION_CODES.TIRAMISU -> getSerializableExtra(key, T::class.java)
SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE -> getSerializableExtra(key, T::class.java)
else -> @Suppress("DEPRECATION") getSerializableExtra(key) as? T
}

inline fun <reified T : Serializable> Bundle.serializable(key: String): T? = when {
SDK_INT >= Build.VERSION_CODES.TIRAMISU -> getSerializable(key, T::class.java)
SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE -> getSerializable(key, T::class.java)
else -> @Suppress("DEPRECATION") getSerializable(key) as? T
}
}
Loading