Created
July 31, 2022 17:26
-
-
Save motorro/7baf8dff44e2c400039f2b4dc9889c38 to your computer and use it in GitHub Desktop.
LCE view
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
@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