Skip to content

Instantly share code, notes, and snippets.

@ericntd
Last active September 9, 2021 17:06
Show Gist options
  • Save ericntd/387317b62b3f192447affc186e32b7b6 to your computer and use it in GitHub Desktop.
Save ericntd/387317b62b3f192447affc186e32b7b6 to your computer and use it in GitHub Desktop.
val viewState = MutableLiveData<ViewState>()
val actionState = SingleLiveEvent<ActionState>() // each value emit only once
init {
viewState.value = ViewState.Loading
interactor.getProfile().let { getProfileState ->
when (getProfileState) {
is GetProfileInteractor.State.Success -> {
// render updates on UI
viewState.value = ViewState.ProfileLoaded(getProfileState.profile)
}
is GetProfileInteractor.State.Failure -> {
viewState.value = ViewState.ProfileLoadFailure(getProfileState.errorMessage)
}
GetProfileInteractor.State.VerificationRequired -> {
actionState.value = ActionState.NeedsVerification
}
}
}
}
sealed class ViewState() {
object Loading: ViewState()
data class ProfileLoaded(val profile: Profile): ViewState()
data class ProfileLoadFailure(val errorMessage: String): ViewState()
}
sealed class ActionState {
object NeedsVerification : ActionState()
object NeedsLogOut: ActionState()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment