Make Info name nullable

This commit is contained in:
vfsfitvnm 2022-10-07 11:41:09 +02:00
parent db4d4e4cae
commit a45270c54a
2 changed files with 4 additions and 6 deletions

View file

@ -2,5 +2,5 @@ package it.vfsfitvnm.vimusic.models
data class Info( data class Info(
val id: String, val id: String,
val name: String val name: String?
) )

View file

@ -4,12 +4,10 @@ import androidx.compose.runtime.saveable.Saver
import androidx.compose.runtime.saveable.SaverScope import androidx.compose.runtime.saveable.SaverScope
import it.vfsfitvnm.vimusic.models.Info import it.vfsfitvnm.vimusic.models.Info
object InfoSaver : Saver<Info, List<String>> { object InfoSaver : Saver<Info, List<String?>> {
override fun SaverScope.save(value: Info): List<String> = listOf(value.id, value.name) override fun SaverScope.save(value: Info) = listOf(value.id, value.name)
override fun restore(value: List<String>): Info? { override fun restore(value: List<String?>) = Info(id = value[0] as String, name = value[1])
return if (value.size == 2) Info(id = value[0], name = value[1]) else null
}
} }
val InfoListSaver = listSaver(InfoSaver) val InfoListSaver = listSaver(InfoSaver)