I'm using this data class to store the form data `...
# android
t
I'm using this data class to store the form data
Copy code
data class FormData(
    private var _email: String = "",
    private var _password: String = "",
    private var _isAllFieldsValid: Boolean = false
) : BaseObservable() {
    var email: String
        @Bindable get() = _email
        set(value) {
            _email = value
            notifyPropertyChanged(BR.email)
        }

    var password: String
        @Bindable get() = _password
        set(value) {
            _password = value
            notifyPropertyChanged(BR.password)
        }

    // I want this function to be notifed for both email and password changes
    fun onValuesChanged() {
        
    }
}
Is there any way to achieve this rather than callback or observer?
s
Kotlin has
observable
property delegate, probably that will work for you
p
Just call the method in setters
Copy code
var email: String
        @Bindable get() = _email
        set(value) {
            _email = value
            onValuesChanged()
            notifyPropertyChanged(BR.email)
        }

    var password: String
        @Bindable get() = _password
        set(value) {
            _password = value
            onValuesChanged()
            notifyPropertyChanged(BR.password)
        }
☝️ 1