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: Minecon724
GPG key ID: A02E6E67AB961189
2 changed files with 44 additions and 28 deletions

View file

@ -261,7 +261,7 @@ fun ChatScreenContent(
) {
ChatToolBar(
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,
onEmptySpaceClick = onRequestFocus
)

View file

@ -26,17 +26,10 @@ import eu.m724.chatapp.R
fun ChatToolBar(
modifier: Modifier = Modifier,
canSend: Boolean,
canRestart: Boolean,
willRestart: Boolean,
onSend: () -> Unit,
onEmptySpaceClick: () -> Unit
) {
val sendButtonColor by animateColorAsState(
targetValue = if (canSend) {
IconButtonDefaults.iconButtonColors().contentColor
} else {
IconButtonDefaults.iconButtonColors().disabledContentColor
}, label = "sendButtonColor"
)
ElevatedCard(
modifier = modifier,
@ -48,29 +41,52 @@ fun ChatToolBar(
.clickable(onClick = onEmptySpaceClick),
horizontalArrangement = Arrangement.End
) {
IconButton(
onClick = onSend,
SendMessageButton(
modifier = Modifier
.height(48.dp)
.padding(horizontal = 8.dp),
onClick = onSend,
enabled = canSend,
colors = IconButtonDefaults.iconButtonColors(
contentColor = sendButtonColor,
disabledContentColor = sendButtonColor
)
) {
if (canRestart) {
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)
)
}
}
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(
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)
)
}
}
}