Skip to content

Commit dd8a22e

Browse files
I've refactored the Send button logic for accessibility and text input state.
The Send button behavior in PhotoReasoningScreen has been updated to meet the following requirements: 1. The button performs the SEND action and appears ACTIVE (primary tint): - Only when Accessibility Service is ON AND Text Input is NOT BLANK. 2. The button performs the GO TO ACCESSIBILITY SETTINGS action and appears ACTIVE (primary tint): - When Accessibility Service is OFF (regardless of Text Input state). 3. The button performs NO action and appears INACTIVE (gray tint): - When Accessibility Service is ON AND Text Input is BLANK. Changes include: - I modified the `enabled` property of the Send `IconButton`. - I updated the `onClick` lambda to branch correctly based on service state and text input. - I adjusted the `Icon` tint to visually reflect whether the button has an available function.
1 parent d8681a9 commit dd8a22e

1 file changed

Lines changed: 21 additions & 13 deletions

File tree

app/src/main/kotlin/com/google/ai/sample/feature/multimodal/PhotoReasoningScreen.kt

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -360,21 +360,29 @@ fun PhotoReasoningScreen(
360360
onValueChange = { userQuestion = it },
361361
modifier = Modifier.weight(1f).padding(end = 8.dp)
362362
)
363-
IconButton(onClick = {
364-
if (isAccessibilityServiceEnabled) {
365-
if (userQuestion.isNotBlank()) {
366-
onReasonClicked(userQuestion, imageUris.toList())
367-
userQuestion = ""
363+
IconButton(
364+
onClick = {
365+
if (isAccessibilityServiceEnabled) {
366+
if (userQuestion.isNotBlank()) {
367+
onReasonClicked(userQuestion, imageUris.toList())
368+
userQuestion = ""
369+
}
370+
// If accessibility is ON but userQuestion is BLANK, no action is needed here as the button's enabled state and tint convey this.
371+
} else {
372+
// Accessibility is OFF
373+
onEnableAccessibilityService()
374+
Toast.makeText(context, "Enable the Accessibility service for Screen Operator", Toast.LENGTH_LONG).show()
368375
}
369-
} else {
370-
onEnableAccessibilityService()
371-
Toast.makeText(context, "Enable the Accessibility service for Screen Operator", Toast.LENGTH_LONG).show()
376+
},
377+
enabled = isInitialized && ((isAccessibilityServiceEnabled && userQuestion.isNotBlank()) || !isAccessibilityServiceEnabled),
378+
modifier = Modifier.padding(all = 4.dp).align(Alignment.CenterVertically)
379+
) {
380+
Icon(
381+
Icons.Default.Send,
382+
stringResource(R.string.action_go),
383+
tint = if ((isAccessibilityServiceEnabled && userQuestion.isNotBlank()) || !isAccessibilityServiceEnabled) MaterialTheme.colorScheme.primary else Color.Gray,
384+
)
372385
}
373-
},
374-
enabled = isInitialized && isAccessibilityServiceEnabled && userQuestion.isNotBlank(), // Modified enabled state
375-
modifier = Modifier.padding(all = 4.dp).align(Alignment.CenterVertically)
376-
) {
377-
Icon(Icons.Default.Send, stringResource(R.string.action_go), tint = MaterialTheme.colorScheme.primary)
378386
}
379387
}
380388
LazyRow(modifier = Modifier.padding(all = 8.dp)) {

0 commit comments

Comments
 (0)