Skip to content

Instantly share code, notes, and snippets.

@PatilShreyas
Created April 21, 2020 10:31
Show Gist options
  • Save PatilShreyas/28848bbb3c681022583c3a47a4d7a872 to your computer and use it in GitHub Desktop.
Save PatilShreyas/28848bbb3c681022583c3a47a4d7a872 to your computer and use it in GitHub Desktop.
private suspend fun addPost(post: Post) {
viewModel.addPost(post).collect { state ->
when (state) {
is State.Loading -> {
showToast("Loading")
binding.buttonAdd.isEnabled = false
}
is State.Success -> {
showToast("Posted")
binding.fieldPostContent.setText("")
binding.buttonAdd.isEnabled = true
}
is State.Failed -> {
showToast("Failed! ${state.message}")
binding.buttonAdd.isEnabled = true
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment