Skip to content

Instantly share code, notes, and snippets.

@PatilShreyas
Created April 21, 2020 10:30
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 PatilShreyas/7b299785b63c53c7ee939f2fc4fcc255 to your computer and use it in GitHub Desktop.
Save PatilShreyas/7b299785b63c53c7ee939f2fc4fcc255 to your computer and use it in GitHub Desktop.
private suspend fun loadPosts() {
viewModel.getAllPosts().collect { state ->
when (state) {
is State.Loading -> {
showToast("Loading")
}
is State.Success -> {
val postText = state.data.joinToString("\n") {
"${it.postContent} ~ ${it.postAuthor}"
}
binding.textPostContent.text = postText
}
is State.Failed -> showToast("Failed! ${state.message}")
} // END when
} // END collect
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment