Skip to content

Commit 81c5649

Browse files
Update PhotoReasoningScreen.kt (#17)
1 parent ca32c7e commit 81c5649

1 file changed

Lines changed: 24 additions & 12 deletions

File tree

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

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import android.content.Intent
55
import android.graphics.drawable.BitmapDrawable
66
import android.net.Uri
77
import android.provider.Settings
8+
import android.widget.Toast // Added for Toast message
89
import androidx.activity.compose.rememberLauncherForActivityResult
910
import androidx.activity.result.PickVisualMediaRequest
1011
import androidx.activity.result.contract.ActivityResultContracts
@@ -148,13 +149,14 @@ internal fun PhotoReasoningRoute(
148149
viewModel.reason(inputText, bitmaps)
149150
}
150151
},
151-
isAccessibilityServiceEnabled = isAccessibilityServiceEffectivelyEnabled, // Use the collected state
152+
isAccessibilityServiceEnabled = isAccessibilityServiceEffectivelyEnabled,
152153
onEnableAccessibilityService = {
153154
mainActivity?.let {
154155
val intent = it.getAccessibilitySettingsIntent()
155156
try {
156157
accessibilitySettingsLauncher.launch(intent)
157-
it.updateStatusMessage("Bitte aktivieren Sie den Dienst für 'Generative AI Sample'.")
158+
// Removed the toast from here as it's now handled by the send button
159+
// and the dedicated "activate" button on the warning card.
158160
} catch (e: Exception) {
159161
Log.e("PhotoReasoningRoute", "Error opening accessibility settings", e)
160162
it.updateStatusMessage("Fehler beim Öffnen der Bedienungshilfen-Einstellungen.", true)
@@ -179,14 +181,14 @@ fun PhotoReasoningScreen(
179181
chatMessages: List<PhotoReasoningMessage> = emptyList(),
180182
onSystemMessageChanged: (String) -> Unit = {},
181183
onReasonClicked: (String, List<Uri>) -> Unit = { _, _ -> },
182-
isAccessibilityServiceEnabled: Boolean = false, // This will now be updated reactively
184+
isAccessibilityServiceEnabled: Boolean = false,
183185
onEnableAccessibilityService: () -> Unit = {},
184186
onClearChatHistory: () -> Unit = {}
185187
) {
186188
var userQuestion by rememberSaveable { mutableStateOf("") }
187189
val imageUris = rememberSaveable(saver = UriSaver()) { mutableStateListOf() }
188190
val listState = rememberLazyListState()
189-
// val context = LocalContext.current // Already available from Route
191+
val context = LocalContext.current // Get context for Toast
190192

191193
val pickMedia = rememberLauncherForActivityResult(
192194
ActivityResultContracts.PickVisualMedia()
@@ -234,7 +236,6 @@ fun PhotoReasoningScreen(
234236
}
235237
}
236238

237-
// Accessibility Service Status Card - visibility controlled by isAccessibilityServiceEnabled
238239
if (!isAccessibilityServiceEnabled) {
239240
Card(
240241
modifier = Modifier
@@ -259,7 +260,11 @@ fun PhotoReasoningScreen(
259260
)
260261
Spacer(modifier = Modifier.height(8.dp))
261262
TextButton(
262-
onClick = onEnableAccessibilityService
263+
onClick = {
264+
onEnableAccessibilityService()
265+
// Optionally, show a toast here as well if the user clicks this specific button
266+
Toast.makeText(context, "Öffne Bedienungshilfen-Einstellungen...", Toast.LENGTH_SHORT).show()
267+
}
263268
) {
264269
Text("Accessibility Service aktivieren")
265270
}
@@ -356,10 +361,18 @@ fun PhotoReasoningScreen(
356361
)
357362
IconButton(
358363
onClick = {
359-
if (userQuestion.isNotBlank()) {
360-
onReasonClicked(userQuestion, imageUris.toList())
361-
userQuestion = ""
364+
// START: Updated Send button logic
365+
if (isAccessibilityServiceEnabled) {
366+
if (userQuestion.isNotBlank()) {
367+
onReasonClicked(userQuestion, imageUris.toList())
368+
userQuestion = "" // Clear input after sending
369+
}
370+
} else {
371+
// Accessibility service is not enabled
372+
onEnableAccessibilityService() // Open settings
373+
Toast.makeText(context, "Enable the Accessibility service for Screen Operator", Toast.LENGTH_LONG).show()
362374
}
375+
// END: Updated Send button logic
363376
},
364377
modifier = Modifier
365378
.padding(all = 4.dp)
@@ -434,7 +447,6 @@ fun PhotoReasoningScreen(
434447
is Command.ClickButton -> "Klick auf Button: \"${command.buttonText}\""
435448
is Command.TapCoordinates -> "Tippen auf Koordinaten: (${command.x}, ${command.y})"
436449
is Command.TakeScreenshot -> "Screenshot aufnehmen"
437-
// ... (other command types remain the same)
438450
is Command.PressHomeButton -> "Home-Button drücken"
439451
is Command.PressBackButton -> "Zurück-Button drücken"
440452
is Command.ShowRecentApps -> "Übersicht der letzten Apps öffnen"
@@ -554,9 +566,9 @@ fun ModelChatBubble(
554566
.drawBehind {
555567
drawCircle(color = Color.White)
556568
}
557-
.padding(end = 8.dp) // Added padding to separate icon from text
569+
.padding(end = 8.dp)
558570
)
559-
Column { // Wrap Text and CircularProgressIndicator in a Column
571+
Column {
560572
Text(
561573
text = text,
562574
color = MaterialTheme.colorScheme.onSecondaryContainer

0 commit comments

Comments
 (0)