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

Code quality: use compat functions for Android 13 type extras #4501

Merged
merged 1 commit into from
Jul 10, 2024

Conversation

jpelgrom
Copy link
Member

@jpelgrom jpelgrom commented Jul 9, 2024

Summary

While reviewing the recent camera widget PR I noticed the following nice inline function, which I wanted to add/use in other places where we currently have an if/else for the type in extras:

private inline fun <reified T : Serializable> Bundle.getSerializableCompat(key: String): T? {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
getSerializable(key, T::class.java)
} else {
@Suppress("DEPRECATION")
getSerializable(key) as? T
}
}

It turns out Google was one step ahead of us and actually added compat classes that do this, so in this PR all relevant usages (including the camera widget inline function) are replaced with the compat functions, to clean up the code a bit.

Screenshots

n/a

Link to pull request in Documentation repository

n/a

Any other notes

Copy link
Member

@dshokouhi dshokouhi left a comment

Choose a reason for hiding this comment

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

Wow thats nice and clean!

@jpelgrom jpelgrom merged commit e838330 into home-assistant:master Jul 10, 2024
4 checks passed
@jpelgrom jpelgrom deleted the compat-serializable branch July 10, 2024 04:47
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