Last active
June 15, 2017 16:05
-
-
Save Aidanvii7/08cb7e0c6c399191d37f3fe412e242f2 to your computer and use it in GitHub Desktop.
pd2
This file contains 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
fun <T> BaseObservable.bindable(initialValue: T, propertyId: Int): BindableProperty<T> { | |
return BindableProperty<T>(initialValue, this) | |
} | |
class BindableProperty<T>(initialValue: T, | |
private val observable: BaseObservable) : ObservableProperty<T>(initialValue) { | |
private var propertyId: Int = 0 | |
override fun beforeChange(property: KProperty<*>, oldValue: T, newValue: T): Boolean { | |
return oldValue != newValue | |
} | |
override fun afterChange(property: KProperty<*>, oldValue: T, newValue: T) { | |
observable.notifyPropertyChanged(propertyId) | |
} | |
operator fun provideDelegate(observable: BaseObservable, property: KProperty<*>): BindableProperty<T> { | |
propertyId = PropertyMapper.bindableResourceIdForKProperty(property) | |
return this | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment