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 becomes a navigable browser with actions

Rishabh Bajpaie2c87dec8906
diff --git a/app/src/androidTest/java/com/gotcha/ChatAssetsNavTest.kt b/app/src/androidTest/java/com/gotcha/ChatAssetsNavTest.kt
index f464fd7..818f8b5 100644
--- a/app/src/androidTest/java/com/gotcha/ChatAssetsNavTest.kt
+++ b/app/src/androidTest/java/com/gotcha/ChatAssetsNavTest.kt
@@ -2,20 +2,25 @@ package com.gotcha
import androidx.compose.ui.test.hasContentDescription
import androidx.compose.ui.test.junit4.createEmptyComposeRule
+import androidx.compose.ui.test.longClick
+import androidx.compose.ui.test.onAllNodesWithText
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
+import androidx.compose.ui.test.performTouchInput
import androidx.test.core.app.ActivityScenario
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.gotcha.data.GotchaStorage
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
+import java.io.File
-/** Chat ⋮ menu ▸ Chat assets opens the per-chat file list; back returns. */
+/** Chat ⋮ menu ▸ Chat assets: browse folders, long-press for actions. */
@RunWith(AndroidJUnit4::class)
class ChatAssetsNavTest {
@@ -29,6 +34,7 @@ class ChatAssetsNavTest {
fun tearDown() {
runCatching { scenario?.close() }
mockLlm.shutdown()
+ GotchaStorage.resetRootPathForTests()
}
@Test
@@ -36,13 +42,67 @@ class ChatAssetsNavTest {
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.
+ seedSessionWithMessage(context, "assets-nav-empty", "Assets empty")
+ openChatFromDrawer("Assets empty")
+
+ // 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()
+ }
+
+ @Test
+ fun chatMenu_assets_browsesFoldersAndDeletes() {
+ mockLlm.start()
+ val context = ApplicationProvider.getApplicationContext<android.content.Context>()
+ TestSeed.seedConfigured(context, baseUrl = mockLlm.baseUrl)
+ seedSessionWithMessage(context, "assets-nav-test", "Assets nav")
+ // Point the chat-folder root at app-private storage: shared external
+ // storage needs All-files access the test device may not have, and the
+ // screen reads this same override in-process.
+ GotchaStorage.rootPath = File(context.filesDir, "assets-test-root").absolutePath
+ val chatDir = GotchaStorage.findOrCreateChatDir("assets-nav-test", "Assets nav")
+ File(chatDir, "docs").mkdirs()
+ File(chatDir, "docs/report.txt").writeText("hello")
+ openChatFromDrawer("Assets nav")
+
+ composeRule.onNodeWithTag("chat_options").performClick()
+ composeRule.waitForIdle()
+ composeRule.onNodeWithTag("chat_assets").performClick()
+ composeRule.waitForIdle()
+
+ // Into the subfolder, long-press the file, delete it with confirm.
+ composeRule.onNodeWithText("docs").performClick()
+ composeRule.waitForIdle()
+ composeRule.onNodeWithText("report.txt").assertExists()
+ composeRule.onNodeWithText("report.txt").performTouchInput { longClick() }
+ composeRule.waitForIdle()
+ composeRule.onNodeWithTag("chat_asset_share").assertExists()
+ composeRule.onNodeWithTag("chat_asset_delete").performClick()
+ composeRule.waitForIdle()
+ composeRule.onNodeWithTag("chat_asset_delete_yes").performClick()
+ composeRule.waitUntil(5000) {
+ composeRule.onAllNodesWithText("report.txt").fetchSemanticsNodes().isEmpty()
+ }
+
+ // Back up to the chat folder: the file is gone, the folder remains.
+ composeRule.onNodeWithTag("chat_assets_back").performClick()
+ composeRule.waitForIdle()
+ composeRule.onNodeWithText("docs").assertExists()
+ }
+
+ private fun seedSessionWithMessage(context: android.content.Context, id: String, title: String) {
kotlinx.coroutines.runBlocking {
com.gotcha.data.ChatHistoryRepository(context).saveSession(
com.gotcha.data.ChatSession(
- id = "assets-nav-test",
- title = "Assets nav",
+ id = id,
+ title = title,
lastModified = System.currentTimeMillis(),
messages = listOf(
com.gotcha.llm.ChatMessage(
@@ -61,23 +121,15 @@ class ChatAssetsNavTest {
touch = true
)
}
+ }
+
+ private fun openChatFromDrawer(title: String) {
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.onNodeWithText(title).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/java/com/gotcha/ui/ChatAssetsScreen.kt b/app/src/main/java/com/gotcha/ui/ChatAssetsScreen.kt
index 062a1a6..fe6a8eb 100644
--- a/app/src/main/java/com/gotcha/ui/ChatAssetsScreen.kt
+++ b/app/src/main/java/com/gotcha/ui/ChatAssetsScreen.kt
@@ -2,7 +2,8 @@ package com.gotcha.ui
import android.content.Intent
import android.webkit.MimeTypeMap
-import androidx.compose.foundation.clickable
+import androidx.activity.compose.BackHandler
+import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
@@ -13,18 +14,21 @@ 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.material.icons.filled.Folder
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.TextButton
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.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
@@ -37,35 +41,71 @@ import androidx.core.content.FileProvider
import com.gotcha.R
import com.gotcha.data.GotchaStorage
import com.gotcha.tools.FileResolver
+import com.gotcha.ui.theme.SkinAlertDialog
import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.launch
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).
+ * The files Gotcha created for one chat, browsable in place: folders open in
+ * the same list, files hand off to the system viewer through the app's
+ * FileProvider (gallery, player, reader — no in-app player to maintain), and
+ * a long press offers open/share/delete. Read-only apart from delete, which
+ * confirms first.
*/
-@OptIn(ExperimentalMaterial3Api::class)
+@OptIn(ExperimentalMaterial3Api::class, androidx.compose.foundation.ExperimentalFoundationApi::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>()) }
+ val scope = rememberCoroutineScope()
+ var root by remember(sessionId) { mutableStateOf<File?>(null) }
+ var currentPath by remember(sessionId) { mutableStateOf<String?>(null) }
+ var loaded by remember { mutableStateOf(false) }
+ var entries by remember { mutableStateOf(emptyList<ChatAssetEntry>()) }
+ var menuEntry by remember { mutableStateOf<ChatAssetEntry?>(null) }
+ var deleteEntry by remember { mutableStateOf<ChatAssetEntry?>(null) }
+
LaunchedEffect(sessionId) {
- sections = withContext(Dispatchers.IO) {
- GotchaStorage.findChatDir(sessionId)?.let(::chatAssetSections).orEmpty()
- }
+ root = withContext(Dispatchers.IO) { GotchaStorage.findChatDir(sessionId) }
+ currentPath = root?.absolutePath
loaded = true
}
+ LaunchedEffect(currentPath) {
+ val dir = currentPath?.let(::File)?.takeIf { it.isDirectory } ?: return@LaunchedEffect
+ entries = withContext(Dispatchers.IO) { chatDirEntries(dir) }
+ }
+
+ val canGoUp = root != null && currentPath != null && currentPath != root?.absolutePath
+ BackHandler {
+ if (canGoUp) {
+ currentPath = File(currentPath!!).parent
+ } else {
+ onBack()
+ }
+ }
Scaffold(
topBar = {
TopAppBar(
- title = { Text(stringResource(R.string.chat_assets_title)) },
+ title = {
+ Text(
+ if (canGoUp) {
+ File(currentPath!!).name
+ } else {
+ stringResource(R.string.chat_assets_title)
+ }
+ )
+ },
navigationIcon = {
IconButton(
- onClick = onBack,
+ onClick = {
+ if (canGoUp) {
+ currentPath = File(currentPath!!).parent
+ } else {
+ onBack()
+ }
+ },
modifier = Modifier.testTag("chat_assets_back")
) {
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = null)
@@ -75,9 +115,9 @@ fun ChatAssetsScreen(sessionId: String, onBack: () -> Unit) {
}
) { padding ->
if (!loaded) {
- // Still scanning; chat folders are small, no spinner.
+ // Still resolving the chat folder; it is one lookup, no spinner.
Unit
- } else if (sections.isEmpty()) {
+ } else if (root == null) {
Text(
text = stringResource(R.string.chat_assets_empty),
style = MaterialTheme.typography.bodyMedium,
@@ -88,43 +128,64 @@ fun ChatAssetsScreen(sessionId: String, onBack: () -> Unit) {
.padding(24.dp)
.testTag("chat_assets_empty")
)
+ } else if (entries.isEmpty()) {
+ Text(
+ text = stringResource(
+ if (canGoUp) {
+ R.string.chat_assets_empty_folder
+ } else {
+ 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(entries, key = { it.path }) { entry ->
+ Row(
+ modifier = Modifier
+ .fillMaxWidth()
+ .combinedClickable(
+ onClick = {
+ when (entry) {
+ is ChatAssetEntry.Folder -> currentPath = entry.path
+ is ChatAssetEntry.Asset -> openAsset(context, File(entry.path))
+ }
+ },
+ onLongClick = { menuEntry = entry }
+ )
+ .padding(horizontal = 16.dp, vertical = 10.dp)
+ .testTag("chat_asset_row"),
+ verticalAlignment = Alignment.CenterVertically
+ ) {
+ Icon(
+ if (entry is ChatAssetEntry.Folder) {
+ Icons.Default.Folder
+ } else {
+ Icons.Default.Description
+ },
+ contentDescription = null,
+ tint = MaterialTheme.colorScheme.onSurfaceVariant
)
- }
- 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 = entry.name,
+ style = MaterialTheme.typography.bodyMedium,
+ fontWeight = FontWeight.Medium
)
- Column(modifier = Modifier.padding(start = 12.dp)) {
- Text(
- text = item.name,
- style = MaterialTheme.typography.bodyMedium,
- fontWeight = FontWeight.Medium
- )
+ if (entry is ChatAssetEntry.Asset) {
Text(
- text = item.detail,
+ text = entry.detail,
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
@@ -135,17 +196,101 @@ fun ChatAssetsScreen(sessionId: String, onBack: () -> Unit) {
}
}
}
-}
-@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
+ menuEntry?.let { entry ->
+ SkinAlertDialog(
+ onDismissRequest = { menuEntry = null },
+ title = { Text(entry.name) },
+ text = {
+ Column {
+ TextButton(
+ onClick = {
+ menuEntry = null
+ when (entry) {
+ is ChatAssetEntry.Folder -> currentPath = entry.path
+ is ChatAssetEntry.Asset -> openAsset(context, File(entry.path))
+ }
+ },
+ modifier = Modifier.testTag("chat_asset_open")
+ ) { Text(stringResource(R.string.second_brain_open)) }
+ if (entry is ChatAssetEntry.Asset) {
+ TextButton(
+ onClick = {
+ menuEntry = null
+ shareAsset(context, File(entry.path))
+ },
+ modifier = Modifier.testTag("chat_asset_share")
+ ) { Text(stringResource(R.string.action_share)) }
+ }
+ TextButton(
+ onClick = {
+ menuEntry = null
+ deleteEntry = entry
+ },
+ modifier = Modifier.testTag("chat_asset_delete")
+ ) { Text(stringResource(R.string.drawer_delete)) }
+ TextButton(
+ onClick = { menuEntry = null },
+ modifier = Modifier.testTag("chat_asset_cancel")
+ ) { Text(stringResource(R.string.action_cancel)) }
+ }
+ },
+ confirmButton = {},
+ modifier = Modifier.testTag("chat_asset_menu")
+ )
}
-)
+
+ deleteEntry?.let { entry ->
+ SkinAlertDialog(
+ onDismissRequest = { deleteEntry = null },
+ title = { Text(stringResource(R.string.chat_assets_delete_title)) },
+ text = { Text(stringResource(R.string.chat_assets_delete_confirm, entry.name)) },
+ confirmButton = {
+ TextButton(
+ onClick = {
+ deleteEntry = null
+ val pathAtDelete = currentPath
+ scope.launch(Dispatchers.IO) {
+ val target = File(entry.path)
+ val deleted = if (target.isDirectory) {
+ target.deleteRecursively()
+ } else {
+ target.delete()
+ }
+ val fresh = pathAtDelete?.let(::File)
+ ?.takeIf { it.isDirectory }
+ ?.let(::chatDirEntries)
+ .orEmpty()
+ withContext(Dispatchers.Main) {
+ // Refresh inline: the path is unchanged by a
+ // delete, so the path-watching scan would not
+ // retrigger. Skip if the user navigated away
+ // mid-delete rather than show a stale folder.
+ if (currentPath == pathAtDelete) {
+ entries = fresh
+ }
+ if (deleted) {
+ android.widget.Toast.makeText(
+ context,
+ context.getString(R.string.chat_assets_deleted),
+ android.widget.Toast.LENGTH_SHORT
+ ).show()
+ }
+ }
+ }
+ },
+ modifier = Modifier.testTag("chat_asset_delete_yes")
+ ) { Text(stringResource(R.string.drawer_delete)) }
+ },
+ dismissButton = {
+ TextButton(onClick = { deleteEntry = null }) {
+ Text(stringResource(R.string.action_cancel))
+ }
+ },
+ modifier = Modifier.testTag("chat_asset_delete_confirm")
+ )
+ }
+}
private fun openAsset(context: android.content.Context, file: File) {
val opened = runCatching {
@@ -173,36 +318,70 @@ private fun openAsset(context: android.content.Context, file: File) {
}
}
-/** One file on the assets screen, with its display strings precomputed. */
-data class ChatAssetItem(val path: String, val name: String, val detail: String)
+private fun shareAsset(context: android.content.Context, file: File) {
+ val shared = runCatching {
+ val uri = FileProvider.getUriForFile(
+ context,
+ "${context.packageName}.fileprovider",
+ file
+ )
+ val mime = MimeTypeMap.getSingleton()
+ .getMimeTypeFromExtension(file.extension) ?: "*/*"
+ val intent = Intent(Intent.ACTION_SEND).apply {
+ type = mime
+ putExtra(Intent.EXTRA_STREAM, uri)
+ addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
+ }
+ context.startActivity(
+ Intent.createChooser(intent, null).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+ )
+ true
+ }.getOrDefault(false)
+ if (!shared) {
+ android.widget.Toast.makeText(
+ context,
+ context.getString(R.string.chat_assets_open_failed),
+ android.widget.Toast.LENGTH_SHORT
+ ).show()
+ }
+}
+
+/** One row in the browser: a subfolder, or a file with its display detail. */
+sealed interface ChatAssetEntry {
+ val name: String
+ val path: String
-/** One named group: a media kind, or null for loose files. */
-data class ChatAssetSection(val kind: GotchaStorage.Kind?, val items: List<ChatAssetItem>)
+ data class Folder(override val name: String, override val path: String) : ChatAssetEntry
+
+ data class Asset(
+ override val name: String,
+ override val path: String,
+ val detail: String
+ ) : ChatAssetEntry
+}
/**
- * 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
+ * Lists one folder's visible contents: subfolders first (A–Z), then files
+ * (newest first). Dot-prefixed entries (`.debug`, `.nomedia`) stay hidden,
+ * like any file manager. 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
+fun chatDirEntries(dir: File): List<ChatAssetEntry> {
+ val children = dir.listFiles()?.filter {
+ !it.name.startsWith(".")
+ }.orEmpty()
+ val folders = children
+ .filter { it.isDirectory }
+ .sortedBy { it.name.lowercase() }
+ .map { ChatAssetEntry.Folder(it.name, it.absolutePath) }
+ val files = children
+ .filter { it.isFile }
+ .sortedByDescending { it.lastModified() }
+ .map(::toAssetEntry)
+ return folders + files
}
-private fun toAssetItem(file: File): ChatAssetItem = ChatAssetItem(
+private fun toAssetEntry(file: File): ChatAssetEntry.Asset = ChatAssetEntry.Asset(
path = file.absolutePath,
name = file.name,
detail = "${file.extension.uppercase()} · ${FileResolver.formatSizeStatic(file.length())}"
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 8b28c66..1a3407b 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1094,10 +1094,10 @@
<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_empty_folder">This folder is empty.</string>
+ <string name="chat_assets_delete_title">Delete?</string>
+ <string name="chat_assets_delete_confirm">Delete %1$s? This can\'t be undone.</string>
+ <string name="chat_assets_deleted">Deleted.</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>
diff --git a/app/src/test/java/com/gotcha/ui/ChatAssetSectionsTest.kt b/app/src/test/java/com/gotcha/ui/ChatAssetSectionsTest.kt
index 9cdd083..aa82bd5 100644
--- a/app/src/test/java/com/gotcha/ui/ChatAssetSectionsTest.kt
+++ b/app/src/test/java/com/gotcha/ui/ChatAssetSectionsTest.kt
@@ -8,7 +8,7 @@ import org.junit.Test
import org.junit.rules.TemporaryFolder
import java.io.File
-/** Pure grouping behind ChatAssetsScreen: no Android framework needed. */
+/** Pure listing behind ChatAssetsScreen: no Android framework needed. */
class ChatAssetSectionsTest {
@get:Rule
@@ -23,46 +23,42 @@ class ChatAssetSectionsTest {
}
@Test
- fun `empty folder has no sections`() {
- assertTrue(chatAssetSections(tmp.root).isEmpty())
+ fun `empty folder has no entries`() {
+ assertTrue(chatDirEntries(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)
+ fun `folders first alphabetical then files newest first`() {
+ val dir = tmp.root
+ file(File(dir, "zebra"), "a.txt", 1000)
+ file(File(dir, "apple"), "b.txt", 1000)
+ file(File(dir, "Pictures"), "old.png", 1000)
+ file(File(dir, "Pictures"), "new.png", 3000)
+ file(dir, "note.md", 2000)
- val sections = chatAssetSections(chatDir)
+ val entries = chatDirEntries(dir)
- assertEquals(
- listOf(GotchaStorage.Kind.PICTURES, null),
- sections.map { it.kind }
+ val folders = entries.filterIsInstance<ChatAssetEntry.Folder>().map { it.name }
+ assertEquals(listOf("apple", "Pictures", "zebra"), folders)
+ val files = entries.filterIsInstance<ChatAssetEntry.Asset>()
+ assertEquals(listOf("new.png", "old.png", "note.md"), files.map { it.name })
+ assertTrue(files[0].detail.startsWith("PNG · "))
+ // Every folder sorts before every file.
+ assertTrue(
+ entries.indexOfLast { it is ChatAssetEntry.Folder } <
+ entries.indexOfFirst { it is ChatAssetEntry.Asset }
)
- 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)
+ fun `dot entries stay hidden`() {
+ val dir = tmp.root
+ file(File(dir, GotchaStorage.Kind.DEBUG.dirName), "trace.txt", 1000)
+ file(dir, ".nomedia", 1000)
+ file(dir, "visible.txt", 1000)
- val sections = chatAssetSections(chatDir)
+ val entries = chatDirEntries(dir)
- // 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())
+ assertEquals(listOf("visible.txt"), entries.map { it.name })
}
}