Skip to content

Instantly share code, notes, and snippets.

@n-belokopytov
Created April 16, 2018 15:39
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 n-belokopytov/f4628408dd0ce106eb102a517593849d to your computer and use it in GitHub Desktop.
Save n-belokopytov/f4628408dd0ce106eb102a517593849d to your computer and use it in GitHub Desktop.
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