Skip to content

Commit

Permalink
Use ParcelCompat methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
Isira-Seneviratne committed Jun 16, 2023
1 parent cd23b04 commit 9730e70
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/Bundle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import android.os.Parcel
import android.os.Parcelable
import androidx.core.content.IntentCompat
import androidx.core.os.BundleCompat
import androidx.core.os.ParcelCompat
import androidx.lifecycle.SavedStateHandle
import org.koitharu.kotatsu.core.model.parcelable.ParcelableMangaTags
import java.io.Serializable

// https://issuetracker.google.com/issues/240585930
Expand All @@ -36,11 +36,11 @@ inline fun <reified T : Serializable> Bundle.getSerializableCompat(key: String):
}

inline fun <reified T : Parcelable> Parcel.readParcelableCompat(): T? {
return readParcelable(ParcelableMangaTags::class.java.classLoader) as T?
return ParcelCompat.readParcelable(this, T::class.java.classLoader, T::class.java)
}

inline fun <reified T : Serializable> Parcel.readSerializableCompat(): T? {
return readSerializable() as T?
return ParcelCompat.readSerializable(this, T::class.java.classLoader, T::class.java)
}

inline fun <reified T : Serializable> Bundle.requireSerializable(key: String): T {
Expand All @@ -49,12 +49,6 @@ inline fun <reified T : Serializable> Bundle.requireSerializable(key: String): T
}
}

inline fun <reified T : Parcelable> Bundle.requireParcelable(key: String): T {
return checkNotNull(getParcelableCompat(key)) {
"Parcelable of type \"${T::class.java.name}\" not found at \"$key\""
}
}

fun <T> SavedStateHandle.require(key: String): T {
return checkNotNull(get(key)) {
"Value $key not found in SavedStateHandle or has a wrong type"
Expand Down

0 comments on commit 9730e70

Please sign in to comment.