Last active
December 21, 2019 16:32
-
-
Save gastsail/66a88c085d3d6567a9b231e1d455177a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private val viewModel by lazy { ViewModelProviders.of(this, EventsVMFactory(EventsImpl(EventsRepoImpl()))).get(EventsViewModel::class.java) } | |
... | |
override fun onCreate() { | |
viewModel.fetchEventList.observe(this, Observer { | |
when(it){ | |
is Resource.Loading -> { | |
// Before try catch in viewmodel we can use emit(Resource.Loading()) to tell the view we started fetching results and this will be triggered | |
} | |
is Resource.Success -> { | |
// we get the list data with it.data | |
} | |
is Resource.Failure-> { | |
//Handle the failure | |
Toast.makeText(this,"An error has ocurred:${it.throwable.message}",Toast.LENGTH_SHORT).show() | |
} | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment