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,18 +41,43 @@ 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,
willRestart = willRestart
)
}
}
}
@Composable
fun SendMessageButton(
onClick: () -> Unit,
willRestart: Boolean,
modifier: Modifier = Modifier,
enabled: Boolean = true
) {
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( colors = IconButtonDefaults.iconButtonColors(
contentColor = sendButtonColor, contentColor = color,
disabledContentColor = sendButtonColor disabledContentColor = color
) )
) { ) {
if (canRestart) { if (willRestart) {
Icon( Icon(
painter = painterResource(R.drawable.outline_restart_alt_24), painter = painterResource(R.drawable.outline_restart_alt_24),
contentDescription = stringResource(R.string.button_send_restart_icon_description) contentDescription = stringResource(R.string.button_send_restart_icon_description)
@ -72,5 +90,3 @@ fun ChatToolBar(
} }
} }
} }
}
}