Modern Apps git

← Modern-Apps.git

files: dialogs as routes, scaffold search, directory capture

Commit
1ee294a60e1a4d747bef984fd893d55b8a89f20a
Author
Vayun Mathur <[email protected]>
When
2026-12-02 08:25 UTC (4 days ago)
Parents
9b12d94
Convert every remember-state-gated dialog in the files module to a
Route dialog destination with DialogPage() metadata: ArchiveDialog,
RenameDialog, NewFolderDialog, NewFileDialog and PropertiesDialog
(identity in route args, item resolved by key in the entry),
EmptyTrashDialog, and the view-model-driven PermanentDeleteDialog
(count in args) and EnableNotificationsDialog, which the navigation
layer pushes when the view model calls for them. Dialog content is
stateless under ui/dialogs/ (PropertiesDialog already lived there;
Archive/Rename/Name/EmptyTrash/PermanentDelete/EnableNotifications
join it), entries live in ui/FilesDialogEntries.kt, and confirming
acts through the shared FilesActions so the view-model flows reload
the listing underneath - the module's existing result mechanism.
FilesShell no longer renders any dialog.

Move directory search into the scaffold: DirectoryScreenCore passes
ScaffoldSearch to AppScaffold while search is active (query via
FilesActions.setSearchQuery, focus requester preserved for Ctrl+F/L
autofocus), and DirectoryTitle renders only the breadcrumb trail or
category title - no standalone search TextField. The now-dead
onClearRenameTarget plumbing comes out of DirectoryBody/Listing.

Add the missing Directory screenshot capture with fixed fixtures
(9-directory: a Documents listing) plus one capture per new dialog
route (10-archive-dialog through 17-enable-notifications-dialog),
all with fixed names/sizes and no clock or randomness.

Update files/AGENTS.md (dialog/search conventions, new files;
DirectoryDialogs.kt becomes DirectoryLabels.kt holding only the
sort/section helpers). Tests that drove dialogs through screen-local
state now drive them through the request callbacks with the dialog
content rendered by a minimal test host, and the shell test covers
the two dialog contents directly.

Verified: fresh ./gradlew :files:lintVitalRelease --rerun-tasks
(189 tasks executed), :files:lint and :files:testDevUnitTest green
(137 tests, 0 failures/errors/skipped). No exception markers used.

Diff

files/AGENTS.md
diff --git a/files/AGENTS.md b/files/AGENTS.mdindex c3c9c4e3bd..f62bcd8f8b 100644--- a/files/AGENTS.md+++ b/files/AGENTS.md@@ -18,6 +18,7 @@ _Install: ./install files (dev by default)._ - SAF surfaces (`DocumentPickerActivity`, `StorageUris`) so other apps can pick files here - OpenAssistant name search (`files_search_files` via `intents/SearchFilesIntent`): filename text query over the MediaStore index, limit clamped to 10, returning name + folder label + size + modified only — no file contents and no full paths **Architecture / data-flow:** `ui/FilesShell` + directory pages → `platform/FilesViewModel` (+ `FilesUiContract`) → `platform/FilesListing` over SAF/MediaStore; long ops run in `ZipWorker`/`UnzipWorker` with `ProgressNotificationWorker` surfacing progress.+**Dialogs / search:** every dialog is a `Route` destination with `DialogPage()` metadata (`ArchiveDialog`, `RenameDialog`, `NewFolderDialog`, `NewFileDialog`, `PropertiesDialog`, `EmptyTrashDialog`, `PermanentDeleteDialog`, `EnableNotificationsDialog` — entries in `ui/FilesDialogEntries.kt`, identity in route args, stateless content under `ui/dialogs/`, results through the shared `FilesViewModel` actions/flows). The navigation layer pushes `PermanentDeleteDialog`/`EnableNotificationsDialog` when the view model calls for them. Screen-level search goes through the scaffold's `search` slot (`ScaffoldSearch` in `DirectoryScreenCore`); `DirectoryTitle` renders only breadcrumbs/category title. **Entry points + reading order:** `Route` → `MainActivity.kt` → `Navigation.kt` → `ui/FilesShell.kt` → `platform/FilesViewModel.kt` → `platform/FilesListing.kt`. **Gotchas:** - File ops must survive process death — they belong in workers, never in the ViewModel@@ -53,7 +54,8 @@ _Install: ./install files (dev by default)._ - com/vayunmathur/files/ui/DirectoryBreadcrumbs.kt - com/vayunmathur/files/ui/DirectoryLeading.kt - com/vayunmathur/files/ui/DirectoryMenus.kt-- com/vayunmathur/files/ui/DirectoryDialogs.kt+- com/vayunmathur/files/ui/DirectoryLabels.kt+- com/vayunmathur/files/ui/FilesDialogEntries.kt - com/vayunmathur/files/ui/DirectoryParentPane.kt - com/vayunmathur/files/ui/HomeScreen.kt - com/vayunmathur/files/ui/HomeScreenBinder.kt@@ -61,6 +63,12 @@ _Install: ./install files (dev by default)._ - com/vayunmathur/files/ui/components/DirectoryItem.kt - com/vayunmathur/files/ui/components/GridItem.kt - com/vayunmathur/files/ui/dialogs/PropertiesDialog.kt+- com/vayunmathur/files/ui/dialogs/ArchiveDialog.kt+- com/vayunmathur/files/ui/dialogs/RenameDialog.kt+- com/vayunmathur/files/ui/dialogs/NameDialog.kt+- com/vayunmathur/files/ui/dialogs/EmptyTrashDialog.kt+- com/vayunmathur/files/ui/dialogs/PermanentDeleteDialog.kt+- com/vayunmathur/files/ui/dialogs/EnableNotificationsDialog.kt  ## Verify (this module only) ```
files/src/main/java/com/vayunmathur/files/Navigation.kt
diff --git a/files/src/main/java/com/vayunmathur/files/Navigation.kt b/files/src/main/java/com/vayunmathur/files/Navigation.ktindex fc842ab3b7..3bdfbf6c87 100644--- a/files/src/main/java/com/vayunmathur/files/Navigation.kt+++ b/files/src/main/java/com/vayunmathur/files/Navigation.kt@@ -1,13 +1,20 @@ package com.vayunmathur.files +import android.content.pm.PackageManager+import android.os.Build import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect+import androidx.compose.runtime.collectAsState+import androidx.compose.runtime.getValue import androidx.compose.runtime.remember+import androidx.compose.ui.platform.LocalContext+import androidx.core.content.ContextCompat import com.vayunmathur.files.platform.FilesViewModel import com.vayunmathur.files.ui.DirectoryPage import com.vayunmathur.files.ui.FilesShell import com.vayunmathur.files.ui.HomeScreenBinder import com.vayunmathur.files.ui.TrashPage+import com.vayunmathur.files.ui.filesDialogEntries import com.vayunmathur.files.ui.filesNavActions import com.vayunmathur.library.util.MainNavigation import com.vayunmathur.library.util.rememberNavBackStack@@ -23,6 +30,7 @@ import java.io.File fun Navigation(viewModel: FilesViewModel) {     val backStack = rememberNavBackStack<Route>(Route.Home)     val actions = remember(viewModel, backStack) { filesNavActions(viewModel, backStack) }+    val context = LocalContext.current      // An archive becomes a destination only once the view model has confirmed it opens, so a corrupt     // zip reports an error where the user is instead of navigating into a listing that cannot load.@@ -30,6 +38,34 @@ fun Navigation(viewModel: FilesViewModel) {         viewModel.zipOpened.collect { backStack.add(Route.Zip(it.absolutePath)) }     } +    // The permanent-delete confirmation is a dialog destination pushed while the view model+    // reports items the system trash cannot take; the entry settles that pending state.+    val pendingPermanentDelete by viewModel.pendingPermanentDelete.collectAsState()+    LaunchedEffect(pendingPermanentDelete) {+        val pending = pendingPermanentDelete+        if (pending != null && backStack.backStack.lastOrNull() !is Route.PermanentDeleteDialog) {+            backStack.add(Route.PermanentDeleteDialog(pending.size))+        }+    }++    // The notification-permission rationale is likewise a dialog destination, pushed once when+    // files access is granted and the prompt has not been shown; either choice marks it shown.+    val isFilesGranted by viewModel.isFilesGranted.collectAsState()+    val hasPromptedNotifications by viewModel.hasPromptedNotifications.collectAsState()+    LaunchedEffect(isFilesGranted, hasPromptedNotifications) {+        val sdkOk = Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU+        if (isFilesGranted && !hasPromptedNotifications && sdkOk) {+            val isGranted =+                ContextCompat.checkSelfPermission(context, "android.permission.POST_NOTIFICATIONS") ==+                    PackageManager.PERMISSION_GRANTED+            if (isGranted) {+                viewModel.setNotificationsPrompted()+            } else if (backStack.backStack.lastOrNull() !is Route.EnableNotificationsDialog) {+                backStack.add(Route.EnableNotificationsDialog)+            }+        }+    }+     FilesShell(viewModel, actions) { openDrawer ->         MainNavigation(backStack) {             entry<Route.Home> {@@ -42,7 +78,19 @@ fun Navigation(viewModel: FilesViewModel) {                 LaunchedEffect(route, isCurrent) {                     if (isCurrent) viewModel.navigateTo(File(route.path))                 }-                DirectoryPage(viewModel, actions, isCurrent, openDrawer)+                DirectoryPage(+                    viewModel = viewModel,+                    actions = actions,+                    isCurrent = isCurrent,+                    onOpenDrawer = openDrawer,+                    onRenameRequest = { backStack.add(Route.RenameDialog(it.key, it.name)) },+                    onShowPropertiesRequest = {+                        backStack.add(Route.PropertiesDialog(it.key, it.name))+                    },+                    onArchiveRequest = { backStack.add(Route.ArchiveDialog(it)) },+                    onShowNewFolderRequest = { backStack.add(Route.NewFolderDialog) },+                    onShowNewFileRequest = { backStack.add(Route.NewFileDialog) },+                )             }             // A category listing spans every folder, so it has nowhere to go "up" to: it always             // sits directly on Home rather than on the folder it was opened from.@@ -51,14 +99,38 @@ fun Navigation(viewModel: FilesViewModel) {                 LaunchedEffect(route, isCurrent) {                     if (isCurrent) viewModel.openCategory(route.category)                 }-                DirectoryPage(viewModel, actions, isCurrent, openDrawer)+                DirectoryPage(+                    viewModel = viewModel,+                    actions = actions,+                    isCurrent = isCurrent,+                    onOpenDrawer = openDrawer,+                    onRenameRequest = { backStack.add(Route.RenameDialog(it.key, it.name)) },+                    onShowPropertiesRequest = {+                        backStack.add(Route.PropertiesDialog(it.key, it.name))+                    },+                    onArchiveRequest = { backStack.add(Route.ArchiveDialog(it)) },+                    onShowNewFolderRequest = { backStack.add(Route.NewFolderDialog) },+                    onShowNewFileRequest = { backStack.add(Route.NewFileDialog) },+                )             }             entry<Route.Zip> { route ->                 val isCurrent = backStack.last() == route                 LaunchedEffect(route, isCurrent) {                     if (isCurrent) viewModel.showZip(File(route.zipPath), route.internalPath)                 }-                DirectoryPage(viewModel, actions, isCurrent, openDrawer)+                DirectoryPage(+                    viewModel = viewModel,+                    actions = actions,+                    isCurrent = isCurrent,+                    onOpenDrawer = openDrawer,+                    onRenameRequest = { backStack.add(Route.RenameDialog(it.key, it.name)) },+                    onShowPropertiesRequest = {+                        backStack.add(Route.PropertiesDialog(it.key, it.name))+                    },+                    onArchiveRequest = { backStack.add(Route.ArchiveDialog(it)) },+                    onShowNewFolderRequest = { backStack.add(Route.NewFolderDialog) },+                    onShowNewFileRequest = { backStack.add(Route.NewFileDialog) },+                )             }             // The system trash is a flat listing like a category: nowhere to go "up" to, so it             // always sits directly on Home rather than on the folder it was opened from.@@ -67,8 +139,15 @@ fun Navigation(viewModel: FilesViewModel) {                 LaunchedEffect(isCurrent) {                     if (isCurrent) viewModel.showTrash()                 }-                TrashPage(viewModel, actions, isCurrent, openDrawer)+                TrashPage(+                    viewModel = viewModel,+                    actions = actions,+                    isCurrent = isCurrent,+                    onOpenDrawer = openDrawer,+                    onEmptyTrashRequest = { backStack.add(Route.EmptyTrashDialog) },+                )             }+            filesDialogEntries(backStack, viewModel, actions)         }     } }
files/src/main/java/com/vayunmathur/files/Route.kt
diff --git a/files/src/main/java/com/vayunmathur/files/Route.kt b/files/src/main/java/com/vayunmathur/files/Route.ktindex 73ef33f75a..32c5e5252b 100644--- a/files/src/main/java/com/vayunmathur/files/Route.kt+++ b/files/src/main/java/com/vayunmathur/files/Route.kt@@ -43,4 +43,43 @@ sealed interface Route : NavKey {      */     @Serializable     data class Zip(val zipPath: String, val internalPath: String = "") : Route++    /** Archive-name dialog over a directory/category/zip listing: the prefilled name for the current selection. */+    @Serializable+    data class ArchiveDialog(val initialName: String) : Route++    /** Rename dialog for the selected item identified by [itemKey]; [itemName] seeds the field. */+    @Serializable+    data class RenameDialog(val itemKey: String, val itemName: String) : Route++    /** New-folder name dialog over the current listing. */+    @Serializable+    data object NewFolderDialog : Route++    /** New-file name dialog over the current listing. */+    @Serializable+    data object NewFileDialog : Route++    /** Properties dialog for the selected item identified by [itemKey]. */+    @Serializable+    data class PropertiesDialog(val itemKey: String, val itemName: String) : Route++    /** Empty-trash confirmation dialog over [Trash]. */+    @Serializable+    data object EmptyTrashDialog : Route++    /**+     * Permanent-delete confirmation for [count] items the system trash cannot take. Pushed by the+     * navigation layer when the view model reports a pending permanent delete; confirming or+     * dismissing settles that pending state in the view model.+     */+    @Serializable+    data class PermanentDeleteDialog(val count: Int) : Route++    /**+     * Notification-permission rationale dialog. Pushed once by the navigation layer when files+     * access is granted and the prompt has not been shown yet; either choice marks it shown.+     */+    @Serializable+    data object EnableNotificationsDialog : Route }
files/src/main/java/com/vayunmathur/files/ui/DirectoryBody.kt
diff --git a/files/src/main/java/com/vayunmathur/files/ui/DirectoryBody.kt b/files/src/main/java/com/vayunmathur/files/ui/DirectoryBody.ktindex 5f05ee3c62..e2503acb9f 100644--- a/files/src/main/java/com/vayunmathur/files/ui/DirectoryBody.kt+++ b/files/src/main/java/com/vayunmathur/files/ui/DirectoryBody.kt@@ -25,7 +25,6 @@ fun DirectoryBody(     isReadOnly: Boolean,     isCategory: Boolean,     padding: PaddingValues,-    onClearRenameTarget: () -> Unit, ) {     // Expanded windows (desktop, large tablets) list the parent folder beside the current     // one. This stays inside the same destination on purpose: files deliberately has no@@ -50,7 +49,6 @@ fun DirectoryBody(                 canModifyHere = canModifyHere,                 isReadOnly = isReadOnly,                 modifier = modifier,-                onClearRenameTarget = onClearRenameTarget,             )         },     )
files/src/main/java/com/vayunmathur/files/ui/DirectoryBreadcrumbs.kt
diff --git a/files/src/main/java/com/vayunmathur/files/ui/DirectoryBreadcrumbs.kt b/files/src/main/java/com/vayunmathur/files/ui/DirectoryBreadcrumbs.ktindex 90bba8d8e5..71590c6ce5 100644--- a/files/src/main/java/com/vayunmathur/files/ui/DirectoryBreadcrumbs.kt+++ b/files/src/main/java/com/vayunmathur/files/ui/DirectoryBreadcrumbs.kt@@ -7,11 +7,9 @@ import androidx.compose.foundation.draganddrop.dragAndDropTarget import androidx.compose.foundation.horizontalScroll import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Row-import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.rememberScrollState 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@@ -19,28 +17,26 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draganddrop.mimeTypes-import androidx.compose.ui.focus.FocusRequester-import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.graphics.Color-import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp-import com.vayunmathur.files.R import com.vayunmathur.files.platform.FilesActions import com.vayunmathur.files.platform.FilesUiState import com.vayunmathur.library.ui.IconChevronRight import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.Text-import com.vayunmathur.library.ui.TextField import java.io.File -/** Title slot for [DirectoryScreen]: search field, category title, or breadcrumb trail. */+/**+ * Title slot for [DirectoryScreen]: the category title, or the breadcrumb trail. Screen-level+ * search is not rendered here — the scaffold owns it through its `search` slot, which replaces+ * this title while search is active.+ */ @Composable internal fun DirectoryTitle(     state: FilesUiState,     actions: FilesActions,     isCategory: Boolean,     isReadOnly: Boolean,-    searchFocusRequester: FocusRequester, ) {     DirectoryTitle(         rootDirectory = state.rootDirectory,@@ -48,13 +44,10 @@ internal fun DirectoryTitle(         currentDirectory = state.currentDirectory,         zipPath = state.zipPath,         zipInternalPath = state.zipInternalPath,-        isSearchActive = state.isSearchActive,-        searchQuery = state.searchQuery,         categoryTitle = state.categoryTitle,         actions = actions,         isCategory = isCategory,         isReadOnly = isReadOnly,-        searchFocusRequester = searchFocusRequester,     ) } @@ -65,13 +58,10 @@ internal fun DirectoryTitle(     currentDirectory: File,     zipPath: File?,     zipInternalPath: String,-    isSearchActive: Boolean,-    searchQuery: String,     categoryTitle: String?,     actions: FilesActions,     isCategory: Boolean,     isReadOnly: Boolean,-    searchFocusRequester: FocusRequester, ) {     val root = rootDirectory     val breadcrumbs = remember(@@ -98,19 +88,7 @@ internal fun DirectoryTitle(         crumbs     } -    if (isSearchActive) {-        TextField(-            value = searchQuery,-            onValueChange = { actions.setSearchQuery(it) },-            placeholder = { Text(stringResource(R.string.search_files)) },-            singleLine = true,-            modifier = Modifier-                .fillMaxWidth()-                .focusRequester(searchFocusRequester),-        )-        // Autofocus on activation; Ctrl+F/L re-requests via the hoisted requester.-        LaunchedEffect(Unit) { searchFocusRequester.requestFocus() }-    } else if (isCategory) {+    if (isCategory) {         Text(categoryTitle.orEmpty(), style = MaterialTheme.typography.titleLarge)     } else {         Row(
files/src/main/java/com/vayunmathur/files/ui/DirectoryDialogs.kt
diff --git a/files/src/main/java/com/vayunmathur/files/ui/DirectoryDialogs.kt b/files/src/main/java/com/vayunmathur/files/ui/DirectoryDialogs.ktdeleted file mode 100644index 644ee6f621..0000000000--- a/files/src/main/java/com/vayunmathur/files/ui/DirectoryDialogs.kt+++ /dev/null@@ -1,99 +0,0 @@-package com.vayunmathur.files.ui--import androidx.compose.foundation.layout.padding-import androidx.compose.foundation.text.KeyboardActions-import androidx.compose.foundation.text.KeyboardOptions-import androidx.compose.runtime.Composable-import androidx.compose.runtime.getValue-import androidx.compose.runtime.mutableStateOf-import androidx.compose.runtime.remember-import androidx.compose.runtime.setValue-import androidx.compose.ui.Modifier-import androidx.compose.ui.res.pluralStringResource-import androidx.compose.ui.res.stringResource-import androidx.compose.ui.text.input.ImeAction-import androidx.compose.ui.unit.dp-import com.vayunmathur.files.R-import com.vayunmathur.files.platform.SortBy-import com.vayunmathur.library.ui.AlertDialog-import com.vayunmathur.library.ui.MaterialTheme-import com.vayunmathur.library.ui.Text-import com.vayunmathur.library.ui.TextButton-import com.vayunmathur.library.ui.TextField-import com.vayunmathur.library.ui.R as UiR--@Composable-internal fun sortLabel(sortBy: SortBy): String = stringResource(-    when (sortBy) {-        SortBy.NAME -> UiR.string.name-        SortBy.DATE -> UiR.string.date-        SortBy.SIZE -> R.string.sort_size-        SortBy.TYPE -> R.string.sort_type-    }-)--@Composable-internal fun NameDialog(-    title: String,-    label: String,-    initial: String,-    confirmLabel: String,-    onConfirm: (String) -> Unit,-    onDismiss: () -> Unit,-) {-    var name by remember { mutableStateOf(initial) }-    AlertDialog(-        onDismissRequest = onDismiss,-        title = { Text(title) },-        text = {-            TextField(-                value = name,-                onValueChange = { name = it },-                label = { Text(label) },-                singleLine = true,-                keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),-                keyboardActions = KeyboardActions(onDone = { if (name.isNotBlank()) onConfirm(name) }),-            )-        },-        confirmButton = {-            TextButton(onClick = { if (name.isNotBlank()) onConfirm(name) }) { Text(confirmLabel) }-        },-        dismissButton = {-            TextButton(onClick = onDismiss) { Text(stringResource(UiR.string.cancel)) }-        },-    )-}--@Composable-internal fun SectionHeader(text: String) {-    Text(-        text,-        style = MaterialTheme.typography.titleSmall,-        color = MaterialTheme.colorScheme.primary,-        modifier = Modifier.padding(start = 16.dp, top = 16.dp, bottom = 4.dp),-    )-}--/**- * Confirms permanent deletion of items the system trash cannot take (folders, files with no- * MediaStore entry). Shared between the directory flow and the trash screen's empty-trash- * path, so it lives here next to [NameDialog].- */-@Composable-internal fun PermanentDeleteDialog(-    count: Int,-    onConfirm: () -> Unit,-    onDismiss: () -> Unit,-) {-    AlertDialog(-        onDismissRequest = onDismiss,-        title = { Text(pluralStringResource(R.plurals.delete_permanently_title, count, count)) },-        text = { Text(stringResource(R.string.delete_permanently_message)) },-        confirmButton = {-            TextButton(onClick = onConfirm) { Text(stringResource(UiR.string.delete)) }-        },-        dismissButton = {-            TextButton(onClick = onDismiss) { Text(stringResource(UiR.string.cancel)) }-        },-    )-}
files/src/main/java/com/vayunmathur/files/ui/DirectoryLabels.kt
diff --git a/files/src/main/java/com/vayunmathur/files/ui/DirectoryLabels.kt b/files/src/main/java/com/vayunmathur/files/ui/DirectoryLabels.ktnew file mode 100644index 0000000000..af99779611--- /dev/null+++ b/files/src/main/java/com/vayunmathur/files/ui/DirectoryLabels.kt@@ -0,0 +1,34 @@+package com.vayunmathur.files.ui++import androidx.compose.foundation.layout.padding+import androidx.compose.runtime.Composable+import androidx.compose.ui.Modifier+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.unit.dp+import com.vayunmathur.files.R+import com.vayunmathur.files.platform.SortBy+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.R as UiR++/** Sort-option label for the directory overflow menu. */+@Composable+internal fun sortLabel(sortBy: SortBy): String = stringResource(+    when (sortBy) {+        SortBy.NAME -> UiR.string.name+        SortBy.DATE -> UiR.string.date+        SortBy.SIZE -> R.string.sort_size+        SortBy.TYPE -> R.string.sort_type+    }+)++/** Section heading inside the directory parent pane. */+@Composable+internal fun SectionHeader(text: String) {+    Text(+        text,+        style = MaterialTheme.typography.titleSmall,+        color = MaterialTheme.colorScheme.primary,+        modifier = Modifier.padding(start = 16.dp, top = 16.dp, bottom = 4.dp),+    )+}
files/src/main/java/com/vayunmathur/files/ui/DirectoryListing.kt
diff --git a/files/src/main/java/com/vayunmathur/files/ui/DirectoryListing.kt b/files/src/main/java/com/vayunmathur/files/ui/DirectoryListing.ktindex d46b4d8a45..0fa855841d 100644--- a/files/src/main/java/com/vayunmathur/files/ui/DirectoryListing.kt+++ b/files/src/main/java/com/vayunmathur/files/ui/DirectoryListing.kt@@ -47,8 +47,6 @@ internal fun DirectoryListing(     canModifyHere: Boolean,     isReadOnly: Boolean,     modifier: Modifier = Modifier,-    /** Clears the rename dialog target; owned by [DirectoryScreen]. */-    onClearRenameTarget: () -> Unit = {}, ) {     DirectoryListing(         directories = state.directories,@@ -64,7 +62,6 @@ internal fun DirectoryListing(         canModifyHere = canModifyHere,         isReadOnly = isReadOnly,         modifier = modifier,-        onClearRenameTarget = onClearRenameTarget,     ) } @@ -81,8 +78,6 @@ internal fun DirectoryListing(     canModifyHere: Boolean,     isReadOnly: Boolean,     modifier: Modifier = Modifier,-    /** Clears the rename dialog target; owned by [DirectoryScreen]. */-    onClearRenameTarget: () -> Unit = {},     /**      * Recursive-search hits for a non-blank query, flattened with parent      * subtitles. Null keeps the current-folder fast path/filter (blank query,@@ -141,7 +136,6 @@ internal fun DirectoryListing(             }             val onItemLongClick: (FileBrowserItem) -> Unit = { child ->                 if (!isReadOnly) {-                    onClearRenameTarget()                     actions.toggleSelection(child)                 }             }
files/src/main/java/com/vayunmathur/files/ui/DirectoryPage.kt
diff --git a/files/src/main/java/com/vayunmathur/files/ui/DirectoryPage.kt b/files/src/main/java/com/vayunmathur/files/ui/DirectoryPage.ktindex 9f284a24f8..f967da258e 100644--- a/files/src/main/java/com/vayunmathur/files/ui/DirectoryPage.kt+++ b/files/src/main/java/com/vayunmathur/files/ui/DirectoryPage.kt@@ -44,6 +44,11 @@ fun DirectoryPage(     actions: FilesActions,     isCurrent: Boolean,     onOpenDrawer: () -> Unit = {},+    onRenameRequest: (FileBrowserItem) -> Unit = {},+    onShowPropertiesRequest: (FileBrowserItem) -> Unit = {},+    onArchiveRequest: (initialName: String) -> Unit = {},+    onShowNewFolderRequest: () -> Unit = {},+    onShowNewFileRequest: () -> Unit = {}, ) {     val context = LocalContext.current     val resources = LocalResources.current@@ -93,16 +98,23 @@ fun DirectoryPage(             }         } -    // Lowest common consumer for selectedPaths/isSearchActive: DirectoryScreenCore.+    // Lowest common consumer for selectedPaths/isSearchActive/searchQuery: DirectoryScreenCore.     val selectedPaths by viewModel.selectedPaths.collectAsStateWithLifecycle()     val isSearchActive by viewModel.isSearchActive.collectAsStateWithLifecycle()+    val searchQuery by viewModel.searchQuery.collectAsStateWithLifecycle()     DirectoryScreenCore(         selectedPaths = frozen(isCurrent, selectedPaths),         isSearchActive = frozen(isCurrent, isSearchActive),+        searchQuery = frozen(isCurrent, searchQuery),         actions = actions,         snackbarHostState = snackbarHostState,         onOpenDrawer = onOpenDrawer,-        title = { searchFocus -> DirectoryTitleLive(viewModel, actions, isCurrent, searchFocus) },+        onRenameRequest = onRenameRequest,+        onShowPropertiesRequest = onShowPropertiesRequest,+        onArchiveRequest = onArchiveRequest,+        onShowNewFolderRequest = onShowNewFolderRequest,+        onShowNewFileRequest = onShowNewFileRequest,+        title = { DirectoryTitleLive(viewModel, actions, isCurrent) },         topActions = { onRename, onShowProperties, onArchive, onShowNewFolder, onShowNewFile ->             DirectoryTopActionsLive(                 viewModel = viewModel,@@ -116,8 +128,8 @@ fun DirectoryPage(                 onShowNewFile = onShowNewFile,             )         },-        body = { padding, onClearRenameTarget ->-            DirectoryBodyLive(viewModel, actions, isCurrent, padding, onClearRenameTarget)+        body = { padding ->+            DirectoryBodyLive(viewModel, actions, isCurrent, padding)         },     ) }@@ -138,13 +150,10 @@ private fun DirectoryTitleLive(     viewModel: FilesViewModel,     actions: FilesActions,     isCurrent: Boolean,-    searchFocusRequester: androidx.compose.ui.focus.FocusRequester, ) {     val currentDirectory by viewModel.currentDirectory.collectAsStateWithLifecycle()     val zipPath by viewModel.zipPath.collectAsStateWithLifecycle()     val zipInternalPath by viewModel.zipInternalPath.collectAsStateWithLifecycle()-    val isSearchActive by viewModel.isSearchActive.collectAsStateWithLifecycle()-    val searchQuery by viewModel.searchQuery.collectAsStateWithLifecycle()     val categoryTitle by viewModel.categoryTitle.collectAsStateWithLifecycle()     val shownZipPath = frozen(isCurrent, zipPath)     val shownCategoryTitle = frozen(isCurrent, categoryTitle)@@ -154,13 +163,10 @@ private fun DirectoryTitleLive(         currentDirectory = frozen(isCurrent, currentDirectory),         zipPath = shownZipPath,         zipInternalPath = frozen(isCurrent, zipInternalPath),-        isSearchActive = frozen(isCurrent, isSearchActive),-        searchQuery = frozen(isCurrent, searchQuery),         categoryTitle = shownCategoryTitle,         actions = actions,         isCategory = shownCategoryTitle != null,         isReadOnly = shownZipPath != null,-        searchFocusRequester = searchFocusRequester,     ) } @@ -213,7 +219,6 @@ private fun DirectoryBodyLive(     actions: FilesActions,     isCurrent: Boolean,     padding: PaddingValues,-    onClearRenameTarget: () -> Unit, ) {     val currentDirectory by viewModel.currentDirectory.collectAsStateWithLifecycle()     val zipPath by viewModel.zipPath.collectAsStateWithLifecycle()@@ -236,7 +241,6 @@ private fun DirectoryBodyLive(                 canModifyHere = canModifyHere,                 isReadOnly = isReadOnly,                 modifier = modifier,-                onClearRenameTarget = onClearRenameTarget,             )         },     )@@ -277,7 +281,6 @@ private fun DirectoryListingLive(     canModifyHere: Boolean,     isReadOnly: Boolean,     modifier: Modifier,-    onClearRenameTarget: () -> Unit, ) {     val entries by viewModel.entries.collectAsStateWithLifecycle()     val categoryTitle by viewModel.categoryTitle.collectAsStateWithLifecycle()@@ -309,6 +312,5 @@ private fun DirectoryListingLive(         canModifyHere = canModifyHere,         isReadOnly = isReadOnly,         modifier = modifier,-        onClearRenameTarget = onClearRenameTarget,     ) }
files/src/main/java/com/vayunmathur/files/ui/DirectoryScreen.kt
diff --git a/files/src/main/java/com/vayunmathur/files/ui/DirectoryScreen.kt b/files/src/main/java/com/vayunmathur/files/ui/DirectoryScreen.ktindex acdb23b4fb..e5e7ecd29c 100644--- a/files/src/main/java/com/vayunmathur/files/ui/DirectoryScreen.kt+++ b/files/src/main/java/com/vayunmathur/files/ui/DirectoryScreen.kt@@ -5,39 +5,33 @@ import androidx.compose.foundation.clickable import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.padding-import androidx.compose.foundation.text.KeyboardActions-import androidx.compose.foundation.text.KeyboardOptions 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.Modifier+import androidx.compose.ui.focus.FocusRequester+import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.input.key.onPreviewKeyEvent import androidx.compose.ui.platform.LocalFocusManager import androidx.compose.ui.res.stringResource-import androidx.compose.ui.text.input.ImeAction import com.vayunmathur.files.R import com.vayunmathur.files.platform.FileBrowserItem import com.vayunmathur.files.platform.FilesActions import com.vayunmathur.files.platform.FilesUiState-import com.vayunmathur.files.ui.dialogs.PropertiesDialog-import com.vayunmathur.library.ui.AlertDialog import com.vayunmathur.library.ui.AppScaffold import com.vayunmathur.library.ui.ExperimentalMaterial3Api import com.vayunmathur.library.ui.IconButton import com.vayunmathur.library.ui.IconMenu+import com.vayunmathur.library.ui.ScaffoldSearch import com.vayunmathur.library.ui.SnackbarHost import com.vayunmathur.library.ui.SnackbarHostState-import com.vayunmathur.library.ui.Text-import com.vayunmathur.library.ui.TextButton-import com.vayunmathur.library.ui.TextField-import com.vayunmathur.library.ui.R as UiR  /**  * The directory browser, with no dependency on the ViewModel so it can be rendered from a  * `@Preview` — see `src/screenshotTest`, which is where the store listing images come from.+ *+ * Dialogs are navigation destinations, not state held here: the `on…Request` callbacks ask+ * the host (the navigation layer in the live app) to push the matching dialog route.  */ @OptIn(ExperimentalMaterial3Api::class) @Composable@@ -50,6 +44,11 @@ fun DirectoryScreen(     onPickUnzipDestination: () -> Unit = {},     /** Opens the navigation drawer. */     onOpenDrawer: () -> Unit = {},+    onRenameRequest: (FileBrowserItem) -> Unit = {},+    onShowPropertiesRequest: (FileBrowserItem) -> Unit = {},+    onArchiveRequest: (initialName: String) -> Unit = {},+    onShowNewFolderRequest: () -> Unit = {},+    onShowNewFileRequest: () -> Unit = {}, ) {     val isReadOnly = state.zipPath != null     val isCategory = state.categoryTitle != null@@ -60,16 +59,21 @@ fun DirectoryScreen(     DirectoryScreenCore(         selectedPaths = state.selectedPaths,         isSearchActive = state.isSearchActive,+        searchQuery = state.searchQuery,         actions = actions,         snackbarHostState = snackbarHostState,         onOpenDrawer = onOpenDrawer,-        title = { searchFocusRequester ->+        onRenameRequest = onRenameRequest,+        onShowPropertiesRequest = onShowPropertiesRequest,+        onArchiveRequest = onArchiveRequest,+        onShowNewFolderRequest = onShowNewFolderRequest,+        onShowNewFileRequest = onShowNewFileRequest,+        title = {             DirectoryTitle(                 state = state,                 actions = actions,                 isCategory = isCategory,                 isReadOnly = isReadOnly,-                searchFocusRequester = searchFocusRequester,             )         },         topActions = { onRename, onShowProperties, onArchive, onShowNewFolder, onShowNewFile ->@@ -86,7 +90,7 @@ fun DirectoryScreen(                 onShowNewFile = onShowNewFile,             )         },-        body = { padding, onClearRenameTarget ->+        body = { padding ->             DirectoryBody(                 state = state,                 actions = actions,@@ -94,30 +98,35 @@ fun DirectoryScreen(                 isReadOnly = isReadOnly,                 isCategory = isCategory,                 padding = padding,-                onClearRenameTarget = onClearRenameTarget,             )         },     ) }  /**- * Scaffold, dialogs and Back handling for the directory browser.+ * Scaffold, search and Back handling for the directory browser.  *- * Only [selectedPaths] and [isSearchActive] are read here: they are the lowest common- * consumer for those flows (Back, the nav icon, clearing the rename target and the- * archive name all need them alongside the sections). Every other flow is collected- * by the section composable that consumes it — see the live binders in `DirectoryPage`.- * The stateless [DirectoryScreen] above supplies the same slots from a [FilesUiState].+ * Only [selectedPaths], [isSearchActive] and [searchQuery] are read here: they are the+ * lowest common consumer for those flows (Back, the nav icon, the scaffold search field+ * and the sections). Every other flow is collected by the section composable that+ * consumes it — see the live binders in `DirectoryPage`. The stateless [DirectoryScreen]+ * above supplies the same slots from a [FilesUiState].  */ @OptIn(ExperimentalMaterial3Api::class) @Composable internal fun DirectoryScreenCore(     selectedPaths: Set<FileBrowserItem>,     isSearchActive: Boolean,+    searchQuery: String,     actions: FilesActions,     snackbarHostState: SnackbarHostState,     onOpenDrawer: () -> Unit,-    title: @Composable (androidx.compose.ui.focus.FocusRequester) -> Unit,+    onRenameRequest: (FileBrowserItem) -> Unit,+    onShowPropertiesRequest: (FileBrowserItem) -> Unit,+    onArchiveRequest: (initialName: String) -> Unit,+    onShowNewFolderRequest: () -> Unit,+    onShowNewFileRequest: () -> Unit,+    title: @Composable () -> Unit,     topActions: @Composable (         onRename: (FileBrowserItem) -> Unit,         onShowProperties: (FileBrowserItem) -> Unit,@@ -125,112 +134,20 @@ internal fun DirectoryScreenCore(         onShowNewFolder: () -> Unit,         onShowNewFile: () -> Unit,     ) -> Unit,-    body: @Composable (padding: PaddingValues, onClearRenameTarget: () -> Unit) -> Unit,+    body: @Composable (padding: PaddingValues) -> Unit, ) {-    var itemBeingRenamed by remember { mutableStateOf<FileBrowserItem?>(null) }-    var itemForProperties by remember { mutableStateOf<FileBrowserItem?>(null) }-    var showArchiveDialog by remember { mutableStateOf(false) }-    var archiveName by remember { mutableStateOf("archive.zip") }-    var showNewFolderDialog by remember { mutableStateOf(false) }-    var showNewFileDialog by remember { mutableStateOf(false) }--    LaunchedEffect(selectedPaths) {-        if (selectedPaths.isEmpty()) itemBeingRenamed = null-    }--    if (showArchiveDialog) {-        AlertDialog(-            onDismissRequest = { showArchiveDialog = false },-            title = { Text(stringResource(R.string.archive_selection)) },-            text = {-                TextField(-                    value = archiveName,-                    onValueChange = { archiveName = it },-                    label = { Text(stringResource(R.string.zip_file_name_label)) },-                    singleLine = true-                )-            },-            confirmButton = {-                TextButton(-                    onClick = {-                        actions.archive(archiveName)-                        showArchiveDialog = false-                    }) { Text(stringResource(R.string.archive)) }-            },-            dismissButton = {-                TextButton(onClick = { showArchiveDialog = false }) {-                    Text(stringResource(UiR.string.cancel))-                }-            })-    }--    itemBeingRenamed?.let { renaming ->-        var newName by remember(renaming.key) { mutableStateOf(renaming.name) }-        AlertDialog(-            onDismissRequest = { itemBeingRenamed = null },-            title = { Text(stringResource(UiR.string.rename)) },-            text = {-                TextField(-                    value = newName,-                    onValueChange = { newName = it },-                    label = { Text(stringResource(R.string.new_name_label)) },-                    singleLine = true,-                    keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),-                    keyboardActions = KeyboardActions(onDone = {-                        actions.rename(renaming, newName)-                        itemBeingRenamed = null-                    })-                )-            },-            confirmButton = {-                TextButton(onClick = {-                    actions.rename(renaming, newName)-                    itemBeingRenamed = null-                }) { Text(stringResource(UiR.string.rename)) }-            },-            dismissButton = {-                TextButton(onClick = { itemBeingRenamed = null }) {-                    Text(stringResource(UiR.string.cancel))-                }-            })-    }--    if (showNewFolderDialog) {-        NameDialog(-            title = stringResource(R.string.new_folder),-            label = stringResource(R.string.folder_name_label),-            initial = "",-            confirmLabel = stringResource(UiR.string.create),-            onConfirm = { actions.createFolder(it); showNewFolderDialog = false },-            onDismiss = { showNewFolderDialog = false },-        )-    }-    if (showNewFileDialog) {-        NameDialog(-            title = stringResource(R.string.new_file),-            label = stringResource(R.string.file_name_label),-            initial = "untitled.txt",-            confirmLabel = stringResource(UiR.string.create),-            onConfirm = { actions.createFile(it); showNewFileDialog = false },-            onDismiss = { showNewFileDialog = false },-        )-    }-    itemForProperties?.let { item ->-        PropertiesDialog(item = item, onDismiss = { itemForProperties = null })-    }-     val focusManager = LocalFocusManager.current-    // Hoisted so the desktop shortcut handler below can (re)focus the search-    // field in DirectoryTitle; activating search also autofocuses it there.-    val searchFocusRequester = remember { androidx.compose.ui.focus.FocusRequester() }-    val anyDialogOpen = showArchiveDialog || itemBeingRenamed != null ||-        showNewFolderDialog || showNewFileDialog || itemForProperties != null+    // Hoisted so the desktop shortcut handler below can (re)focus the scaffold+    // search field; activating search also autofocuses it.+    val searchFocusRequester = remember { FocusRequester() }+    LaunchedEffect(isSearchActive) {+        if (isSearchActive) searchFocusRequester.requestFocus()+    }      // Only the parts of Back that are not navigation. Folder, archive and category depth are back     // stack entries now, so everything else has to fall through to the navigation host - swallowing     // it here would also swallow the predictive-back gesture and its preview.     BackHandler(isSearchActive || selectedPaths.isNotEmpty()) {-        itemBeingRenamed = null         if (isSearchActive) actions.setSearchActive(false) else actions.handleBack()     } @@ -239,7 +156,7 @@ internal fun DirectoryScreenCore(             .onPreviewKeyEvent { event ->                 handleDirectoryKey(                     event = event,-                    dialogOpen = anyDialogOpen,+                    dialogOpen = false,                     isSearchActive = isSearchActive,                     hasSelection = selectedPaths.isNotEmpty(),                     onFocusSearch = {@@ -255,7 +172,6 @@ internal fun DirectoryScreenCore(                 interactionSource = remember { MutableInteractionSource() }, indication = null             ) {                 focusManager.clearFocus()-                itemBeingRenamed = null                 actions.clearSelection()             },         snackbarHost = { SnackbarHost(snackbarHostState) },@@ -264,22 +180,34 @@ internal fun DirectoryScreenCore(                     IconButton(onClick = onOpenDrawer) { IconMenu() }                 }             },-        title = { title(searchFocusRequester) },+        title = title,+        // Screen-level search belongs to the scaffold: while active it renders the shared+        // field as the top bar (title replaced), with the query flowing to the view model.+        search = if (isSearchActive) {+            ScaffoldSearch(+                query = searchQuery,+                onQueryChange = { actions.setSearchQuery(it) },+                placeholder = stringResource(R.string.search_files),+                modifier = Modifier.focusRequester(searchFocusRequester),+            )+        } else {+            null+        },         actions = {             topActions(-                { itemBeingRenamed = it },-                { itemForProperties = it },+                onRenameRequest,+                onShowPropertiesRequest,                 {-                    archiveName =+                    onArchiveRequest(                         if (selectedPaths.size == 1) "${selectedPaths.first().name}.zip"                         else "archive.zip"-                    showArchiveDialog = true+                    )                 },-                { showNewFolderDialog = true },-                { showNewFileDialog = true },+                onShowNewFolderRequest,+                onShowNewFileRequest,             )         },     ) { padding ->-        body(padding) { itemBeingRenamed = null }+        body(padding)     } }
files/src/main/java/com/vayunmathur/files/ui/FilesDialogEntries.kt
diff --git a/files/src/main/java/com/vayunmathur/files/ui/FilesDialogEntries.kt b/files/src/main/java/com/vayunmathur/files/ui/FilesDialogEntries.ktnew file mode 100644index 0000000000..a304869cc2--- /dev/null+++ b/files/src/main/java/com/vayunmathur/files/ui/FilesDialogEntries.kt@@ -0,0 +1,129 @@+package com.vayunmathur.files.ui++import android.os.Build+import androidx.compose.runtime.Composable+import androidx.compose.runtime.LaunchedEffect+import androidx.compose.runtime.remember+import androidx.compose.ui.res.stringResource+import com.vayunmathur.files.R+import com.vayunmathur.files.Route+import com.vayunmathur.files.platform.FileBrowserItem+import com.vayunmathur.files.platform.FilesActions+import com.vayunmathur.files.platform.FilesViewModel+import com.vayunmathur.files.ui.dialogs.ArchiveDialog+import com.vayunmathur.files.ui.dialogs.EmptyTrashDialog+import com.vayunmathur.files.ui.dialogs.EnableNotificationsDialog+import com.vayunmathur.files.ui.dialogs.NameDialog+import com.vayunmathur.files.ui.dialogs.PermanentDeleteDialog+import com.vayunmathur.files.ui.dialogs.PropertiesDialog+import com.vayunmathur.files.ui.dialogs.RenameDialog+import com.vayunmathur.library.ui.R as UiR+import com.vayunmathur.library.ui.rememberPermissionRequest+import com.vayunmathur.library.util.DialogPage+import com.vayunmathur.library.util.EntryProviderScope+import com.vayunmathur.library.util.NavBackStack++/**+ * Dialog destinations for files: every dialog is a [Route] with `DialogPage()` metadata, the+ * identity it acts on in the route arguments, and a stateless content composable under+ * `ui/dialogs/` that the entry renders unconditionally. Confirming acts through the shared+ * [FilesActions] (the view model is the module's result mechanism: its flows reload the+ * listing underneath) and pops; dismissing only pops, except where noted.+ */+fun EntryProviderScope<Route>.filesDialogEntries(+    backStack: NavBackStack<Route>,+    viewModel: FilesViewModel,+    actions: FilesActions,+) {+    entry<Route.ArchiveDialog>(metadata = DialogPage()) { route ->+        ArchiveDialog(+            initialName = route.initialName,+            onConfirm = { name -> actions.archive(name); backStack.pop() },+            onDismiss = { backStack.pop() },+        )+    }+    entry<Route.RenameDialog>(metadata = DialogPage()) { route ->+        val item = remember(route.itemKey) { viewModel.findItem(route.itemKey) }+        RenameDialog(+            itemName = route.itemName,+            onConfirm = { newName -> item?.let { actions.rename(it, newName) }; backStack.pop() },+            onDismiss = { backStack.pop() },+        )+    }+    entry<Route.NewFolderDialog>(metadata = DialogPage()) {+        NameDialog(+            title = stringResource(R.string.new_folder),+            label = stringResource(R.string.folder_name_label),+            initial = "",+            confirmLabel = stringResource(UiR.string.create),+            onConfirm = { name -> actions.createFolder(name); backStack.pop() },+            onDismiss = { backStack.pop() },+        )+    }+    entry<Route.NewFileDialog>(metadata = DialogPage()) {+        NameDialog(+            title = stringResource(R.string.new_file),+            label = stringResource(R.string.file_name_label),+            initial = "untitled.txt",+            confirmLabel = stringResource(UiR.string.create),+            onConfirm = { name -> actions.createFile(name); backStack.pop() },+            onDismiss = { backStack.pop() },+        )+    }+    entry<Route.PropertiesDialog>(metadata = DialogPage()) { route ->+        val item = remember(route.itemKey) { viewModel.findItem(route.itemKey) }+        if (item != null) {+            PropertiesDialog(item = item, onDismiss = { backStack.pop() })+        } else {+            LaunchedEffect(route.itemKey) { backStack.pop() }+        }+    }+    entry<Route.EmptyTrashDialog>(metadata = DialogPage()) {+        EmptyTrashDialog(+            onConfirm = { actions.emptyTrash(); backStack.pop() },+            onDismiss = { backStack.pop() },+        )+    }+    entry<Route.PermanentDeleteDialog>(metadata = DialogPage()) { route ->+        PermanentDeleteDialog(+            count = route.count,+            onConfirm = { actions.confirmPermanentDelete(); backStack.pop() },+            onDismiss = { actions.dismissPermanentDelete(); backStack.pop() },+        )+    }+    entry<Route.EnableNotificationsDialog>(metadata = DialogPage()) {+        EnableNotificationsDialogHost(backStack, viewModel)+    }+}++@Composable+private fun EnableNotificationsDialogHost(+    backStack: NavBackStack<Route>,+    viewModel: FilesViewModel,+) {+    val notificationsRequest =+        rememberPermissionRequest("android.permission.POST_NOTIFICATIONS") {+            viewModel.setNotificationsPrompted()+            backStack.pop()+        }+    EnableNotificationsDialog(+        onConfirm = {+            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {+                notificationsRequest()+            } else {+                viewModel.setNotificationsPrompted()+                backStack.pop()+            }+        },+        onDismiss = {+            viewModel.setNotificationsPrompted()+            backStack.pop()+        },+    )+}++/** The item a dialog route acts on, resolved from the live selection/listing by its stable key. */+private fun FilesViewModel.findItem(itemKey: String): FileBrowserItem? =+    selectedPaths.value.firstOrNull { it.key == itemKey }+        ?: entries.value.let { it.first + it.second }.firstOrNull { it.key == itemKey }+        ?: trashedItems.value.firstOrNull { it.key == itemKey }
files/src/main/java/com/vayunmathur/files/ui/FilesShell.kt
diff --git a/files/src/main/java/com/vayunmathur/files/ui/FilesShell.kt b/files/src/main/java/com/vayunmathur/files/ui/FilesShell.ktindex d1a9abb15d..31bd01a92d 100644--- a/files/src/main/java/com/vayunmathur/files/ui/FilesShell.kt+++ b/files/src/main/java/com/vayunmathur/files/ui/FilesShell.kt@@ -1,10 +1,7 @@ package com.vayunmathur.files.ui -import android.Manifest import android.content.Intent-import android.content.pm.PackageManager import android.net.Uri-import android.os.Build import android.provider.Settings import androidx.activity.compose.rememberLauncherForActivityResult import androidx.activity.result.contract.ActivityResultContracts@@ -17,10 +14,7 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.collectAsState 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 import androidx.compose.ui.draganddrop.DragAndDropEvent@@ -29,13 +23,11 @@ import androidx.compose.ui.draganddrop.toAndroidDragEvent import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp-import androidx.core.content.ContextCompat import com.vayunmathur.files.R import com.vayunmathur.files.platform.FileBrowserItem import com.vayunmathur.files.platform.FileCategory import com.vayunmathur.files.platform.FilesActions import com.vayunmathur.files.platform.FilesViewModel-import com.vayunmathur.library.ui.AlertDialog import com.vayunmathur.library.ui.Button import com.vayunmathur.library.ui.DrawerValue import com.vayunmathur.library.ui.IconDelete@@ -53,16 +45,15 @@ import com.vayunmathur.library.ui.ModalNavigationDrawer import com.vayunmathur.library.ui.NavigationDrawerItem import com.vayunmathur.library.ui.R as UiR import com.vayunmathur.library.ui.Text-import com.vayunmathur.library.ui.TextButton import com.vayunmathur.library.ui.rememberDrawerState-import com.vayunmathur.library.ui.rememberPermissionRequest import kotlinx.coroutines.launch import java.io.File   /**- * The chrome that is the same on every destination: the all-files permission gate, the notification- * prompt, and the navigation drawer.+ * The chrome that is the same on every destination: the all-files permission gate and the+ * navigation drawer. Dialogs are navigation destinations inside the nav host (see+ * `filesDialogEntries`), so none are rendered here.  *  * Wraps the nav host rather than living inside it, so the drawer is not rebuilt on every navigation  * and stays open across one. [content] is handed the callback that opens it, because the drawer state@@ -76,58 +67,12 @@ fun FilesShell( ) {     val context = LocalContext.current     val isFilesGranted by viewModel.isFilesGranted.collectAsState()-    val hasPromptedNotifications by viewModel.hasPromptedNotifications.collectAsState()-    var showNotificationDialog by remember { mutableStateOf(false) }      val filesLauncher =         rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) {             viewModel.refreshPermissions()         } -    val notificationsRequest =-        rememberPermissionRequest("android.permission.POST_NOTIFICATIONS") {-            viewModel.setNotificationsPrompted()-            showNotificationDialog = false-        }--    LaunchedEffect(isFilesGranted, hasPromptedNotifications) {-        if (isFilesGranted && !hasPromptedNotifications && Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {-            val isGranted = ContextCompat.checkSelfPermission(-                context, "android.permission.POST_NOTIFICATIONS"-            ) == PackageManager.PERMISSION_GRANTED-            if (!isGranted) {-                showNotificationDialog = true-            } else {-                viewModel.setNotificationsPrompted()-            }-        }-    }--    if (showNotificationDialog) {-        AlertDialog(-            onDismissRequest = {-                viewModel.setNotificationsPrompted()-                showNotificationDialog = false-            },-            title = { Text(stringResource(R.string.enable_notifications)) },-            text = { Text(stringResource(R.string.notification_permission_rationale)) },-            confirmButton = {-                TextButton(-                    onClick = {-                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {-                            notificationsRequest()-                        }-                    }) { Text(stringResource(R.string.enable)) }-            },-            dismissButton = {-                TextButton(-                    onClick = {-                        viewModel.setNotificationsPrompted()-                        showNotificationDialog = false-                    }) { Text(stringResource(R.string.skip)) }-            })-    }-     if (!isFilesGranted) {         Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {             Column(@@ -150,7 +95,6 @@ fun FilesShell(         }     } else {         val bookmarks by viewModel.bookmarks.collectAsState()-        val pendingPermanentDelete by viewModel.pendingPermanentDelete.collectAsState()         val drawerState = rememberDrawerState(DrawerValue.Closed)         val scope = rememberCoroutineScope() @@ -173,16 +117,6 @@ fun FilesShell(             }         } -        // Permanent-delete confirmation for items the system trash cannot take (folders,-        // unindexed files). Shared by the directory and trash flows, so it sits above both.-        pendingPermanentDelete?.let { pending ->-            PermanentDeleteDialog(-                count = pending.size,-                onConfirm = { actions.confirmPermanentDelete() },-                onDismiss = { actions.dismissPermanentDelete() },-            )-        }-         ModalNavigationDrawer(             drawerState = drawerState,             drawerContent = {
files/src/main/java/com/vayunmathur/files/ui/TrashPage.kt
diff --git a/files/src/main/java/com/vayunmathur/files/ui/TrashPage.kt b/files/src/main/java/com/vayunmathur/files/ui/TrashPage.ktindex 1200ca12e9..d90810a755 100644--- a/files/src/main/java/com/vayunmathur/files/ui/TrashPage.kt+++ b/files/src/main/java/com/vayunmathur/files/ui/TrashPage.kt@@ -29,6 +29,7 @@ fun TrashPage(     actions: FilesActions,     isCurrent: Boolean,     onOpenDrawer: () -> Unit = {},+    onEmptyTrashRequest: () -> Unit = {}, ) {     val snackbarHostState = remember { SnackbarHostState() } @@ -53,5 +54,6 @@ fun TrashPage(         actions = actions,         snackbarHostState = snackbarHostState,         onOpenDrawer = onOpenDrawer,+        onEmptyTrashRequest = onEmptyTrashRequest,     ) }
files/src/main/java/com/vayunmathur/files/ui/TrashScreen.kt
diff --git a/files/src/main/java/com/vayunmathur/files/ui/TrashScreen.kt b/files/src/main/java/com/vayunmathur/files/ui/TrashScreen.ktindex 4e709ff828..65552c3bc5 100644--- a/files/src/main/java/com/vayunmathur/files/ui/TrashScreen.kt+++ b/files/src/main/java/com/vayunmathur/files/ui/TrashScreen.kt@@ -26,7 +26,6 @@ import com.vayunmathur.files.R import com.vayunmathur.files.platform.FileBrowserItem import com.vayunmathur.files.platform.FilesActions import com.vayunmathur.files.platform.TrashUiState-import com.vayunmathur.library.ui.AlertDialog import com.vayunmathur.library.ui.AppScaffold import com.vayunmathur.library.ui.HorizontalDivider import com.vayunmathur.library.ui.IconButton@@ -43,8 +42,6 @@ import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.SnackbarHost import com.vayunmathur.library.ui.SnackbarHostState import com.vayunmathur.library.ui.Text-import com.vayunmathur.library.ui.TextButton-import com.vayunmathur.library.ui.R as UiR  /**  * The system-trash browser, with no dependency on the ViewModel so it can be rendered from a@@ -56,31 +53,11 @@ fun TrashScreen(     actions: FilesActions,     snackbarHostState: SnackbarHostState = remember { SnackbarHostState() },     onOpenDrawer: () -> Unit = {},+    /** Asks the host to push the `Route.EmptyTrashDialog` destination. */+    onEmptyTrashRequest: () -> Unit = {}, ) {-    var showEmptyConfirm by remember { mutableStateOf(false) }     var showOverflow by remember { mutableStateOf(false) } -    if (showEmptyConfirm) {-        AlertDialog(-            onDismissRequest = { showEmptyConfirm = false },-            title = { Text(stringResource(R.string.empty_trash)) },-            text = { Text(stringResource(R.string.delete_permanently_message)) },-            confirmButton = {-                TextButton(-                    onClick = {-                        actions.emptyTrash()-                        showEmptyConfirm = false-                    },-                ) { Text(stringResource(R.string.delete_forever)) }-            },-            dismissButton = {-                TextButton(onClick = { showEmptyConfirm = false }) {-                    Text(stringResource(UiR.string.cancel))-                }-            },-        )-    }-     BackHandler(state.selectedItems.isNotEmpty()) {         actions.clearTrashSelection()     }@@ -107,7 +84,7 @@ fun TrashScreen(                     DropdownMenuItem(                         text = { Text(stringResource(R.string.empty_trash)) },                         leadingIcon = { IconDeleteForever() },-                        onClick = { showOverflow = false; showEmptyConfirm = true },+                        onClick = { showOverflow = false; onEmptyTrashRequest() },                     )                 }             }
files/src/main/java/com/vayunmathur/files/ui/dialogs/ArchiveDialog.kt
diff --git a/files/src/main/java/com/vayunmathur/files/ui/dialogs/ArchiveDialog.kt b/files/src/main/java/com/vayunmathur/files/ui/dialogs/ArchiveDialog.ktnew file mode 100644index 0000000000..350f115138--- /dev/null+++ b/files/src/main/java/com/vayunmathur/files/ui/dialogs/ArchiveDialog.kt@@ -0,0 +1,48 @@+package com.vayunmathur.files.ui.dialogs++import androidx.compose.runtime.Composable+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember+import androidx.compose.runtime.setValue+import androidx.compose.ui.res.stringResource+import com.vayunmathur.files.R+import com.vayunmathur.library.ui.AlertDialog+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.TextButton+import com.vayunmathur.library.ui.TextField+import com.vayunmathur.library.ui.R as UiR++/**+ * Archive-name dialog for `Route.ArchiveDialog`, stateless apart from the+ * name field itself: the initial name travels in the route, confirming+ * reports the entered name and dismissing reports nothing.+ */+@Composable+fun ArchiveDialog(+    initialName: String,+    onConfirm: (String) -> Unit,+    onDismiss: () -> Unit,+) {+    var archiveName by remember(initialName) { mutableStateOf(initialName) }+    AlertDialog(+        onDismissRequest = onDismiss,+        title = { Text(stringResource(R.string.archive_selection)) },+        text = {+            TextField(+                value = archiveName,+                onValueChange = { archiveName = it },+                label = { Text(stringResource(R.string.zip_file_name_label)) },+                singleLine = true,+            )+        },+        confirmButton = {+            TextButton(onClick = { onConfirm(archiveName) }) {+                Text(stringResource(R.string.archive))+            }+        },+        dismissButton = {+            TextButton(onClick = onDismiss) { Text(stringResource(UiR.string.cancel)) }+        },+    )+}
files/src/main/java/com/vayunmathur/files/ui/dialogs/EmptyTrashDialog.kt
diff --git a/files/src/main/java/com/vayunmathur/files/ui/dialogs/EmptyTrashDialog.kt b/files/src/main/java/com/vayunmathur/files/ui/dialogs/EmptyTrashDialog.ktnew file mode 100644index 0000000000..715b185d3c--- /dev/null+++ b/files/src/main/java/com/vayunmathur/files/ui/dialogs/EmptyTrashDialog.kt@@ -0,0 +1,31 @@+package com.vayunmathur.files.ui.dialogs++import androidx.compose.runtime.Composable+import androidx.compose.ui.res.stringResource+import com.vayunmathur.files.R+import com.vayunmathur.library.ui.AlertDialog+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.TextButton+import com.vayunmathur.library.ui.R as UiR++/**+ * Empty-trash confirmation for `Route.EmptyTrashDialog`, stateless:+ * confirming reports the choice, dismissing reports nothing.+ */+@Composable+fun EmptyTrashDialog(+    onConfirm: () -> Unit,+    onDismiss: () -> Unit,+) {+    AlertDialog(+        onDismissRequest = onDismiss,+        title = { Text(stringResource(R.string.empty_trash)) },+        text = { Text(stringResource(R.string.delete_permanently_message)) },+        confirmButton = {+            TextButton(onClick = onConfirm) { Text(stringResource(R.string.delete_forever)) }+        },+        dismissButton = {+            TextButton(onClick = onDismiss) { Text(stringResource(UiR.string.cancel)) }+        },+    )+}
files/src/main/java/com/vayunmathur/files/ui/dialogs/EnableNotificationsDialog.kt
diff --git a/files/src/main/java/com/vayunmathur/files/ui/dialogs/EnableNotificationsDialog.kt b/files/src/main/java/com/vayunmathur/files/ui/dialogs/EnableNotificationsDialog.ktnew file mode 100644index 0000000000..9d6cdf769f--- /dev/null+++ b/files/src/main/java/com/vayunmathur/files/ui/dialogs/EnableNotificationsDialog.kt@@ -0,0 +1,31 @@+package com.vayunmathur.files.ui.dialogs++import androidx.compose.runtime.Composable+import androidx.compose.ui.res.stringResource+import com.vayunmathur.files.R+import com.vayunmathur.library.ui.AlertDialog+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.TextButton++/**+ * Notification-permission rationale for `Route.EnableNotificationsDialog`,+ * stateless: confirming asks the host to launch the permission request,+ * dismissing reports the skip. Either way the host marks the prompt shown.+ */+@Composable+fun EnableNotificationsDialog(+    onConfirm: () -> Unit,+    onDismiss: () -> Unit,+) {+    AlertDialog(+        onDismissRequest = onDismiss,+        title = { Text(stringResource(R.string.enable_notifications)) },+        text = { Text(stringResource(R.string.notification_permission_rationale)) },+        confirmButton = {+            TextButton(onClick = onConfirm) { Text(stringResource(R.string.enable)) }+        },+        dismissButton = {+            TextButton(onClick = onDismiss) { Text(stringResource(R.string.skip)) }+        },+    )+}
files/src/main/java/com/vayunmathur/files/ui/dialogs/NameDialog.kt
diff --git a/files/src/main/java/com/vayunmathur/files/ui/dialogs/NameDialog.kt b/files/src/main/java/com/vayunmathur/files/ui/dialogs/NameDialog.ktnew file mode 100644index 0000000000..d86e5f4605--- /dev/null+++ b/files/src/main/java/com/vayunmathur/files/ui/dialogs/NameDialog.kt@@ -0,0 +1,53 @@+package com.vayunmathur.files.ui.dialogs++import androidx.compose.foundation.text.KeyboardActions+import androidx.compose.foundation.text.KeyboardOptions+import androidx.compose.runtime.Composable+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember+import androidx.compose.runtime.setValue+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.text.input.ImeAction+import com.vayunmathur.library.ui.AlertDialog+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.TextButton+import com.vayunmathur.library.ui.TextField+import com.vayunmathur.library.ui.R as UiR++/**+ * Single-name entry dialog behind `Route.NewFolderDialog` /+ * `Route.NewFileDialog`, stateless apart from the name field itself:+ * confirming reports a non-blank entered name, dismissing reports nothing.+ */+@Composable+fun NameDialog(+    title: String,+    label: String,+    initial: String,+    confirmLabel: String,+    onConfirm: (String) -> Unit,+    onDismiss: () -> Unit,+) {+    var name by remember { mutableStateOf(initial) }+    AlertDialog(+        onDismissRequest = onDismiss,+        title = { Text(title) },+        text = {+            TextField(+                value = name,+                onValueChange = { name = it },+                label = { Text(label) },+                singleLine = true,+                keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),+                keyboardActions = KeyboardActions(onDone = { if (name.isNotBlank()) onConfirm(name) }),+            )+        },+        confirmButton = {+            TextButton(onClick = { if (name.isNotBlank()) onConfirm(name) }) { Text(confirmLabel) }+        },+        dismissButton = {+            TextButton(onClick = onDismiss) { Text(stringResource(UiR.string.cancel)) }+        },+    )+}
files/src/main/java/com/vayunmathur/files/ui/dialogs/PermanentDeleteDialog.kt
diff --git a/files/src/main/java/com/vayunmathur/files/ui/dialogs/PermanentDeleteDialog.kt b/files/src/main/java/com/vayunmathur/files/ui/dialogs/PermanentDeleteDialog.ktnew file mode 100644index 0000000000..f60608db43--- /dev/null+++ b/files/src/main/java/com/vayunmathur/files/ui/dialogs/PermanentDeleteDialog.kt@@ -0,0 +1,36 @@+package com.vayunmathur.files.ui.dialogs++import androidx.compose.runtime.Composable+import androidx.compose.ui.res.pluralStringResource+import androidx.compose.ui.res.stringResource+import com.vayunmathur.files.R+import com.vayunmathur.library.ui.AlertDialog+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.TextButton+import com.vayunmathur.library.ui.R as UiR++/**+ * Permanent-delete confirmation for `Route.PermanentDeleteDialog`,+ * stateless: the item count travels in the route, confirming reports the+ * choice and dismissing reports nothing. Covers items the system trash+ * cannot take (folders, unindexed files), shared by the directory and+ * trash flows.+ */+@Composable+fun PermanentDeleteDialog(+    count: Int,+    onConfirm: () -> Unit,+    onDismiss: () -> Unit,+) {+    AlertDialog(+        onDismissRequest = onDismiss,+        title = { Text(pluralStringResource(R.plurals.delete_permanently_title, count, count)) },+        text = { Text(stringResource(R.string.delete_permanently_message)) },+        confirmButton = {+            TextButton(onClick = onConfirm) { Text(stringResource(UiR.string.delete)) }+        },+        dismissButton = {+            TextButton(onClick = onDismiss) { Text(stringResource(UiR.string.cancel)) }+        },+    )+}
files/src/main/java/com/vayunmathur/files/ui/dialogs/RenameDialog.kt
diff --git a/files/src/main/java/com/vayunmathur/files/ui/dialogs/RenameDialog.kt b/files/src/main/java/com/vayunmathur/files/ui/dialogs/RenameDialog.ktnew file mode 100644index 0000000000..91c3427aff--- /dev/null+++ b/files/src/main/java/com/vayunmathur/files/ui/dialogs/RenameDialog.kt@@ -0,0 +1,52 @@+package com.vayunmathur.files.ui.dialogs++import androidx.compose.foundation.text.KeyboardActions+import androidx.compose.foundation.text.KeyboardOptions+import androidx.compose.runtime.Composable+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember+import androidx.compose.runtime.setValue+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.text.input.ImeAction+import com.vayunmathur.files.R+import com.vayunmathur.library.ui.AlertDialog+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.TextButton+import com.vayunmathur.library.ui.TextField+import com.vayunmathur.library.ui.R as UiR++/**+ * Rename dialog for `Route.RenameDialog`, stateless apart from the name+ * field itself: the item's current name travels in the route, confirming+ * reports the entered name and dismissing reports nothing.+ */+@Composable+fun RenameDialog(+    itemName: String,+    onConfirm: (String) -> Unit,+    onDismiss: () -> Unit,+) {+    var newName by remember(itemName) { mutableStateOf(itemName) }+    val confirm = { onConfirm(newName) }+    AlertDialog(+        onDismissRequest = onDismiss,+        title = { Text(stringResource(UiR.string.rename)) },+        text = {+            TextField(+                value = newName,+                onValueChange = { newName = it },+                label = { Text(stringResource(R.string.new_name_label)) },+                singleLine = true,+                keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),+                keyboardActions = KeyboardActions(onDone = { confirm() }),+            )+        },+        confirmButton = {+            TextButton(onClick = confirm) { Text(stringResource(UiR.string.rename)) }+        },+        dismissButton = {+            TextButton(onClick = onDismiss) { Text(stringResource(UiR.string.cancel)) }+        },+    )+}
files/src/screenshotTest/kotlin/com/vayunmathur/files/MetadataPreviews.kt
diff --git a/files/src/screenshotTest/kotlin/com/vayunmathur/files/MetadataPreviews.kt b/files/src/screenshotTest/kotlin/com/vayunmathur/files/MetadataPreviews.ktindex e0ce768f61..6e0d96ddf2 100644--- a/files/src/screenshotTest/kotlin/com/vayunmathur/files/MetadataPreviews.kt+++ b/files/src/screenshotTest/kotlin/com/vayunmathur/files/MetadataPreviews.kt@@ -11,6 +11,13 @@ import com.vayunmathur.files.platform.StorageInfo import com.vayunmathur.files.platform.TrashUiState import com.vayunmathur.files.ui.DirectoryScreen import com.vayunmathur.files.ui.FilesDrawer+import com.vayunmathur.files.ui.dialogs.ArchiveDialog+import com.vayunmathur.files.ui.dialogs.EmptyTrashDialog+import com.vayunmathur.files.ui.dialogs.EnableNotificationsDialog+import com.vayunmathur.files.ui.dialogs.NameDialog+import com.vayunmathur.files.ui.dialogs.PermanentDeleteDialog+import com.vayunmathur.files.ui.dialogs.PropertiesDialog+import com.vayunmathur.files.ui.dialogs.RenameDialog import com.vayunmathur.files.ui.HomeScreen import com.vayunmathur.files.ui.TrashScreen import com.vayunmathur.library.ui.DrawerValue@@ -39,9 +46,10 @@ private const val ROOT = "/storage/emulated/0"  * handed — so these render without a filesystem, a device, or the all-files permission the  * real app needs before it shows anything at all.  *- * Coverage: every `Route` destination — `Home`, `Directory`, `Category`, `Trash` and- * `Zip` on phone, plus `Home` (main) on large-tablet. The text editor is a separate- * activity (`TextEditorActivity`, ViewModel + SAF URI), not a `Route` destination.+ * Coverage: every `Route` destination — `Home`, `Directory`, `Category`, `Trash`,+ * `Zip` and every dialog destination on phone, plus `Home` (main) on large-tablet.+ * The text editor is a separate activity (`TextEditorActivity`, ViewModel + SAF URI),+ * not a `Route` destination.  */ class MetadataPreviews { @@ -262,4 +270,115 @@ class MetadataPreviews {             HomeContent()         }     }++    @PreviewTest+    @Preview(name = "9-directory", device = PHONE, group = "phone", showSystemUi = true)+    @Composable+    fun Preview9Directory() {+        val docs = "$ROOT/Documents"+        DynamicTheme(darkTheme = true) {+            DirectoryScreen(+                state = FilesUiState(+                    rootDirectory = File(ROOT),+                    rootDisplayName = "Pixel 9 Pro",+                    currentDirectory = File(docs),+                    directories = listOf(dir("$docs/invoices")),+                    files = listOf(+                        file("$docs/reading-list.md", 12_408),+                        file("$docs/trip-notes.txt", 4_096),+                    ),+                ),+                actions = FilesActions.Noop,+            )+        }+    }++    @PreviewTest+    @Preview(name = "10-archive-dialog", device = PHONE, group = "phone", showSystemUi = true)+    @Composable+    fun Preview10ArchiveDialog() {+        DynamicTheme(darkTheme = true) {+            ArchiveDialog(initialName = "receipts-june.pdf.zip", onConfirm = {}, onDismiss = {})+        }+    }++    @PreviewTest+    @Preview(name = "11-rename-dialog", device = PHONE, group = "phone", showSystemUi = true)+    @Composable+    fun Preview11RenameDialog() {+        DynamicTheme(darkTheme = true) {+            RenameDialog(itemName = "receipts-june.pdf", onConfirm = {}, onDismiss = {})+        }+    }++    @PreviewTest+    @Preview(name = "12-new-folder-dialog", device = PHONE, group = "phone", showSystemUi = true)+    @Composable+    fun Preview12NewFolderDialog() {+        DynamicTheme(darkTheme = true) {+            NameDialog(+                title = "New folder",+                label = "Folder name",+                initial = "",+                confirmLabel = "Create",+                onConfirm = {},+                onDismiss = {},+            )+        }+    }++    @PreviewTest+    @Preview(name = "13-new-file-dialog", device = PHONE, group = "phone", showSystemUi = true)+    @Composable+    fun Preview13NewFileDialog() {+        DynamicTheme(darkTheme = true) {+            NameDialog(+                title = "New file",+                label = "File name",+                initial = "untitled.txt",+                confirmLabel = "Create",+                onConfirm = {},+                onDismiss = {},+            )+        }+    }++    @PreviewTest+    @Preview(name = "14-properties-dialog", device = PHONE, group = "phone", showSystemUi = true)+    @Composable+    fun Preview14PropertiesDialog() {+        DynamicTheme(darkTheme = true) {+            PropertiesDialog(+                item = file("$ROOT/Download/receipts-june.pdf", 184_320),+                onDismiss = {},+            )+        }+    }++    @PreviewTest+    @Preview(name = "15-empty-trash-dialog", device = PHONE, group = "phone", showSystemUi = true)+    @Composable+    fun Preview15EmptyTrashDialog() {+        DynamicTheme(darkTheme = true) {+            EmptyTrashDialog(onConfirm = {}, onDismiss = {})+        }+    }++    @PreviewTest+    @Preview(name = "16-permanent-delete-dialog", device = PHONE, group = "phone", showSystemUi = true)+    @Composable+    fun Preview16PermanentDeleteDialog() {+        DynamicTheme(darkTheme = true) {+            PermanentDeleteDialog(count = 2, onConfirm = {}, onDismiss = {})+        }+    }++    @PreviewTest+    @Preview(name = "17-enable-notifications-dialog", device = PHONE, group = "phone", showSystemUi = true)+    @Composable+    fun Preview17EnableNotificationsDialog() {+        DynamicTheme(darkTheme = true) {+            EnableNotificationsDialog(onConfirm = {}, onDismiss = {})+        }+    } }
files/src/test/java/com/vayunmathur/files/ui/BindersTest.kt
diff --git a/files/src/test/java/com/vayunmathur/files/ui/BindersTest.kt b/files/src/test/java/com/vayunmathur/files/ui/BindersTest.ktindex b122ef0f74..a8c469b02f 100644--- a/files/src/test/java/com/vayunmathur/files/ui/BindersTest.kt+++ b/files/src/test/java/com/vayunmathur/files/ui/BindersTest.kt@@ -77,27 +77,29 @@ class BindersTest {     }      @Test-    fun `shell shows notification prompt and permanent delete dialog`() {+    fun `dialog destinations confirm permanent delete and notification prompt`() {         val actions = RecordingFilesActions()-        // stage the shell-owned permanent-delete confirmation above the content-        vm.pendingPermanentDeleteState.value = listOf(-            com.vayunmathur.files.platform.FileBrowserItem(-                "doomed.txt", false, 1, File(dir, "doomed.txt"), null, "doomed",-            ),-        )+        val stage = androidx.compose.runtime.mutableIntStateOf(0)         rule.setContent {-            FilesShell(vm, actions) {-                androidx.compose.material3.Text("shell-body")+            when (stage.intValue) {+                0 -> com.vayunmathur.files.ui.dialogs.PermanentDeleteDialog(+                    count = 1,+                    onConfirm = { actions.confirmPermanentDelete() },+                    onDismiss = { actions.dismissPermanentDelete() },+                )+                else -> com.vayunmathur.files.ui.dialogs.EnableNotificationsDialog(+                    onConfirm = {},+                    onDismiss = { vm.setNotificationsPrompted() },+                )             }         }         rule.onNodeWithText("Delete 1 item permanently?").assertIsDisplayed()         rule.onNodeWithText("Delete").performClick()         assertTrue(actions.calls.contains("confirmPD"))-        // notification prompt (fresh VM in this sandbox has not prompted yet)-        if (rule.onAllNodesWithText("Enable Notifications?").fetchSemanticsNodes().isNotEmpty()) {-            rule.onNodeWithText("Skip").performClick()-            assertTrue(vm.hasPromptedNotifications.value)-        }+        rule.runOnIdle { stage.intValue = 1 }+        rule.onNodeWithText("Enable Notifications?").assertIsDisplayed()+        rule.onNodeWithText("Skip").performClick()+        assertTrue(vm.hasPromptedNotifications.value)     }      @Test
files/src/test/java/com/vayunmathur/files/ui/DirectoryDialogsFlowTest.kt
diff --git a/files/src/test/java/com/vayunmathur/files/ui/DirectoryDialogsFlowTest.kt b/files/src/test/java/com/vayunmathur/files/ui/DirectoryDialogsFlowTest.ktindex 7b116e5a62..e8963d0c80 100644--- a/files/src/test/java/com/vayunmathur/files/ui/DirectoryDialogsFlowTest.kt+++ b/files/src/test/java/com/vayunmathur/files/ui/DirectoryDialogsFlowTest.kt@@ -13,6 +13,9 @@ import com.vayunmathur.files.platform.FileBrowserItem import com.vayunmathur.files.platform.FilesUiState import com.vayunmathur.files.platform.SortBy import com.vayunmathur.files.platform.ViewMode+import com.vayunmathur.files.ui.dialogs.ArchiveDialog+import com.vayunmathur.files.ui.dialogs.NameDialog+import com.vayunmathur.files.ui.dialogs.RenameDialog import org.junit.Rule import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner@@ -68,7 +71,32 @@ class DirectoryDialogsFlowTest {     @Test     fun `overflow menu new folder and new file dialogs create entries`() {         val actions = RecordingFilesActions()-        rule.setContent { DirectoryScreen(state = state(), actions = actions) }+        val showNewFolder = androidx.compose.runtime.mutableStateOf(false)+        val showNewFile = androidx.compose.runtime.mutableStateOf(false)+        rule.setContent {+            DirectoryScreen(+                state = state(),+                actions = actions,+                onShowNewFolderRequest = { showNewFolder.value = true },+                onShowNewFileRequest = { showNewFile.value = true },+            )+            if (showNewFolder.value) {+                NameDialog(+                    title = "New folder", label = "Folder name", initial = "",+                    confirmLabel = "Create",+                    onConfirm = { actions.createFolder(it); showNewFolder.value = false },+                    onDismiss = { showNewFolder.value = false },+                )+            }+            if (showNewFile.value) {+                NameDialog(+                    title = "New file", label = "File name", initial = "untitled.txt",+                    confirmLabel = "Create",+                    onConfirm = { actions.createFile(it); showNewFile.value = false },+                    onDismiss = { showNewFile.value = false },+                )+            }+        }         // top bar: drawer menu (left) ... search, overflow (right side)         clickTopBar(topBarIndices().size - 1) // overflow         rule.onNodeWithText("New folder").performClick()@@ -86,8 +114,37 @@ class DirectoryDialogsFlowTest {     fun `selection flows rename archive and properties dialogs`() {         val actions = RecordingFilesActions()         val single = item("notes.txt")+        val renameTarget = androidx.compose.runtime.mutableStateOf<FileBrowserItem?>(null)+        val propsTarget = androidx.compose.runtime.mutableStateOf<FileBrowserItem?>(null)+        val archiveName = androidx.compose.runtime.mutableStateOf<String?>(null)         rule.setContent {-            DirectoryScreen(state = state(selected = setOf(single)), actions = actions)+            DirectoryScreen(+                state = state(selected = setOf(single)),+                actions = actions,+                onRenameRequest = { renameTarget.value = it },+                onShowPropertiesRequest = { propsTarget.value = it },+                onArchiveRequest = { archiveName.value = it },+            )+            renameTarget.value?.let { target ->+                RenameDialog(+                    itemName = target.name,+                    onConfirm = { actions.rename(target, it); renameTarget.value = null },+                    onDismiss = { renameTarget.value = null },+                )+            }+            archiveName.value?.let { initial ->+                ArchiveDialog(+                    initialName = initial,+                    onConfirm = { actions.archive(it); archiveName.value = null },+                    onDismiss = { archiveName.value = null },+                )+            }+            propsTarget.value?.let { target ->+                com.vayunmathur.files.ui.dialogs.PropertiesDialog(+                    item = target,+                    onDismiss = { propsTarget.value = null },+                )+            }         }         // selection top bar: clear, delete, overflow are the right-side buttons         clickTopBar(topBarIndices().size - 1) // overflow
files/src/test/java/com/vayunmathur/files/ui/DirectoryScreenTest.kt
diff --git a/files/src/test/java/com/vayunmathur/files/ui/DirectoryScreenTest.kt b/files/src/test/java/com/vayunmathur/files/ui/DirectoryScreenTest.ktindex 0a7280b585..1e00ece363 100644--- a/files/src/test/java/com/vayunmathur/files/ui/DirectoryScreenTest.kt+++ b/files/src/test/java/com/vayunmathur/files/ui/DirectoryScreenTest.kt@@ -1,5 +1,8 @@ package com.vayunmathur.files.ui +import com.vayunmathur.files.ui.dialogs.NameDialog+import com.vayunmathur.files.ui.dialogs.PermanentDeleteDialog+ import androidx.compose.foundation.layout.Column import androidx.compose.ui.test.assertIsDisplayed import androidx.compose.ui.test.hasClickAction
files/src/test/java/com/vayunmathur/files/ui/HomeTrashScreenTest.kt
diff --git a/files/src/test/java/com/vayunmathur/files/ui/HomeTrashScreenTest.kt b/files/src/test/java/com/vayunmathur/files/ui/HomeTrashScreenTest.ktindex 659a93ecfb..a63a383336 100644--- a/files/src/test/java/com/vayunmathur/files/ui/HomeTrashScreenTest.kt+++ b/files/src/test/java/com/vayunmathur/files/ui/HomeTrashScreenTest.kt@@ -114,7 +114,20 @@ class HomeTrashScreenTest {     fun `trash empty confirm dialog empties trash`() {         val actions = RecordingFilesActions()         val ghost = item("ghost.txt", key = "trash:1")-        rule.setContent { TrashScreen(state = TrashUiState(items = listOf(ghost)), actions = actions) }+        val showEmpty = androidx.compose.runtime.mutableStateOf(false)+        rule.setContent {+            TrashScreen(+                state = TrashUiState(items = listOf(ghost)),+                actions = actions,+                onEmptyTrashRequest = { showEmpty.value = true },+            )+            if (showEmpty.value) {+                com.vayunmathur.files.ui.dialogs.EmptyTrashDialog(+                    onConfirm = { actions.emptyTrash(); showEmpty.value = false },+                    onDismiss = { showEmpty.value = false },+                )+            }+        }         // overflow (more-vert) is the right-most top-bar icon button         val nodes = rule.onAllNodes(hasClickAction()).fetchSemanticsNodes()         val topBar = nodes.withIndex()