Advertisement
Guest User

Untitled

a guest
Feb 3rd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.58 KB | None | 0 0
  1. class Repository {
  2.     // ....
  3.     fun login(user:String, password:String): LiveData<Status> { /* ... */ }
  4. }
  5.  
  6. class LoginViewModel : ViewModel() {
  7.  
  8.     @Inject
  9.     lateinit var repo: Repository
  10.    
  11.     private var auth = MutableLiveData<User>()
  12.     private var showErrorEvent = SingleLiveEvent<String>()
  13.     private var showSuccessEvent = SingleLiveEvent<String>()
  14.  
  15.     private val authenticationStatus = Transformations.switchMap(auth, { data ->
  16.         repo.login(data.user, data.password)
  17.     })
  18.  
  19.     // Called from UI
  20.     fun performLogin(data:Data){
  21.         auth.value = data
  22.     }
  23.  
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement