From 2bd84636d67f4c5ed77843cfd8b58bef5177c04e Mon Sep 17 00:00:00 2001 From: Ax333l Date: Wed, 15 Nov 2023 21:32:54 +0100 Subject: [PATCH] fix: parcel error for nullable types --- .../ui/viewmodel/PatchesSelectorViewModel.kt | 3 ++- .../manager/util/saver/NullableSaver.kt | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/app/revanced/manager/ui/viewmodel/PatchesSelectorViewModel.kt b/app/src/main/java/app/revanced/manager/ui/viewmodel/PatchesSelectorViewModel.kt index c9bcfdb9..f3df1c4d 100644 --- a/app/src/main/java/app/revanced/manager/ui/viewmodel/PatchesSelectorViewModel.kt +++ b/app/src/main/java/app/revanced/manager/ui/viewmodel/PatchesSelectorViewModel.kt @@ -25,6 +25,7 @@ import app.revanced.manager.ui.model.BundleInfo.Extensions.toPatchSelection import app.revanced.manager.ui.model.SelectedApp import app.revanced.manager.util.Options import app.revanced.manager.util.PatchesSelection +import app.revanced.manager.util.saver.Nullable import app.revanced.manager.util.saver.nullableSaver import app.revanced.manager.util.saver.persistentMapSaver import app.revanced.manager.util.saver.persistentSetSaver @@ -210,7 +211,7 @@ class PatchesSelectorViewModel(input: Params) : ViewModel(), KoinComponent { ) ) - private val patchesSaver: Saver> = + private val patchesSaver: Saver> = nullableSaver(persistentMapSaver(valueSaver = persistentSetSaver())) } diff --git a/app/src/main/java/app/revanced/manager/util/saver/NullableSaver.kt b/app/src/main/java/app/revanced/manager/util/saver/NullableSaver.kt index 6116722a..a94a5388 100644 --- a/app/src/main/java/app/revanced/manager/util/saver/NullableSaver.kt +++ b/app/src/main/java/app/revanced/manager/util/saver/NullableSaver.kt @@ -1,22 +1,24 @@ package app.revanced.manager.util.saver +import android.os.Parcelable import androidx.compose.runtime.saveable.Saver -import java.util.Optional -import kotlin.jvm.optionals.getOrNull +import kotlinx.parcelize.Parcelize +import kotlinx.parcelize.RawValue + +@Parcelize +class Nullable(val inner: @RawValue T?) : Parcelable /** * Creates a saver that can save nullable versions of types that have custom savers. */ -fun nullableSaver(baseSaver: Saver): Saver> = +fun nullableSaver(baseSaver: Saver): Saver> = Saver( save = { value -> with(baseSaver) { - save(value ?: return@Saver Optional.empty()) - }?.let { - Optional.of(it) - } + save(value ?: return@Saver Nullable(null)) + }?.let(::Nullable) }, restore = { - it.getOrNull()?.let(baseSaver::restore) + it.inner?.let(baseSaver::restore) } ) \ No newline at end of file