Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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