Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
State Machine in View with a Sealed Class from Kotlin
override fun onStart() {
viewModel.tabbedListLiveData.observe(this, Observer {
when (it) {
is ErrorState -> {
showProgress(false)
showErrorView(it.errorMessage, it.errorColor)
}
is InProgressState -> showProgress(true)
is OfflineState -> {
showProgress(false)
displayList(it.listElements)
hideTabs()
}
is ListState -> {
showProgress(false)
displayList(it.listElements, it.totalItems)
displayTabs(it.currentTabId, it.tabs)
}
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment