Skip to content

Instantly share code, notes, and snippets.

@akexorcist
Last active November 1, 2017 03:20
Show Gist options
  • Save akexorcist/af59afb306bdf2c05de9e7b0a2c3a7ca to your computer and use it in GitHub Desktop.
Save akexorcist/af59afb306bdf2c05de9e7b0a2c3a7ca to your computer and use it in GitHub Desktop.
Simple parcelable model class
open class BaseItem(open var type: Int) : Parcelable {
constructor(parcel: Parcel) : this(
type = parcel.readInt())
override fun writeToParcel(parcel: Parcel, flags: Int) {
with(parcel) {
writeInt(type)
}
}
...
}
class ContentItem : BaseItem {
var text: String
var title: String
constructor(title: String, text: String) : super(ItemType.TYPE_VIDEO) {
this.title = title
this.text = text
}
constructor(parcel: Parcel) : super(parcel) {
title = parcel.readString()
text = parcel.readString()
}
override fun writeToParcel(parcel: Parcel, flags: Int) {
super.writeToParcel(parcel, flags)
with(parcel) {
writeString(title)
writeString(text)
}
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment