Last active
July 31, 2022 16:04
-
-
Save motorro/087bc16df053f7c983e9cf070e88421e to your computer and use it in GitHub Desktop.
Item list state
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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