Skip to content

Commit 7cef210

Browse files
Update PhotoReasoningScreen.kt
1 parent d2364fb commit 7cef210

1 file changed

Lines changed: 22 additions & 25 deletions

File tree

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

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import androidx.compose.foundation.layout.Box
99
import androidx.compose.foundation.layout.Column
1010
import androidx.compose.foundation.layout.Row
1111
import androidx.compose.foundation.layout.Spacer
12+
import androidx.compose.foundation.layout.fillMaxSize // <<< IMPORT HINZUGEFÜGT
1213
import androidx.compose.foundation.layout.fillMaxWidth
1314
import androidx.compose.foundation.layout.height
1415
import androidx.compose.foundation.layout.padding
@@ -62,6 +63,7 @@ import coil.size.Precision
6263
import com.google.ai.sample.R
6364
import com.google.ai.sample.ScreenOperatorAccessibilityService
6465
import com.google.ai.sample.util.Command
66+
import com.google.ai.sample.util.ModelPreferences // <<< IMPORT HINZUGEFÜGT
6567
import com.google.ai.sample.util.UriSaver
6668
import kotlinx.coroutines.launch
6769
import android.util.Log
@@ -75,7 +77,7 @@ internal fun PhotoReasoningRoute(
7577
val detectedCommands by viewModel.detectedCommands.collectAsState()
7678
val systemMessage by viewModel.systemMessage.collectAsState()
7779
val chatMessages by viewModel.chatMessagesFlow.collectAsState()
78-
val modelUpdateTrigger by viewModel.modelUpdateTrigger.collectAsState() // <<< NEU: Trigger beobachten
80+
val modelUpdateTrigger by viewModel.modelUpdateTrigger.collectAsState() // Trigger beobachten
7981

8082
val coroutineScope = rememberCoroutineScope()
8183
val imageRequestBuilder = ImageRequest.Builder(LocalContext.current)
@@ -84,27 +86,14 @@ internal fun PhotoReasoningRoute(
8486
val mainActivity = context as? MainActivity
8587

8688
DisposableEffect(viewModel) {
87-
// Entferne den Aufruf von setPhotoReasoningViewModel
88-
// mainActivity?.setPhotoReasoningViewModel(viewModel) // Nicht mehr benötigt
89-
9089
Log.d("PhotoReasoningRoute", "PhotoReasoningRoute is active. ViewModel instance should be available via MainActivity.getInstance().retrievePhotoReasoningViewModel()")
91-
92-
// Check if accessibility service is enabled
9390
mainActivity?.checkAccessibilityServiceEnabled()
94-
95-
// Load the saved system message and chat history
9691
viewModel.loadSystemMessage(context)
97-
98-
onDispose {
99-
// Optional: clear the reference when navigating away
100-
}
92+
onDispose { }
10193
}
10294

103-
// <<< NEU: LaunchedEffect für den Trigger >>>
10495
LaunchedEffect(modelUpdateTrigger) {
10596
Log.d("PhotoReasoningRoute", "Model update trigger changed: $modelUpdateTrigger. Recomposition might occur.")
106-
// Hier könnten explizite Aktionen stehen, aber oft reicht das Beobachten
107-
// für die Neuzeichnung durch Compose.
10897
}
10998

11099
PhotoReasoningScreen(
@@ -147,7 +136,6 @@ internal fun PhotoReasoningRoute(
147136
mainActivity?.checkAccessibilityServiceEnabled()
148137
},
149138
onClearChatHistory = {
150-
// Rufe die ViewModel-Funktion auf
151139
viewModel.clearChatHistory(context)
152140
// Der Reset des LazyListState passiert jetzt im onClick des Buttons
153141
}
@@ -183,7 +171,6 @@ fun PhotoReasoningScreen(
183171
// Scroll to the bottom when new messages arrive
184172
LaunchedEffect(chatMessages.size) {
185173
if (chatMessages.isNotEmpty()) {
186-
// Nur scrollen, wenn die Liste nicht gerade geleert wurde
187174
listState.animateScrollToItem(chatMessages.size - 1)
188175
}
189176
}
@@ -284,15 +271,12 @@ fun PhotoReasoningScreen(
284271
// New button to clear chat history
285272
IconButton(
286273
onClick = {
287-
// Rufe die ViewModel-Funktion auf
288274
onClearChatHistory()
289-
// <<< KORREKTUR: Setze den LazyListState zurück >>>
290275
coroutineScope.launch {
291276
listState.scrollToItem(0) // Scrolle zum Anfang (leere Liste)
292277
}
293-
// Leere auch die lokalen Bild-URIs
294278
imageUris.clear()
295-
userQuestion = "" // Leere auch das Textfeld
279+
userQuestion = ""
296280
},
297281
modifier = Modifier
298282
.padding(top = 4.dp)
@@ -386,8 +370,8 @@ fun PhotoReasoningScreen(
386370
is Command.ScrollRightFromCoordinates -> "Nach rechts scrollen von Position (${command.x}, ${command.y}) mit Distanz ${command.distance}px und Dauer ${command.duration}ms"
387371
is Command.OpenApp -> "App öffnen: \"${command.packageName}\""
388372
is Command.WriteText -> "Text schreiben: \"${command.text}\""
389-
is Command.UseHighReasoningModel -> "Wechsle zu ${ModelPreferences.HIGH_REASONING_MODEL}"
390-
is Command.UseLowReasoningModel -> "Wechsle zu ${ModelPreferences.LOW_REASONING_MODEL}"
373+
is Command.UseHighReasoningModel -> "Wechsle zu ${ModelPreferences.HIGH_REASONING_MODEL}" // <<< KORREKTUR: Verwendet jetzt den korrekten Import
374+
is Command.UseLowReasoningModel -> "Wechsle zu ${ModelPreferences.LOW_REASONING_MODEL}" // <<< KORREKTUR: Verwendet jetzt den korrekten Import
391375
}
392376
Text(text = "${index + 1}. $commandText", color = MaterialTheme.colorScheme.onTertiaryContainer)
393377
if (index < detectedCommands.size - 1) {
@@ -445,7 +429,20 @@ fun ErrorChatBubble(text: String) {
445429
// --- Previews (unverändert) ---
446430
@Preview
447431
@Composable
448-
fun PhotoReasoningScreenPreviewWithContent() { /* ... */ }
432+
fun PhotoReasoningScreenPreviewWithContent() {
433+
PhotoReasoningScreen(
434+
uiState = PhotoReasoningUiState.Success("This is a preview."),
435+
commandExecutionStatus = "Befehl ausgeführt",
436+
detectedCommands = listOf(Command.ClickButton("OK")),
437+
systemMessage = "Systemnachricht",
438+
chatMessages = listOf(
439+
PhotoReasoningMessage("User message", PhotoParticipant.USER),
440+
PhotoReasoningMessage("Model response", PhotoParticipant.MODEL)
441+
)
442+
)
443+
}
449444
@Composable
450445
@Preview(showSystemUi = true)
451-
fun PhotoReasoningScreenPreviewEmpty() { /* ... */ }
446+
fun PhotoReasoningScreenPreviewEmpty() {
447+
PhotoReasoningScreen()
448+
}

0 commit comments

Comments
 (0)