Skip to content

Instantly share code, notes, and snippets.

@motorro
Created July 31, 2022 17:26
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/7baf8dff44e2c400039f2b4dc9889c38 to your computer and use it in GitHub Desktop.
Save motorro/7baf8dff44e2c400039f2b4dc9889c38 to your computer and use it in GitHub Desktop.
LCE view
@Composable
fun LceScreen(onExit: @Composable () -> Unit) {
val model: LceViewModel = viewModel()
val state = model.state.collectAsState(LceUiState.Loading)
BackHandler(onBack = { model.process(Back) })
Scaffold(
modifier = Modifier.fillMaxSize(),
backgroundColor = MaterialTheme.colors.background,
topBar = {
TopAppBar(
title = { Text(stringResource(R.string.title)) },
navigationIcon = {
IconButton(onClick = { model.process(Back) }) {
Icon(
imageVector = Icons.Filled.ArrowBack,
contentDescription = "Back",
tint = Color.White
)
}
}
)
}
) {
when (val uiState = state.value) {
LceUiState.Loading -> Loading()
is LceUiState.ItemList -> ItemList(
state = uiState,
onItemClicked = { model.process(ItemClicked(it)) }
)
is LceUiState.Error -> LoadError(
state = uiState,
onRetry = { model.process(Retry) },
onBack = { model.process(Back) },
onExit = { model.process(Exit) }
)
is LceUiState.Item -> ItemDetails(state = uiState)
LceUiState.Terminated -> onExit()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment