Skip to content

Commit 4e873f5

Browse files
Add files via upload
1 parent 0cf719d commit 4e873f5

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ internal fun PhotoReasoningRoute(
9393
coroutineScope.launch {
9494
// Take screenshot when Go button is pressed
9595
val screenshotManager = ScreenshotManager.getInstance(context)
96+
97+
// Use a callback approach instead of direct suspension function calls
9698
screenshotManager.takeScreenshot { bitmap ->
9799
if (bitmap != null) {
98100
// Save screenshot to file
@@ -102,16 +104,22 @@ internal fun PhotoReasoningRoute(
102104
val updatedItems = selectedItems.toMutableList()
103105
updatedItems.add(screenshotFile.toUri())
104106

105-
// Process all images including screenshot
106-
processImagesAndReason(updatedItems, inputText, imageRequestBuilder, imageLoader, viewModel)
107+
// Process all images including screenshot within the coroutine scope
108+
coroutineScope.launch {
109+
processImagesAndReason(updatedItems, inputText, imageRequestBuilder, imageLoader, viewModel)
110+
}
107111
} else {
108112
// If screenshot saving failed, proceed with original images
109-
processImagesAndReason(selectedItems, inputText, imageRequestBuilder, imageLoader, viewModel)
113+
coroutineScope.launch {
114+
processImagesAndReason(selectedItems, inputText, imageRequestBuilder, imageLoader, viewModel)
115+
}
110116
Toast.makeText(context, "Failed to save screenshot", Toast.LENGTH_SHORT).show()
111117
}
112118
} else {
113119
// If screenshot failed, proceed with original images
114-
processImagesAndReason(selectedItems, inputText, imageRequestBuilder, imageLoader, viewModel)
120+
coroutineScope.launch {
121+
processImagesAndReason(selectedItems, inputText, imageRequestBuilder, imageLoader, viewModel)
122+
}
115123
Toast.makeText(context, "Failed to take screenshot", Toast.LENGTH_SHORT).show()
116124
}
117125
}

0 commit comments

Comments
 (0)