mirror of
https://github.com/ReVanced/revanced-manager.git
synced 2024-11-10 01:01:56 +01:00
fix: parcel error for nullable types
This commit is contained in:
parent
ac561e7aca
commit
2bd84636d6
2 changed files with 12 additions and 9 deletions
|
@ -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<PersistentPatchesSelection?, Optional<PatchesSelection>> =
|
||||
private val patchesSaver: Saver<PersistentPatchesSelection?, Nullable<PatchesSelection>> =
|
||||
nullableSaver(persistentMapSaver(valueSaver = persistentSetSaver()))
|
||||
}
|
||||
|
||||
|
|
|
@ -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<T>(val inner: @RawValue T?) : Parcelable
|
||||
|
||||
/**
|
||||
* Creates a saver that can save nullable versions of types that have custom savers.
|
||||
*/
|
||||
fun <Original : Any, Saveable : Any> nullableSaver(baseSaver: Saver<Original, Saveable>): Saver<Original?, Optional<Saveable>> =
|
||||
fun <Original : Any, Saveable : Any> nullableSaver(baseSaver: Saver<Original, Saveable>): Saver<Original?, Nullable<Saveable>> =
|
||||
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)
|
||||
}
|
||||
)
|
Loading…
Reference in a new issue