Skip to content

Instantly share code, notes, and snippets.

@motorro
Last active July 31, 2022 16:04
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/087bc16df053f7c983e9cf070e88421e to your computer and use it in GitHub Desktop.
Save motorro/087bc16df053f7c983e9cf070e88421e to your computer and use it in GitHub Desktop.
Item list state
class ItemListState : CommonMachineState<LceGesture, LceUiState>() {
private val items = listOf(
ItemId.LOADS_CONTENT to "Item that loads",
ItemId.FAILS_WITH_ERROR to "Item that fails to load"
)
override fun doStart() {
setUiState(LceUiState.ItemList(items.map { ItemModel(it.first, it.second) }))
}
override fun doProcess(gesture: LceGesture) = when(gesture) {
is LceGesture.ItemClicked -> onItemClicked(gesture.id)
is LceGesture.Back -> onBack()
else -> Timber.d("Unhandled gesture: %s", gesture)
}
private fun onItemClicked(id: ItemId) {
setMachineState(LoadingState(id))
}
private fun onBack() {
setMachineState(TerminatedState())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment