diff --git a/app/src/main/java/com/github/libretube/extensions/Bundle.kt b/app/src/main/java/com/github/libretube/extensions/Bundle.kt index 52ca984c2..e5da96054 100644 --- a/app/src/main/java/com/github/libretube/extensions/Bundle.kt +++ b/app/src/main/java/com/github/libretube/extensions/Bundle.kt @@ -5,16 +5,21 @@ import android.os.Bundle import android.os.Parcelable import androidx.core.os.BundleCompat import java.io.Serializable +import kotlin.reflect.safeCast inline fun Bundle.parcelable(key: String?): T? { return BundleCompat.getParcelable(this, key, T::class.java) } -inline fun Bundle.serializable(key: String): T? { +inline fun Bundle.serializable(key: String?): T? { + return getSerializable(this, key, T::class.java) +} + +fun getSerializable(bundle: Bundle, key: String?, clazz: Class): T? { return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { - getSerializable(key, T::class.java) + bundle.getSerializable(key, clazz) } else { @Suppress("DEPRECATION") - getSerializable(key) as? T + clazz.kotlin.safeCast(bundle.getSerializable(key)) } } diff --git a/app/src/main/java/com/github/libretube/extensions/Intent.kt b/app/src/main/java/com/github/libretube/extensions/Intent.kt index b2b3011e8..dfc8f4813 100644 --- a/app/src/main/java/com/github/libretube/extensions/Intent.kt +++ b/app/src/main/java/com/github/libretube/extensions/Intent.kt @@ -11,10 +11,5 @@ inline fun Intent.parcelableExtra(name: String?): T? { } inline fun Intent.serializableExtra(name: String?): T? { - return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { - getSerializableExtra(name, T::class.java) - } else { - @Suppress("DEPRECATION") - getSerializableExtra(name) as? T - } + return extras?.serializable(name) }