Guest User

Untitled

a guest
Jan 29th, 2020
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.60 KB | None | 0 0
  1.  
  2. //interface for view/fragment/activity/whatever
  3. interface LoginAcceptable {
  4.     fun onChangeLocation()
  5.     fun onLoginSuccess()
  6.     fun onAppUpdateAvailable()
  7.     fun renderLocationConfig(configuration: LocationConfiguration)
  8. }
  9.  
  10. // typealias for livedata
  11. typealias LoginEvent = LoginAcceptable.() -> Unit
  12.  
  13. // single livedata in viewModel
  14. val ui = MutableLiveData<LoginEvent>()
  15.  
  16. // just syntax sugar
  17. operator fun <T> MutableLiveData<T>.invoke(value: T) {
  18.     postValue(value)
  19. }
  20.  
  21.  
  22. // somewhere in ViewModel
  23. fun foo() {
  24.      ui {
  25.         onLoginSuccess()
  26.         onChangeLocation()
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment