Updated Hands Free icon and its state

This commit is contained in:
souravanand001 2026-06-18 02:44:09 +05:30
parent 04216343f1
commit c3bce8f807
3 changed files with 48 additions and 16 deletions

View file

@ -242,6 +242,7 @@ fun ChatLayout(
isDocumentSupported = isDocumentSupported,
isHandsFree = isHandsFree,
onToggleHandsFree = onToggleHandsFree,
hasMessages = chatList.isNotEmpty(),
)
}
}

View file

@ -3,6 +3,11 @@ package com.app.assistant.ui.screen
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.tween
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.expandHorizontally
import androidx.compose.animation.shrinkHorizontally
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
@ -89,6 +94,7 @@ fun UserInputField(
isDocumentSupported: Boolean = false,
isHandsFree: Boolean = false,
onToggleHandsFree: () -> Unit = {},
hasMessages: Boolean = false,
) {
val containerColor = TextFieldDefaults.colors().unfocusedContainerColor
val rippleColor = adjustContrast(containerColor)
@ -232,17 +238,12 @@ fun UserInputField(
}
} else null,
trailingIcon = {
val hasInput = question.isNotEmpty() || selectedAttachments.isNotEmpty()
val showSendButton = hasInput || isListening || hasMessages
Row(
horizontalArrangement = Arrangement.End,
verticalAlignment = Alignment.CenterVertically
) {
IconButton(onClick = onToggleHandsFree) {
Icon(
painter = painterResource(id = R.drawable.ic_speaker),
contentDescription = "Toggle Hands-free Mode",
tint = if (isHandsFree) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.onSurfaceVariant
)
}
if (isSpeaking) {
IconButton(onClick = {
if (isSpeaking) {
@ -264,15 +265,34 @@ fun UserInputField(
)
}
}
IconButton(onClick = {
if (question.isNotEmpty() || selectedAttachments.isNotEmpty()) {
onProcessQuestion(focusManager, keyboardController, false)
AnimatedVisibility(
visible = !showSendButton,
enter = fadeIn() + expandHorizontally(),
exit = fadeOut() + shrinkHorizontally()
) {
IconButton(onClick = onToggleHandsFree) {
Icon(
painter = painterResource(id = R.drawable.ic_live_modes),
contentDescription = "Toggle Hands-free Mode",
tint = if (isHandsFree) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.onSurfaceVariant
)
}
}
AnimatedVisibility(
visible = showSendButton,
enter = fadeIn() + expandHorizontally(),
exit = fadeOut() + shrinkHorizontally()
) {
IconButton(onClick = {
if (question.isNotEmpty() || selectedAttachments.isNotEmpty()) {
onProcessQuestion(focusManager, keyboardController, false)
}
}) {
Icon(
imageVector = Icons.AutoMirrored.Filled.Send,
contentDescription = stringResource(id = R.string.send_desc),
)
}
}) {
Icon(
imageVector = Icons.AutoMirrored.Filled.Send,
contentDescription = stringResource(id = R.string.send_desc),
)
}
}
},
@ -435,7 +455,8 @@ fun UserInputFieldIdlePreview() {
onStopSpeaking = {},
onStartListening = {},
onProcessQuestion = { _, _, _ -> },
isImageSupported = true
isImageSupported = true,
hasMessages = true
)
}
}

View file

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="#FFFFFF">
<path
android:fillColor="@android:color/white"
android:pathData="M19,9l1.25,-2.75L23,5l-2.75,-1.25L19,1l-1.25,2.75L15,5l2.75,1.25L19,9zM11.5,9.5L9,4L6.5,9.5L1,12l5.5,2.5L9,20l2.5,-5.5L17,12l-5.5,-2.5zM19,15l-1.25,2.75L15,19l2.75,1.25L19,23l1.25,-2.75L23,19l-2.75,-1.25L19,15z"/>
</vector>