refactor: Remove BuildCompat calls

This commit is contained in:
Isira Seneviratne 2023-09-07 19:31:59 +05:30
parent d808a48529
commit ba2b918ebc
2 changed files with 4 additions and 8 deletions

View File

@ -1,9 +1,8 @@
package com.github.libretube.extensions package com.github.libretube.extensions
import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.os.Parcelable import android.os.Parcelable
import androidx.annotation.OptIn
import androidx.core.os.BuildCompat
import androidx.core.os.BundleCompat import androidx.core.os.BundleCompat
import java.io.Serializable import java.io.Serializable
@ -11,9 +10,8 @@ inline fun <reified T : Parcelable> Bundle.parcelable(key: String?): T? {
return BundleCompat.getParcelable(this, key, T::class.java) return BundleCompat.getParcelable(this, key, T::class.java)
} }
@OptIn(BuildCompat.PrereleaseSdkCheck::class)
inline fun <reified T : Serializable> Bundle.serializable(key: String): T? { inline fun <reified T : Serializable> Bundle.serializable(key: String): T? {
return if (BuildCompat.isAtLeastU()) { return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
getSerializable(key, T::class.java) getSerializable(key, T::class.java)
} else { } else {
@Suppress("DEPRECATION") @Suppress("DEPRECATION")

View File

@ -1,19 +1,17 @@
package com.github.libretube.extensions package com.github.libretube.extensions
import android.content.Intent import android.content.Intent
import android.os.Build
import android.os.Parcelable import android.os.Parcelable
import androidx.annotation.OptIn
import androidx.core.content.IntentCompat import androidx.core.content.IntentCompat
import androidx.core.os.BuildCompat
import java.io.Serializable import java.io.Serializable
inline fun <reified T : Parcelable> Intent.parcelableExtra(name: String?): T? { inline fun <reified T : Parcelable> Intent.parcelableExtra(name: String?): T? {
return IntentCompat.getParcelableExtra(this, name, T::class.java) return IntentCompat.getParcelableExtra(this, name, T::class.java)
} }
@OptIn(BuildCompat.PrereleaseSdkCheck::class)
inline fun <reified T : Serializable> Intent.serializableExtra(name: String?): T? { inline fun <reified T : Serializable> Intent.serializableExtra(name: String?): T? {
return if (BuildCompat.isAtLeastU()) { return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
getSerializableExtra(name, T::class.java) getSerializableExtra(name, T::class.java)
} else { } else {
@Suppress("DEPRECATION") @Suppress("DEPRECATION")