Created
April 21, 2020 10:31
-
-
Save PatilShreyas/28848bbb3c681022583c3a47a4d7a872 to your computer and use it in GitHub Desktop.
This file contains 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 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