From ed5b7ed9fbb8e5596e833278f3e2715dc2e2579c Mon Sep 17 00:00:00 2001 From: Hai Zhang Date: Sun, 13 Oct 2024 23:07:59 -0700 Subject: [PATCH] Refactor: Use appClassLoader instead of reified generics in ParcelExtensions And add Parcel.readValue(). --- .../android/files/util/ParcelExtensions.kt | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/me/zhanghai/android/files/util/ParcelExtensions.kt b/app/src/main/java/me/zhanghai/android/files/util/ParcelExtensions.kt index 4c25ff774..83ad45c3c 100644 --- a/app/src/main/java/me/zhanghai/android/files/util/ParcelExtensions.kt +++ b/app/src/main/java/me/zhanghai/android/files/util/ParcelExtensions.kt @@ -7,24 +7,26 @@ package me.zhanghai.android.files.util import android.os.Parcel import android.os.Parcelable -import me.zhanghai.android.files.compat.readParcelableListCompat import kotlin.contracts.ExperimentalContracts import kotlin.contracts.InvocationKind import kotlin.contracts.contract +import me.zhanghai.android.files.app.appClassLoader +import me.zhanghai.android.files.compat.readParcelableListCompat -inline fun Parcel.readParcelable(): T? = - readParcelable(T::class.java.classLoader) +@Suppress("DEPRECATION") +fun Parcel.readParcelable(): T? = readParcelable(appClassLoader) fun Parcel.readParcelableListCompat(classLoader: ClassLoader?): List = readParcelableListCompat(mutableListOf(), classLoader) -inline fun > Parcel.readParcelableListCompat( - list: L -): L = readParcelableListCompat(list, E::class.java.classLoader) +fun > Parcel.readParcelableListCompat(list: L): L = + readParcelableListCompat(list, appClassLoader) -inline fun Parcel.readParcelableListCompat(): List = +fun Parcel.readParcelableListCompat(): List = readParcelableListCompat(mutableListOf()) +@Suppress("UNCHECKED_CAST") fun Parcel.readValue(): T? = readValue(appClassLoader) as T? + @OptIn(ExperimentalContracts::class) inline fun Parcel.use(block: (Parcel) -> R): R { contract {