Guest User

Untitled

a guest
Jan 19th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. class TeamViewModel : ViewModel(), CoroutineScope {
  2. //...Rest of TeamViewModel
  3. fun getTeams(): LiveData<List<Team>> {
  4. if (!::teams.isInitialized) {
  5. teams = MutableLiveData()
  6. loadTeams()
  7. }
  8.  
  9. return teams
  10. }
  11.  
  12. //...Rest of TeamViewModel
  13. private fun loadTeams() {
  14. launch {
  15. try {
  16. isLoading.value = true
  17. val result = NetworkClient.getTeams(Dispatchers.IO)
  18. result.await()?.let {
  19. showError.value = false
  20. teams.value = it
  21. }
  22. } catch (e: Exception) {
  23. showError.value = true
  24. } finally {
  25. isLoading.value = false
  26. }
  27. }
  28. }
  29. }
Add Comment
Please, Sign In to add comment