Skip to content

Commit 1024ff5

Browse files
Add files via upload
1 parent 9231859 commit 1024ff5

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

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

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,16 @@ class PhotoReasoningViewModel(
317317

318318
/**
319319
* Add a screenshot to the conversation
320+
*
321+
* @param screenshotUri URI of the screenshot
322+
* @param context Application context
323+
* @param screenInfo Optional information about screen elements (null if not available)
320324
*/
321-
fun addScreenshotToConversation(screenshotUri: Uri, context: android.content.Context) {
325+
fun addScreenshotToConversation(
326+
screenshotUri: Uri,
327+
context: android.content.Context,
328+
screenInfo: String? = null
329+
) {
322330
viewModelScope.launch(Dispatchers.Main) {
323331
try {
324332
Log.d(TAG, "Adding screenshot to conversation: $screenshotUri")
@@ -340,9 +348,16 @@ class PhotoReasoningViewModel(
340348
// Show toast
341349
Toast.makeText(context, "Verarbeite Screenshot...", Toast.LENGTH_SHORT).show()
342350

351+
// Create message text with screen information if available
352+
val messageText = if (screenInfo != null) {
353+
"Screenshot aufgenommen\n\n$screenInfo"
354+
} else {
355+
"Screenshot aufgenommen"
356+
}
357+
343358
// Add screenshot message to chat history
344359
val screenshotMessage = PhotoReasoningMessage(
345-
text = "Screenshot aufgenommen",
360+
text = messageText,
346361
participant = PhotoParticipant.USER,
347362
imageUris = listOf(screenshotUri.toString())
348363
)
@@ -377,8 +392,15 @@ class PhotoReasoningViewModel(
377392
// Show toast
378393
Toast.makeText(context, "Screenshot hinzugefügt, sende an KI...", Toast.LENGTH_SHORT).show()
379394

395+
// Create prompt with screen information if available
396+
val prompt = if (screenInfo != null) {
397+
"Analysiere diesen Screenshot. Hier sind die verfügbaren Bildschirmelemente: $screenInfo"
398+
} else {
399+
"Analysiere diesen Screenshot"
400+
}
401+
380402
// Re-send the query with the updated images
381-
reason("Analysiere diesen Screenshot", listOf(bitmap))
403+
reason(prompt, listOf(bitmap))
382404

383405
// Show a toast to indicate the screenshot was added
384406
Toast.makeText(context, "Screenshot zur Konversation hinzugefügt", Toast.LENGTH_SHORT).show()

0 commit comments

Comments
 (0)