Skip to content

Instantly share code, notes, and snippets.

@motorro
Created July 31, 2022 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save motorro/e5bf990012320bfdba62fced4d82df2f to your computer and use it in GitHub Desktop.
Save motorro/e5bf990012320bfdba62fced4d82df2f to your computer and use it in GitHub Desktop.
Load error state
class ErrorState(private val failed: ItemId, private val error: Throwable) : CommonMachineState<LceGesture, LceUiState>() {
override fun doStart() {
setUiState(LceUiState.Error(error))
}
override fun doProcess(gesture: LceGesture) = when (gesture) {
LceGesture.Back -> onBack()
LceGesture.Retry -> onRetry()
LceGesture.Exit -> onExit()
else -> Timber.d("Unhandled gesture: %s", gesture)
}
private fun onRetry() {
setMachineState(LoadingState(failed))
}
private fun onBack() {
setMachineState(ItemListState())
}
private fun onExit() {
setMachineState(TerminatedState())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment