Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements idea #32

Open
danielgomezrico opened this issue Oct 1, 2019 · 0 comments
Open

Improvements idea #32

danielgomezrico opened this issue Oct 1, 2019 · 0 comments

Comments

@danielgomezrico
Copy link

The idea was took from https://medium.com/@BladeCoder/reducing-parcelable-boilerplate-code-using-kotlin-741c3124a49a.

If you have an internal KParcelable then:

  1. You dont have to put describeContents everywhere.
interface KParcelable : Parcelable {
    override fun describeContents() = 0
    override fun writeToParcel(dest: Parcel, flags: Int)
}
  1. You can have a parcelableCreator function like:
inline fun <reified T> parcelableCreator(crossinline create: (Parcel) -> T): 
Parcelable.Creator<T> {
    return object : Parcelable.Creator<T> {
        override fun createFromParcel(source: Parcel) = create(source)
        override fun newArray(size: Int) = arrayOfNulls<T>(size)
    }
}

to write simpler creators:

companion object {
        @JvmField
        val CREATOR: Parcelable.Creator<RealEstate> = parcelableCreator(::RealEstate)
    }
@danielgomezrico danielgomezrico changed the title Improvements Improvements idea Oct 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant