Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class TeamViewModel : ViewModel(), CoroutineScope {
- //...Rest of TeamViewModel
- fun getTeams(): LiveData<List<Team>> {
- if (!::teams.isInitialized) {
- teams = MutableLiveData()
- loadTeams()
- }
- return teams
- }
- //...Rest of TeamViewModel
- private fun loadTeams() {
- launch {
- try {
- isLoading.value = true
- val result = NetworkClient.getTeams(Dispatchers.IO)
- result.await()?.let {
- showError.value = false
- teams.value = it
- }
- } catch (e: Exception) {
- showError.value = true
- } finally {
- isLoading.value = false
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment