From acf73aab98e0fa4bb63a2bea6305aebaa1d2ad8c Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Mon, 12 Aug 2024 06:41:22 +0530 Subject: [PATCH] refactor: Simplify serializable extensions --- .../java/com/github/libretube/extensions/Bundle.kt | 13 +------------ .../java/com/github/libretube/extensions/Intent.kt | 2 +- 2 files changed, 2 insertions(+), 13 deletions(-) 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 5c011fdbf..23b3797b3 100644 --- a/app/src/main/java/com/github/libretube/extensions/Bundle.kt +++ b/app/src/main/java/com/github/libretube/extensions/Bundle.kt @@ -1,11 +1,9 @@ package com.github.libretube.extensions -import android.os.Build 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) @@ -16,14 +14,5 @@ inline fun Bundle.parcelableArrayList(key: String?): Ar } 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) { - bundle.getSerializable(key, clazz) - } else { - @Suppress("DEPRECATION") - clazz.kotlin.safeCast(bundle.getSerializable(key)) - } + return BundleCompat.getSerializable(this, key, T::class.java) } 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 abf7b9ac6..79efbceda 100644 --- a/app/src/main/java/com/github/libretube/extensions/Intent.kt +++ b/app/src/main/java/com/github/libretube/extensions/Intent.kt @@ -10,5 +10,5 @@ inline fun Intent.parcelableExtra(name: String?): T? { } inline fun Intent.serializableExtra(name: String?): T? { - return extras?.serializable(name) + return IntentCompat.getSerializableExtra(this, name, T::class.java) }