Skip to content

Instantly share code, notes, and snippets.

@ericntd
Last active September 9, 2021 17:06
Show Gist options
  • Save ericntd/a76147651e102085923a9676a15a3d49 to your computer and use it in GitHub Desktop.
Save ericntd/a76147651e102085923a9676a15a3d49 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.
}
is ProfileViewModel.ViewState.ProfileLoadFailure -> TODO()
ProfileViewModel.ViewState.Loading -> {
// render loading animation
}
}
})
viewModel.actionState.observe(this, Observer { state ->
when (state) {
ProfileViewModel.ActionState.NeedsVerification -> {
// navigation to Verification screen
}
ProfileViewModel.ActionState.NeedsLogOut -> {
// Clear data, finish this activity and navigate to LogIn screen?
}
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment