Skip to content

Instantly share code, notes, and snippets.

@le0nidas
Created March 20, 2022 12:08
Embed
What would you like to do?
companion object : Parceler<Task> {
override fun create(parcel: Parcel): Task {
return Task(
//...
parcel.readStatus()
)
}
override fun Task.write(parcel: Parcel, flags: Int) {
with(parcel) {
//...
writeStatus(status)
}
}
}
fun Parcel.readStatus(): Status {
return readLong().let { value ->
when (value) {
0L -> NotStarted
1L -> InProgress
else -> Completed(LocalDate.ofEpochDay(value))
}
}
}
fun Parcel.writeStatus(status: Status) {
when (status) {
is Completed -> writeLong(status.completedAt.toEpochDay())
InProgress -> writeLong(1)
NotStarted -> writeLong(0)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment