Skip to content

Instantly share code, notes, and snippets.

@ericntd
Last active September 9, 2021 17:06
Show Gist options
  • Save ericntd/f5ac7b5c3c14b2438f1683fc07a58e52 to your computer and use it in GitHub Desktop.
Save ericntd/f5ac7b5c3c14b2438f1683fc07a58e52 to your computer and use it in GitHub Desktop.
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setUpObservation()
}
private fun setUpObservation() {
viewModel.viewState.observe(this, Observer { state ->
when (state) {
is ProfileViewModel.ViewState.ProfileLoaded -> {
// render avatar, user name, photos etc.
textViewName.text = state.profile.name
// ...
}
is ProfileViewModel.ViewState.ProfileLoadFailure -> {
// render error layout with icon, error messages
}
ProfileViewModel.ViewState.Loading -> {
// render loading animation
}
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment