Last active
January 2, 2021 14:28
-
-
Save carotkut94/2ba06c99e3d9552ee4571c4646eca719 to your computer and use it in GitHub Desktop.
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
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) | |
} | |
} |
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
file name is .java but its Kotlin :)