@@ -103,6 +103,66 @@ internal fun PhotoReasoningRoute(
103103 }
104104 }
105105
106+ PhotoReasoningScreen (
107+ uiState = photoReasoningUiState,
108+ commandExecutionStatus = commandExecutionStatus,
109+ detectedCommands = detectedCommands,
110+ systemMessage = systemMessage,
111+ chatMessages = chatMessages,
112+ onSystemMessageChanged = { message ->
113+ viewModel.updateSystemMessage(message, context)
114+ },
115+ onReasonClicked = { inputText, selectedItems ->
116+ coroutineScope.launch {
117+ Log .d(" PhotoReasoningScreen" , " Go button clicked, processing images" )
118+
119+ // Process all selected images
120+ val bitmaps = selectedItems.mapNotNull {
121+ Log .d(" PhotoReasoningScreen" , " Processing image: $it " )
122+ val imageRequest = imageRequestBuilder
123+ .data(it)
124+ .precision(Precision .EXACT )
125+ .build()
126+ try {
127+ val result = imageLoader.execute(imageRequest)
128+ if (result is SuccessResult ) {
129+ Log .d(" PhotoReasoningScreen" , " Successfully processed image" )
130+ return @mapNotNull (result.drawable as BitmapDrawable ).bitmap
131+ } else {
132+ Log .e(" PhotoReasoningScreen" , " Failed to process image: result is not SuccessResult" )
133+ return @mapNotNull null
134+ }
135+ } catch (e: Exception ) {
136+ Log .e(" PhotoReasoningScreen" , " Error processing image: ${e.message} " )
137+ return @mapNotNull null
138+ }
139+ }
140+
141+ Log .d(" PhotoReasoningScreen" , " Processed ${bitmaps.size} images" )
142+
143+ // Send to AI
144+ viewModel.reason(inputText, bitmaps)
145+ }
146+ },
147+ isAccessibilityServiceEnabled = mainActivity?.let {
148+ ScreenOperatorAccessibilityService .isAccessibilityServiceEnabled(it)
149+ } ? : false ,
150+ onEnableAccessibilityService = {
151+ mainActivity?.checkAccessibilityServiceEnabled()
152+ },
153+ onClearChatHistory = {
154+ mainActivity?.let {
155+ val viewModel = it.getPhotoReasoningViewModel()
156+ viewModel?.clearChatHistory(context)
157+ }
158+ }
159+ )
160+ }
161+ // Optional: clear the reference when navigating away
162+ // mainActivity?.clearPhotoReasoningViewModel()
163+ }
164+ }
165+
106166 PhotoReasoningScreen (
107167 uiState = photoReasoningUiState,
108168 commandExecutionStatus = commandExecutionStatus,
@@ -163,7 +223,8 @@ fun PhotoReasoningScreen(
163223 onSystemMessageChanged : (String ) -> Unit = {},
164224 onReasonClicked : (String , List <Uri >) -> Unit = { _, _ -> },
165225 isAccessibilityServiceEnabled : Boolean = false,
166- onEnableAccessibilityService : () -> Unit = {}
226+ onEnableAccessibilityService : () -> Unit = {},
227+ onClearChatHistory : () -> Unit = {}
167228) {
168229 var userQuestion by rememberSaveable { mutableStateOf(" " ) }
169230 val imageUris = rememberSaveable(saver = UriSaver ()) { mutableStateListOf() }
@@ -172,6 +233,13 @@ fun PhotoReasoningScreen(
172233
173234 // Get the MainActivity instance from the context
174235 val mainActivity = context as ? MainActivity
236+
237+ // Media picker for adding images
238+ val pickMedia = rememberLauncherForActivityResult(
239+ ActivityResultContracts .PickVisualMedia ()
240+ ) { uri ->
241+ uri?.let { imageUris.add(it) }
242+ }
175243
176244 // Scroll to the bottom when new messages arrive
177245 LaunchedEffect (chatMessages.size) {
@@ -312,10 +380,7 @@ fun PhotoReasoningScreen(
312380 IconButton (
313381 onClick = {
314382 // Clear chat history directly without confirmation
315- mainActivity?.let {
316- val viewModel = it.getPhotoReasoningViewModel()
317- viewModel?.clearChatHistory(context)
318- }
383+ onClearChatHistory()
319384 },
320385 modifier = Modifier
321386 .padding(top = 4 .dp)
0 commit comments