Last active
April 30, 2018 21:00
-
-
Save kibotu/30688a3d09cad0ecbb932c05b79fa482 to your computer and use it in GitHub Desktop.
RealmListParcelConverter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open class RealmListParcelConverter<T> : TypeRangeParcelConverter<RealmList<T>, RealmList<T>> where T : RealmObject { | |
override fun toParcel(input: RealmList<T>?, parcel: Parcel) { | |
if (input == null) { | |
parcel.writeInt(NULL) | |
} else { | |
parcel.writeInt(input.size) | |
for (item in input) { | |
parcel.writeParcelable(Parcels.wrap(item), 0) | |
} | |
} | |
} | |
override fun fromParcel(parcel: Parcel): RealmList<T> { | |
val size = parcel.readInt() | |
val list = RealmList<T>() | |
for (i in 0 until size) { | |
val parcelable = parcel.readParcelable<Parcelable>(javaClass.classLoader) | |
list.add(Parcels.unwrap<T>(parcelable)) | |
} | |
return list | |
} | |
companion object { | |
private const val NULL = -1 | |
} | |
} |
Author
kibotu
commented
Feb 2, 2018
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment