Advertisement
Guest User

ViewModel

a guest
Jan 18th, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. class DetailViewModel : ViewModel() {
  2. private val repository: Repository = Repository()
  3.  
  4. private val detailLeague: MutableLiveData<ListDetailLeague> = MutableLiveData()
  5.  
  6.  
  7. fun getDetailLeague(id: Int): LiveData<ListDetailLeague> {
  8. if(detailLeague.value == null) setDataDetailLeague(id)
  9. return detailLeague
  10. }
  11.  
  12. var showLoading: MutableLiveData<Boolean> = MutableLiveData()
  13. var isError: MutableLiveData<Boolean> = MutableLiveData()
  14.  
  15. private fun setDataDetailLeague(id: Int){
  16. showLoading.value = true
  17.  
  18. repository.getDetailLeagueRepository(id, object : DetailLeagueCallback {
  19. override fun onSuccess(response: ListDetailLeague) {
  20. showLoading.value = false
  21. detailLeague.value = response
  22. }
  23.  
  24. override fun onError() {
  25. showLoading.value = false
  26. isError.value = true
  27. }
  28.  
  29. })
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement