Skip to content

Commit

Permalink
Update API where getParcelableExtra method is used (#1197)
Browse files Browse the repository at this point in the history
* Update API where getParcelableExtra method is used

* update CHANGELOG.md
  • Loading branch information
saperi22 authored Oct 29, 2024
1 parent a7e5681 commit 7a7124e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
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
}
}

0 comments on commit 7a7124e

Please sign in to comment.