Skip to content

Instantly share code, notes, and snippets.

@le0nidas
Created March 20, 2022 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save le0nidas/2a692c31ee5d6aa2f765aa2f8f3a605a to your computer and use it in GitHub Desktop.
Save le0nidas/2a692c31ee5d6aa2f765aa2f8f3a605a to your computer and use it in GitHub Desktop.
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