Fix getParcelableCompat extensions
This commit is contained in:
@@ -24,7 +24,6 @@ import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.coroutineScope
|
||||
import androidx.work.CoroutineWorker
|
||||
import com.google.android.material.elevation.ElevationOverlayProvider
|
||||
import kotlin.math.roundToLong
|
||||
import kotlinx.coroutines.channels.awaitClose
|
||||
import kotlinx.coroutines.channels.trySendBlocking
|
||||
import kotlinx.coroutines.delay
|
||||
@@ -37,6 +36,7 @@ import okio.IOException
|
||||
import org.json.JSONException
|
||||
import org.koitharu.kotatsu.BuildConfig
|
||||
import org.koitharu.kotatsu.utils.InternalResourceHelper
|
||||
import kotlin.math.roundToLong
|
||||
|
||||
val Context.activityManager: ActivityManager?
|
||||
get() = getSystemService(ACTIVITY_SERVICE) as? ActivityManager
|
||||
|
||||
@@ -1,47 +1,41 @@
|
||||
@file:Suppress("DEPRECATION")
|
||||
|
||||
package org.koitharu.kotatsu.utils.ext
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import org.koitharu.kotatsu.core.model.parcelable.ParcelableMangaTags
|
||||
import java.io.Serializable
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
// https://issuetracker.google.com/issues/240585930
|
||||
|
||||
inline fun <reified T : Parcelable> Bundle.getParcelableCompat(key: String): T? {
|
||||
if (!containsKey(key)) {
|
||||
return null
|
||||
}
|
||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
getParcelable(key, T::class.java)
|
||||
} else {
|
||||
getParcelable(key) as? T
|
||||
}
|
||||
return getParcelable(key) as T?
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
inline fun <reified T : Parcelable> Intent.getParcelableExtraCompat(key: String): T? {
|
||||
if (!hasExtra(key)) {
|
||||
return null
|
||||
}
|
||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
getParcelableExtra(key, T::class.java)
|
||||
} else {
|
||||
getParcelableExtra(key) as? T
|
||||
}
|
||||
return getParcelableExtra(key) as T?
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
inline fun <reified T : Serializable> Bundle.getSerializableCompat(key: String): T? {
|
||||
if (!containsKey(key)) {
|
||||
return null
|
||||
}
|
||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
getSerializable(key, T::class.java)
|
||||
} else {
|
||||
getSerializable(key) as? T
|
||||
getSerializable(key) as T?
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <reified T : Parcelable> Parcel.readParcelableCompat(): T? {
|
||||
return readParcelable(ParcelableMangaTags::class.java.classLoader) as T?
|
||||
}
|
||||
|
||||
inline fun <reified T : Serializable> Parcel.readSerializableCompat(): T? {
|
||||
return readSerializable() as T?
|
||||
}
|
||||
|
||||
inline fun <reified T : Serializable> Bundle.requireSerializable(key: String): T {
|
||||
return checkNotNull(getSerializableCompat(key)) {
|
||||
"Serializable of type \"${T::class.java.name}\" not found at \"$key\""
|
||||
|
||||
Reference in New Issue
Block a user