@@ -412,7 +412,8 @@ class PhotoReasoningViewModel(
412412 val userMessage = PhotoReasoningMessage (
413413 text = messageText,
414414 participant = PhotoParticipant .USER ,
415- isPending = false
415+ isPending = false ,
416+ image = result // Include the image in the message
416417 )
417418 _chatState .addMessage(userMessage)
418419 _chatMessagesFlow .value = chatMessages
@@ -461,7 +462,53 @@ class PhotoReasoningViewModel(
461462 val userMessage = PhotoReasoningMessage (
462463 text = messageText,
463464 participant = PhotoParticipant .USER ,
464- isPending = false
465+ isPending = false ,
466+ image = screenshot // Include the image in the message
467+ )
468+ _chatState .addMessage(userMessage)
469+ _chatMessagesFlow .value = chatMessages
470+
471+ // Save chat history
472+ saveChatHistory(MainActivity .getInstance()?.applicationContext)
473+
474+ // Update the current selected images to include only the latest screenshot
475+ currentSelectedImages = listOf (screenshot)
476+
477+ // Update status
478+ _commandExecutionStatus .value = " Screenshot zur Konversation hinzugefügt"
479+
480+ // Rebuild chat history to ensure context is maintained
481+ rebuildChatHistory()
482+ } catch (e: Exception ) {
483+ Log .e(TAG , " Error adding screenshot to conversation: ${e.message} " , e)
484+ _commandExecutionStatus .value = " Fehler beim Hinzufügen des Screenshots: ${e.message} "
485+ }
486+ }
487+ }
488+
489+ /* *
490+ * Add a screenshot to the conversation with screen info
491+ *
492+ * @param screenshot Bitmap of the screenshot
493+ * @param screenInfo Information about screen elements
494+ */
495+ fun addScreenshotToConversation (screenshot : Bitmap , screenInfo : String ) {
496+ PhotoReasoningApplication .applicationScope.launch(Dispatchers .Main ) {
497+ try {
498+ Log .d(TAG , " Adding screenshot to conversation with screen info" )
499+
500+ // Update status
501+ _commandExecutionStatus .value = " Verarbeite Screenshot..."
502+
503+ // Create message text with screen info
504+ val messageText = " Screenshot aufgenommen\n\n $screenInfo "
505+
506+ // Add user message to chat history
507+ val userMessage = PhotoReasoningMessage (
508+ text = messageText,
509+ participant = PhotoParticipant .USER ,
510+ isPending = false ,
511+ image = screenshot // Include the image in the message
465512 )
466513 _chatState .addMessage(userMessage)
467514 _chatMessagesFlow .value = chatMessages
0 commit comments