Skip to content

Instantly share code, notes, and snippets.

@humbledroid
Last active January 2, 2021 14:28
Show Gist options
  • Select an option

  • Save humbledroid/2ba06c99e3d9552ee4571c4646eca719 to your computer and use it in GitHub Desktop.

Select an option

Save humbledroid/2ba06c99e3d9552ee4571c4646eca719 to your computer and use it in GitHub Desktop.
import android.app.Application
import androidx.databinding.Observable
import androidx.databinding.PropertyChangeRegistry
import androidx.lifecycle.AndroidViewModel
abstract class ObservableViewModel(app: Application): AndroidViewModel(app), Observable {
@delegate:Transient
private val mCallBacks: PropertyChangeRegistry by lazy { PropertyChangeRegistry() }
override fun addOnPropertyChangedCallback(callback: Observable.OnPropertyChangedCallback) {
mCallBacks.add(callback)
}
override fun removeOnPropertyChangedCallback(callback: Observable.OnPropertyChangedCallback) {
mCallBacks.remove(callback)
}
fun notifyChange() {
mCallBacks.notifyChange(this, 0)
}
fun notifyChange(viewId:Int){
mCallBacks.notifyChange(this, viewId)
}
}
@humbledroid

Copy link
Copy Markdown
Author

Thanks for point that out, fixed it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment