LibreTube/app/src/main/java/com/github/libretube/extensions/Bundle.kt

23 lines
670 B
Kotlin
Raw Normal View History

2023-06-17 07:57:56 +05:30
package com.github.libretube.extensions
import android.os.Bundle
import android.os.Parcelable
import androidx.annotation.OptIn
import androidx.core.os.BuildCompat
2023-06-17 07:57:56 +05:30
import androidx.core.os.BundleCompat
import java.io.Serializable
2023-06-17 07:57:56 +05:30
inline fun <reified T : Parcelable> Bundle.parcelable(key: String?): T? {
return BundleCompat.getParcelable(this, key, T::class.java)
}
@OptIn(BuildCompat.PrereleaseSdkCheck::class)
inline fun <reified T : Serializable> Bundle.serializable(key: String): T? {
return if (BuildCompat.isAtLeastU()) {
getSerializable(key, T::class.java)
} else {
@Suppress("DEPRECATION")
getSerializable(key) as? T
}
}