Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // interface for view/activity/fragment/whatever, can be delegated also.
- interface LoginAcceptable {
- fun onChangeLocation()
- fun onLoginSuccess()
- fun onAppUpdateAvailable()
- fun renderLocationConfig(configuration: LocationConfiguration)
- }
- // alias for short name in single livedata
- typealias LoginEvent = LoginAcceptable.() -> Unit
- // single livedata in view model
- val ui = MutableLiveData<LoginEvent>()
- // just syntax sugar
- operator fun <T> MutableLiveData<T>.invoke(function: T) {
- postValue(function)
- }
- // viewmodel function
- fun onLogin() {
- // call to this single livedata
- ui {
- onLoginSuccess()
- onAppUpdateAvailable()
- }
- }
- // observe in your view
- viewModel.ui.observe { it(this) }
Advertisement
Add Comment
Please, Sign In to add comment