2023-06-17 07:57:56 +05:30
|
|
|
package com.github.libretube.extensions
|
|
|
|
|
2023-09-07 19:31:59 +05:30
|
|
|
import android.os.Build
|
2023-06-17 07:57:56 +05:30
|
|
|
import android.os.Bundle
|
|
|
|
import android.os.Parcelable
|
|
|
|
import androidx.core.os.BundleCompat
|
2023-09-04 04:52:23 +05:30
|
|
|
import java.io.Serializable
|
2023-09-09 06:41:32 +05:30
|
|
|
import kotlin.reflect.safeCast
|
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)
|
|
|
|
}
|
2023-09-04 04:52:23 +05:30
|
|
|
|
2024-01-23 16:46:35 +05:30
|
|
|
inline fun <reified T : Parcelable> Bundle.parcelableArrayList(key: String?): ArrayList<T>? {
|
|
|
|
return BundleCompat.getParcelableArrayList(this, key, T::class.java)
|
|
|
|
}
|
|
|
|
|
2023-09-09 06:41:32 +05:30
|
|
|
inline fun <reified T : Serializable> Bundle.serializable(key: String?): T? {
|
|
|
|
return getSerializable(this, key, T::class.java)
|
|
|
|
}
|
|
|
|
|
|
|
|
fun <T : Serializable> getSerializable(bundle: Bundle, key: String?, clazz: Class<T>): T? {
|
2023-09-07 19:31:59 +05:30
|
|
|
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
|
2023-09-09 06:41:32 +05:30
|
|
|
bundle.getSerializable(key, clazz)
|
2023-09-04 04:52:23 +05:30
|
|
|
} else {
|
|
|
|
@Suppress("DEPRECATION")
|
2023-09-09 06:41:32 +05:30
|
|
|
clazz.kotlin.safeCast(bundle.getSerializable(key))
|
2023-09-04 04:52:23 +05:30
|
|
|
}
|
|
|
|
}
|