Skip to content

Your phone, on your command. Gotcha is world's first fully on-device AI copilot for Android that turns natural language into real device actions — safely.

Chat assets viewer: per-chat files from the overflow menu

Rishabh Bajpai9c40687e7c03
diff --git a/app/src/androidTest/java/com/gotcha/ChatAssetsNavTest.kt b/app/src/androidTest/java/com/gotcha/ChatAssetsNavTest.kt
new file mode 100644
index 0000000..f464fd7
--- /dev/null
+++ b/app/src/androidTest/java/com/gotcha/ChatAssetsNavTest.kt
@@ -0,0 +1,83 @@
+package com.gotcha
+
+import androidx.compose.ui.test.hasContentDescription
+import androidx.compose.ui.test.junit4.createEmptyComposeRule
+import androidx.compose.ui.test.onNodeWithTag
+import androidx.compose.ui.test.onNodeWithText
+import androidx.compose.ui.test.performClick
+import androidx.test.core.app.ActivityScenario
+import androidx.test.core.app.ApplicationProvider
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.gotcha.testutil.MockLlm
+import com.gotcha.testutil.TestSeed
+import org.junit.After
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+
+/** Chat ⋮ menu ▸ Chat assets opens the per-chat file list; back returns. */
+@RunWith(AndroidJUnit4::class)
+class ChatAssetsNavTest {
+
+ @get:Rule
+ val composeRule = createEmptyComposeRule()
+
+ private var scenario: ActivityScenario<MainActivity>? = null
+ private val mockLlm = MockLlm()
+
+ @After
+ fun tearDown() {
+ runCatching { scenario?.close() }
+ mockLlm.shutdown()
+ }
+
+ @Test
+ fun chatMenu_assets_opensEmptyAssets_andBackReturns() {
+ mockLlm.start()
+ val context = ApplicationProvider.getApplicationContext<android.content.Context>()
+ TestSeed.seedConfigured(context, baseUrl = mockLlm.baseUrl)
+ // The ⋮ menu only renders on an open chat, and home is message-less:
+ // seed one exchanged line and open it from the drawer.
+ kotlinx.coroutines.runBlocking {
+ com.gotcha.data.ChatHistoryRepository(context).saveSession(
+ com.gotcha.data.ChatSession(
+ id = "assets-nav-test",
+ title = "Assets nav",
+ lastModified = System.currentTimeMillis(),
+ messages = listOf(
+ com.gotcha.llm.ChatMessage(
+ role = "user",
+ content = kotlinx.serialization.json.JsonPrimitive("hello")
+ )
+ ),
+ displayMessages = listOf(
+ com.gotcha.agent.UiMessage(
+ id = 1,
+ kind = com.gotcha.agent.MessageKind.USER,
+ text = "hello"
+ )
+ )
+ ),
+ touch = true
+ )
+ }
+ scenario = ActivityScenario.launch(MainActivity::class.java)
+ composeRule.waitForIdle()
+ composeRule.onNodeWithTag("chat_input").assertExists()
+ composeRule.onNode(hasContentDescription("Open menu")).performClick()
+ composeRule.waitForIdle()
+ composeRule.onNodeWithText("Assets nav").performClick()
+ composeRule.waitForIdle()
+
+ // A fresh seeded chat has no folder: the empty state must show.
+ composeRule.onNodeWithTag("chat_options").performClick()
+ composeRule.waitForIdle()
+ composeRule.onNodeWithTag("chat_assets").performClick()
+ composeRule.waitForIdle()
+ composeRule.onNodeWithTag("chat_assets_empty").assertExists()
+
+ composeRule.onNodeWithTag("chat_assets_back").performClick()
+ composeRule.waitForIdle()
+ composeRule.onNodeWithTag("chat_input").assertExists()
+ }
+}
diff --git a/app/src/main/assets/app/about-gotcha.md b/app/src/main/assets/app/about-gotcha.md
index 704ac90..7b9bbe9 100644
--- a/app/src/main/assets/app/about-gotcha.md
+++ b/app/src/main/assets/app/about-gotcha.md
@@ -102,8 +102,9 @@ if needed.
Settings, on their own Connectors screen.
**Whole-library chat backup and import live in Settings ▸ Chats.** A chat's ⋮ menu has
-**Export chat** (shares the conversation as readable Markdown) and **Back up
-chat** (saves the whole chat to a `.gotcha.json` file, images optional). Settings ▸ Chats has
+**Export chat** (shares the conversation as readable Markdown), **Back up
+chat** (saves the whole chat to a `.gotcha.json` file, images optional), and
+**Chat assets** (the files Gotcha created for that chat). Settings ▸ Chats has
**Back up all chats** and **Import chats**, which reads
either kind of file back. A Markdown export imports as text only, without its
images, attachments or full tool arguments; a backup restores everything. In
diff --git a/app/src/main/java/com/gotcha/MainActivity.kt b/app/src/main/java/com/gotcha/MainActivity.kt
index 1b92215..2ffcffe 100644
--- a/app/src/main/java/com/gotcha/MainActivity.kt
+++ b/app/src/main/java/com/gotcha/MainActivity.kt
@@ -77,6 +77,7 @@ import com.gotcha.tools.ScreenPerception
import com.gotcha.tools.TermuxTool
import com.gotcha.tools.ToolResult
import com.gotcha.ui.AppDrawerContent
+import com.gotcha.ui.ChatAssetsScreen
import com.gotcha.ui.ChatScreen
import com.gotcha.ui.ChatTransferDialogs
import com.gotcha.ui.ConnectorsScreen
@@ -114,7 +115,7 @@ import kotlinx.coroutines.withContext
import kotlinx.serialization.json.JsonPrimitive
import android.provider.Settings as AndroidSettings
-enum class Route { HOME, SETTINGS, CONNECTORS, INBOX }
+enum class Route { HOME, SETTINGS, CONNECTORS, INBOX, CHAT_ASSETS }
/**
* Where the user is, in the tour's vocabulary. Null means somewhere the tour has
@@ -859,6 +860,9 @@ class MainActivity : ComponentActivity() {
var settingsPage by rememberSaveable {
mutableStateOf(if (unconfigured) SettingsPage.AI_CONFIG else null)
}
+ // The chat whose assets ChatAssetsScreen shows; set on the tap that
+ // navigates there, alongside the route, like settingsPage is for Settings.
+ var assetsSessionId by rememberSaveable { mutableStateOf<String?>(null) }
// The field a settings search result opened settingsPage on. Only that
// tap sets it; every other way of changing page clears it, so it can't
// outlive the visit it was meant for. Deliberately not saveable: after a
@@ -1231,6 +1235,14 @@ class MainActivity : ComponentActivity() {
BackHandler { leaveConnectors() }
ConnectorsScreen(onBack = leaveConnectors)
}
+ Route.CHAT_ASSETS -> {
+ BackHandler { currentRoute = Route.HOME }
+ // Both are saveable and always set together; a null id
+ // only shows a blank frame rather than navigating mid-compose.
+ assetsSessionId?.let { id ->
+ ChatAssetsScreen(sessionId = id, onBack = { currentRoute = Route.HOME })
+ }
+ }
Route.HOME -> {
// Back from an active chat returns to a fresh home (new session,
// new greeting); on an empty home the default back exits the app.
@@ -1276,6 +1288,12 @@ class MainActivity : ComponentActivity() {
onStopRecording = { cb -> chatViewModel.stopRecording(cb) },
onExportChat = chatViewModel::exportChat,
onBackupChat = { state.activeSessionId?.let(chatTransfer::startBackup) },
+ onOpenChatAssets = {
+ state.activeSessionId?.let { id ->
+ assetsSessionId = id
+ currentRoute = Route.CHAT_ASSETS
+ }
+ },
onReturnToRunning = {
state.runningSessionId?.let { chatViewModel.openSession(it) }
},
diff --git a/app/src/main/java/com/gotcha/ui/ChatAssetsScreen.kt b/app/src/main/java/com/gotcha/ui/ChatAssetsScreen.kt
new file mode 100644
index 0000000..062a1a6
--- /dev/null
+++ b/app/src/main/java/com/gotcha/ui/ChatAssetsScreen.kt
@@ -0,0 +1,209 @@
+package com.gotcha.ui
+
+import android.content.Intent
+import android.webkit.MimeTypeMap
+import androidx.compose.foundation.clickable
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.lazy.LazyColumn
+import androidx.compose.foundation.lazy.items
+import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.automirrored.filled.ArrowBack
+import androidx.compose.material.icons.filled.Description
+import androidx.compose.material3.ExperimentalMaterial3Api
+import androidx.compose.material3.Icon
+import androidx.compose.material3.IconButton
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.Scaffold
+import androidx.compose.material3.Text
+import androidx.compose.material3.TopAppBar
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.LaunchedEffect
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.remember
+import androidx.compose.runtime.setValue
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.platform.LocalContext
+import androidx.compose.ui.platform.testTag
+import androidx.compose.ui.res.stringResource
+import androidx.compose.ui.text.font.FontWeight
+import androidx.compose.ui.unit.dp
+import androidx.core.content.FileProvider
+import com.gotcha.R
+import com.gotcha.data.GotchaStorage
+import com.gotcha.tools.FileResolver
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.withContext
+import java.io.File
+
+/**
+ * The files Gotcha created for one chat, without a file-manager safari.
+ * Read-only: tapping a file hands it to the system viewer through the app's
+ * FileProvider (gallery, player, reader — no in-app player to maintain).
+ */
+@OptIn(ExperimentalMaterial3Api::class)
+@Composable
+fun ChatAssetsScreen(sessionId: String, onBack: () -> Unit) {
+ val context = LocalContext.current
+ var loaded by remember(sessionId) { mutableStateOf(false) }
+ var sections by remember(sessionId) { mutableStateOf(emptyList<ChatAssetSection>()) }
+ LaunchedEffect(sessionId) {
+ sections = withContext(Dispatchers.IO) {
+ GotchaStorage.findChatDir(sessionId)?.let(::chatAssetSections).orEmpty()
+ }
+ loaded = true
+ }
+
+ Scaffold(
+ topBar = {
+ TopAppBar(
+ title = { Text(stringResource(R.string.chat_assets_title)) },
+ navigationIcon = {
+ IconButton(
+ onClick = onBack,
+ modifier = Modifier.testTag("chat_assets_back")
+ ) {
+ Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = null)
+ }
+ }
+ )
+ }
+ ) { padding ->
+ if (!loaded) {
+ // Still scanning; chat folders are small, no spinner.
+ Unit
+ } else if (sections.isEmpty()) {
+ Text(
+ text = stringResource(R.string.chat_assets_empty),
+ style = MaterialTheme.typography.bodyMedium,
+ color = MaterialTheme.colorScheme.onSurfaceVariant,
+ modifier = Modifier
+ .fillMaxSize()
+ .padding(padding)
+ .padding(24.dp)
+ .testTag("chat_assets_empty")
+ )
+ } else {
+ LazyColumn(
+ modifier = Modifier
+ .fillMaxSize()
+ .padding(padding)
+ ) {
+ sections.forEach { section ->
+ item(key = "header:${section.kind}") {
+ Text(
+ text = sectionTitle(section.kind),
+ style = MaterialTheme.typography.labelLarge,
+ color = MaterialTheme.colorScheme.onSurfaceVariant,
+ modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp)
+ )
+ }
+ items(section.items, key = { it.path }) { item ->
+ Row(
+ modifier = Modifier
+ .fillMaxWidth()
+ .clickable { openAsset(context, File(item.path)) }
+ .padding(horizontal = 16.dp, vertical = 10.dp)
+ .testTag("chat_asset_row"),
+ verticalAlignment = Alignment.CenterVertically
+ ) {
+ Icon(
+ Icons.Default.Description,
+ contentDescription = null,
+ tint = MaterialTheme.colorScheme.onSurfaceVariant
+ )
+ Column(modifier = Modifier.padding(start = 12.dp)) {
+ Text(
+ text = item.name,
+ style = MaterialTheme.typography.bodyMedium,
+ fontWeight = FontWeight.Medium
+ )
+ Text(
+ text = item.detail,
+ style = MaterialTheme.typography.bodySmall,
+ color = MaterialTheme.colorScheme.onSurfaceVariant
+ )
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+@Composable
+private fun sectionTitle(kind: GotchaStorage.Kind?): String = stringResource(
+ when (kind) {
+ GotchaStorage.Kind.PICTURES -> R.string.chat_assets_pictures
+ GotchaStorage.Kind.RECORDINGS -> R.string.chat_assets_recordings
+ GotchaStorage.Kind.SCREENSHOTS -> R.string.chat_assets_screenshots
+ GotchaStorage.Kind.DEBUG, null -> R.string.chat_assets_other_files
+ }
+)
+
+private fun openAsset(context: android.content.Context, file: File) {
+ val opened = runCatching {
+ val uri = FileProvider.getUriForFile(
+ context,
+ "${context.packageName}.fileprovider",
+ file
+ )
+ val mime = MimeTypeMap.getSingleton()
+ .getMimeTypeFromExtension(file.extension) ?: "*/*"
+ val intent = Intent(Intent.ACTION_VIEW).apply {
+ setDataAndType(uri, mime)
+ addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
+ addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+ }
+ context.startActivity(intent)
+ true
+ }.getOrDefault(false)
+ if (!opened) {
+ android.widget.Toast.makeText(
+ context,
+ context.getString(R.string.chat_assets_open_failed),
+ android.widget.Toast.LENGTH_SHORT
+ ).show()
+ }
+}
+
+/** One file on the assets screen, with its display strings precomputed. */
+data class ChatAssetItem(val path: String, val name: String, val detail: String)
+
+/** One named group: a media kind, or null for loose files. */
+data class ChatAssetSection(val kind: GotchaStorage.Kind?, val items: List<ChatAssetItem>)
+
+/**
+ * Groups a chat folder's contents for display: Pictures, Recordings and
+ * Screenshots first (only when non-empty), then loose files. Newest first
+ * inside each group. Sizes are read here — callers run this off the UI
+ * thread — so composition never touches the disk. Pure for unit tests.
+ */
+fun chatAssetSections(chatDir: File): List<ChatAssetSection> {
+ val sections = mutableListOf<ChatAssetSection>()
+ for (kind in listOf(GotchaStorage.Kind.PICTURES, GotchaStorage.Kind.RECORDINGS, GotchaStorage.Kind.SCREENSHOTS)) {
+ val files = File(chatDir, kind.dirName).listFiles()
+ ?.filter { it.isFile }
+ ?.sortedByDescending { it.lastModified() }
+ .orEmpty()
+ if (files.isNotEmpty()) sections += ChatAssetSection(kind, files.map(::toAssetItem))
+ }
+ val loose = chatDir.listFiles()
+ ?.filter { it.isFile }
+ ?.sortedByDescending { it.lastModified() }
+ .orEmpty()
+ if (loose.isNotEmpty()) sections += ChatAssetSection(null, loose.map(::toAssetItem))
+ return sections
+}
+
+private fun toAssetItem(file: File): ChatAssetItem = ChatAssetItem(
+ path = file.absolutePath,
+ name = file.name,
+ detail = "${file.extension.uppercase()} · ${FileResolver.formatSizeStatic(file.length())}"
+)
diff --git a/app/src/main/java/com/gotcha/ui/ChatScreen.kt b/app/src/main/java/com/gotcha/ui/ChatScreen.kt
index dcd4dd3..a7e0f95 100644
--- a/app/src/main/java/com/gotcha/ui/ChatScreen.kt
+++ b/app/src/main/java/com/gotcha/ui/ChatScreen.kt
@@ -127,6 +127,7 @@ fun ChatScreen(
onStopRecording: ((String) -> Unit) -> Unit = {},
onExportChat: () -> Unit = {},
onBackupChat: () -> Unit = {},
+ onOpenChatAssets: () -> Unit = {},
onReturnToRunning: () -> Unit = {},
onCreateShareCard: () -> Unit = {},
onEditMessage: (Long, String, List<ComposerAttachment>) -> Unit = { _, _, _ -> },
@@ -303,6 +304,7 @@ fun ChatScreen(
ChatOptionsMenu(
onExportChat = onExportChat,
onBackupChat = onBackupChat,
+ onOpenChatAssets = onOpenChatAssets,
onCreateShareCard = onCreateShareCard,
shareEnabled = !state.isBusy,
keptOutOfNotifications = chatKeptOutOfNotifications,
@@ -960,6 +962,7 @@ private fun UnreadBadge(count: Int, showCount: Boolean, modifier: Modifier = Mod
private fun ChatOptionsMenu(
onExportChat: () -> Unit,
onBackupChat: () -> Unit,
+ onOpenChatAssets: () -> Unit,
onCreateShareCard: () -> Unit,
shareEnabled: Boolean,
keptOutOfNotifications: Boolean,
@@ -1027,6 +1030,14 @@ private fun ChatOptionsMenu(
},
modifier = Modifier.testTag("chat_backup")
)
+ DropdownMenuItem(
+ text = { Text(stringResource(R.string.chat_assets)) },
+ onClick = {
+ expanded = false
+ onOpenChatAssets()
+ },
+ modifier = Modifier.testTag("chat_assets")
+ )
DropdownMenuItem(
text = { Text(stringResource(R.string.chat_create_share_card)) },
enabled = shareEnabled,
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 9bc2cf5..8b28c66 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1091,6 +1091,14 @@
<string name="chat_export_chat">Export chat</string>
<string name="chat_back_up_chat">Back up chat</string>
<string name="chat_create_share_card">Create share card</string>
+ <string name="chat_assets">Chat assets</string>
+ <string name="chat_assets_title">Chat assets</string>
+ <string name="chat_assets_empty">No files yet. Things Gotcha creates for this chat land here.</string>
+ <string name="chat_assets_pictures">Pictures</string>
+ <string name="chat_assets_recordings">Recordings</string>
+ <string name="chat_assets_screenshots">Screenshots</string>
+ <string name="chat_assets_other_files">Other files</string>
+ <string name="chat_assets_open_failed">Couldn\'t open that file.</string>
<string name="chat_keep_out_of_notifications">Keep out of notifications</string>
<string name="chat_stop_reading_aloud">Stop reading aloud</string>
<string name="chat_gotcha_logo">Gotcha logo</string>
diff --git a/app/src/test/java/com/gotcha/ui/ChatAssetSectionsTest.kt b/app/src/test/java/com/gotcha/ui/ChatAssetSectionsTest.kt
new file mode 100644
index 0000000..9cdd083
--- /dev/null
+++ b/app/src/test/java/com/gotcha/ui/ChatAssetSectionsTest.kt
@@ -0,0 +1,68 @@
+package com.gotcha.ui
+
+import com.gotcha.data.GotchaStorage
+import org.junit.Assert.assertEquals
+import org.junit.Assert.assertTrue
+import org.junit.Rule
+import org.junit.Test
+import org.junit.rules.TemporaryFolder
+import java.io.File
+
+/** Pure grouping behind ChatAssetsScreen: no Android framework needed. */
+class ChatAssetSectionsTest {
+
+ @get:Rule
+ val tmp = TemporaryFolder()
+
+ private fun file(dir: File, name: String, modified: Long): File {
+ dir.mkdirs()
+ return File(dir, name).apply {
+ writeText("x")
+ setLastModified(modified)
+ }
+ }
+
+ @Test
+ fun `empty folder has no sections`() {
+ assertTrue(chatAssetSections(tmp.root).isEmpty())
+ }
+
+ @Test
+ fun `kinds come first loose files last newest first`() {
+ val chatDir = tmp.root
+ file(File(chatDir, "Pictures"), "old.png", 1000)
+ file(File(chatDir, "Pictures"), "new.png", 3000)
+ file(chatDir, "note.md", 2000)
+
+ val sections = chatAssetSections(chatDir)
+
+ assertEquals(
+ listOf(GotchaStorage.Kind.PICTURES, null),
+ sections.map { it.kind }
+ )
+ assertEquals(listOf("new.png", "old.png"), sections[0].items.map { it.name })
+ assertEquals(listOf("note.md"), sections[1].items.map { it.name })
+ assertTrue(sections[0].items[0].detail.startsWith("PNG · "))
+ }
+
+ @Test
+ fun `empty kind folders are skipped`() {
+ val chatDir = tmp.root
+ File(chatDir, "Recordings").mkdirs()
+ file(chatDir, "audio.m4a", 1000)
+
+ val sections = chatAssetSections(chatDir)
+
+ // Only the loose file: the empty Recordings dir adds no section.
+ assertEquals(1, sections.size)
+ assertEquals(null, sections[0].kind)
+ }
+
+ @Test
+ fun `debug folders are not listed`() {
+ val chatDir = tmp.root
+ file(File(chatDir, GotchaStorage.Kind.DEBUG.dirName), "trace.txt", 1000)
+
+ assertTrue(chatAssetSections(chatDir).isEmpty())
+ }
+}