Make chat toolbar a bit more modular

This commit is contained in:
Minecon724 2025-06-22 17:59:21 +02:00
commit 5ab88d9063
Signed by untrusted user who does not match committer: m724
GPG key ID: A02E6E67AB961189
2 changed files with 44 additions and 28 deletions

View file

@ -261,7 +261,7 @@ fun ChatScreenContent(
) { ) {
ChatToolBar( ChatToolBar(
canSend = (chatComposerState.composerValue.isNotBlank() || uiState.lastResponseError != null) && !uiState.requestInProgress, canSend = (chatComposerState.composerValue.isNotBlank() || uiState.lastResponseError != null) && !uiState.requestInProgress,
canRestart = chatComposerState.composerValue.isBlank() && uiState.lastResponseError != null, willRestart = chatComposerState.composerValue.isBlank() && uiState.lastResponseError != null,
onSend = onSend, onSend = onSend,
onEmptySpaceClick = onRequestFocus onEmptySpaceClick = onRequestFocus
) )

View file

@ -26,17 +26,10 @@ import eu.m724.chatapp.R
fun ChatToolBar( fun ChatToolBar(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
canSend: Boolean, canSend: Boolean,
canRestart: Boolean, willRestart: Boolean,
onSend: () -> Unit, onSend: () -> Unit,
onEmptySpaceClick: () -> Unit onEmptySpaceClick: () -> Unit
) { ) {
val sendButtonColor by animateColorAsState(
targetValue = if (canSend) {
IconButtonDefaults.iconButtonColors().contentColor
} else {
IconButtonDefaults.iconButtonColors().disabledContentColor
}, label = "sendButtonColor"
)
ElevatedCard( ElevatedCard(
modifier = modifier, modifier = modifier,
@ -48,29 +41,52 @@ fun ChatToolBar(
.clickable(onClick = onEmptySpaceClick), .clickable(onClick = onEmptySpaceClick),
horizontalArrangement = Arrangement.End horizontalArrangement = Arrangement.End
) { ) {
IconButton( SendMessageButton(
onClick = onSend,
modifier = Modifier modifier = Modifier
.height(48.dp) .height(48.dp)
.padding(horizontal = 8.dp), .padding(horizontal = 8.dp),
onClick = onSend,
enabled = canSend, enabled = canSend,
colors = IconButtonDefaults.iconButtonColors( willRestart = willRestart
contentColor = sendButtonColor, )
disabledContentColor = sendButtonColor }
) }
) { }
if (canRestart) {
Icon( @Composable
painter = painterResource(R.drawable.outline_restart_alt_24), fun SendMessageButton(
contentDescription = stringResource(R.string.button_send_restart_icon_description) onClick: () -> Unit,
) willRestart: Boolean,
} else { modifier: Modifier = Modifier,
Icon( enabled: Boolean = true
imageVector = Icons.AutoMirrored.Filled.Send, ) {
contentDescription = stringResource(R.string.button_send_icon_description) val color by animateColorAsState(
) targetValue = if (enabled) {
} IconButtonDefaults.iconButtonColors().contentColor
} } else {
IconButtonDefaults.iconButtonColors().disabledContentColor
}, label = "sendButtonColor"
)
IconButton(
onClick = onClick,
modifier = modifier,
enabled = enabled,
colors = IconButtonDefaults.iconButtonColors(
contentColor = color,
disabledContentColor = color
)
) {
if (willRestart) {
Icon(
painter = painterResource(R.drawable.outline_restart_alt_24),
contentDescription = stringResource(R.string.button_send_restart_icon_description)
)
} else {
Icon(
imageVector = Icons.AutoMirrored.Filled.Send,
contentDescription = stringResource(R.string.button_send_icon_description)
)
} }
} }
} }