Skip to content

Instantly share code, notes, and snippets.

@brunogabriel
Created October 5, 2021 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brunogabriel/4a0a21451407c55bc609d4f3b349a801 to your computer and use it in GitHub Desktop.
Save brunogabriel/4a0a21451407c55bc609d4f3b349a801 to your computer and use it in GitHub Desktop.
Método getPosts
fun takePosts() {
compositeDisposable + useCase.takePosts()
.subscribeOn(appSchedulers.io)
.observeOn(appSchedulers.main)
.doOnSubscribe { _displayingView.value = DisplayingView.Loading.ordinal }
.subscribeBy(onError = {
_displayingView.value = DisplayingView.Error.ordinal
_errorMessage.value = it.message ?: DEFAULT_ERROR_MESSAGE
}, onSuccess = { result ->
if (result.isNotEmpty()) {
_postsResult.value = result
_displayingView.value = DisplayingView.Success.ordinal
} else {
_displayingView.value = DisplayingView.Empty.ordinal
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment