Last active
September 9, 2021 17:06
-
-
Save ericntd/d6b2e4667971fffaccce6457c232c8fe 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>() | |
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) | |
} | |
} | |
} | |
} | |
sealed class ViewState() { | |
object Loading: ViewState() | |
data class ProfileLoaded(val profile: Profile): ViewState() | |
data class ProfileLoadFailure(val errorType: Int): ViewState() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment