Guest User

Untitled

a guest
Jan 20th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. package id.ihwan.aac.viewmodel
  2.  
  3. import android.app.Application
  4. import androidx.lifecycle.AndroidViewModel
  5. import androidx.lifecycle.MutableLiveData
  6. import id.ihwan.aac.model.MovieResponse
  7. import id.ihwan.aac.network.MainRepository
  8.  
  9. class MainViewModel(application: Application): AndroidViewModel(application) {
  10.  
  11. private val repository = MainRepository()
  12.  
  13. var movies : MutableLiveData<MovieResponse> = MutableLiveData()
  14. var error: MutableLiveData<Throwable> = MutableLiveData()
  15.  
  16. fun getMovie(){
  17. repository.requestMovie({
  18. movies.postValue(it)
  19. },{
  20. error.postValue(it)
  21. })
  22. }
  23.  
  24. override fun onCleared() {
  25. super.onCleared()
  26. repository.onDestroy()
  27. }
  28. }
Add Comment
Please, Sign In to add comment