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 c9bcfdb998..f3df1c4d1f 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 6116722aa0..a94a53886c 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