Last active
September 9, 2021 17:06
-
-
Save ericntd/387317b62b3f192447affc186e32b7b6 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
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