Skip to content

Instantly share code, notes, and snippets.

@marcinOz
Created June 14, 2018 10:54
Show Gist options
  • Save marcinOz/9a88d99bfc43563c99285234de47d458 to your computer and use it in GitHub Desktop.
Save marcinOz/9a88d99bfc43563c99285234de47d458 to your computer and use it in GitHub Desktop.
class MovieListViewModel @Inject constructor(private val dataProvider: DataProvider) : ViewModel() {
val movieDiscover = MutableLiveData<ResourceState>()
fun fetchMovieDiscover() {
movieDiscover.postValue(LoadingState())
dataProvider.getMovieDiscover().subscribeBy(
onSuccess = { result ->
if (result.isEmpty()) movieDiscover.postValue(EmptyState())
else movieDiscover.postValue(PopulatedState(result))
},
onError = { error -> movieDiscover.postValue(ErrorState(error.message)) }
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment