Skip to content

Instantly share code, notes, and snippets.

@pandulapeter
Last active February 20, 2018 13:34
Show Gist options
  • Save pandulapeter/925e8d088ebdd0e17ad71c000508dc69 to your computer and use it in GitHub Desktop.
Save pandulapeter/925e8d088ebdd0e17ad71c000508dc69 to your computer and use it in GitHub Desktop.
BundleDelegate
sealed class BundleDelegate<T>(protected val key: kotlin.String) : ReadWriteProperty<Bundle, T> {
class Int(key: kotlin.String) : BundleDelegate<kotlin.Int>(key) {
override fun getValue(thisRef: Bundle, property: KProperty<*>) = thisRef.getInt(key)
override fun setValue(thisRef: Bundle, property: KProperty<*>, value: kotlin.Int) = thisRef.putInt(key, value)
}
class String(key: kotlin.String) : BundleDelegate<kotlin.String>(key) {
override fun getValue(thisRef: Bundle, property: KProperty<*>) = thisRef.getString(key)
override fun setValue(thisRef: Bundle, property: KProperty<*>, value: kotlin.String) = thisRef.putString(key, value)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment