Skip to content

Instantly share code, notes, and snippets.

@ericntd
Last active September 9, 2021 17:06
Show Gist options
  • Save ericntd/d6b2e4667971fffaccce6457c232c8fe to your computer and use it in GitHub Desktop.
Save ericntd/d6b2e4667971fffaccce6457c232c8fe to your computer and use it in GitHub Desktop.
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