Add File Manager Return and Exit navigation

Description:
- Add an Exit button at the right end of the File Manager toolbar. It finishes the File Manager activity from any directory.
- Remember the directory supplied when Game files or Proton prefix opens the File Manager. Show a Return to start button in the toolbar for those launches, and use it to reopen that directory after the user switches storage locations or browses elsewhere.
- When returning, restore the starting storage root and close search or favorites views. Show a message if the starting directory is no longer available.
- Add accessible labels for both buttons while retaining the existing toolbar actions and File Manager styling.

Why it was needed:
- Exiting previously required repeatedly navigating back through directories to the original location.
- Switching from the game's initial directory to Internal storage offered no direct route back, leaving users to find the path manually through Linux system storage.
This commit is contained in:
K11MCH1 committed 2026-10-22 16:00:56 +09:00
1 parent 8ccd771059
commit 3f2aea4d08
3 files changed
+39 -5

No files matched your search

@@ -29,7 +29,7 @@ class FileManagerActivity : ComponentActivity() {
setContent {
DroidDeckTheme(appScale = com.droiddeck.launcher.core.AppUiPrefs.scale(this)) {
Surface(modifier = Modifier.fillMaxSize().systemBarsPadding(), color = MaterialTheme.colorScheme.background) {
FileManagerScreen(initialDir = initialDir)
FileManagerScreen(initialDir = initialDir, onExit = { finish() })
}
}
}
@@ -28,6 +28,8 @@ import androidx.compose.foundation.lazy.grid.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ExitToApp
import androidx.compose.material.icons.automirrored.filled.KeyboardReturn
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material.icons.filled.ContentPaste
import androidx.compose.material.icons.filled.CreateNewFolder
@@ -104,6 +106,7 @@ fun FileManagerScreen(
initialDir: File? = null,
pickerTitle: String? = null,
onPick: ((File) -> Unit)? = null,
onExit: (() -> Unit)? = null,
) {
val context = LocalContext.current
val scope = rememberCoroutineScope()
@@ -117,12 +120,14 @@ fun FileManagerScreen(
val pickPrefs = remember { context.getSharedPreferences("file_manager", android.content.Context.MODE_PRIVATE) }
val browsePrefs = pickPrefs
val rootDir = remember {
val rootDir = remember(initialDir) {
initialDir?.takeIf { it.isDirectory } ?: File("/storage/emulated/0")
}
val launchDir = remember(initialDir, pickMode) {
initialDir?.takeIf { it.isDirectory && !pickMode }
}
var currentDir by remember { mutableStateOf(rootDir) }
var currentRoot by remember {
val initialRoot = remember(rootDir) {
val abs = rootDir.absolutePath
val internal = "/storage/emulated/0"
val vol = when {
@@ -138,8 +143,9 @@ fun FileManagerScreen(
?: rootDir
}
}
mutableStateOf(vol)
vol
}
var currentRoot by remember { mutableStateOf(initialRoot) }
var entries by remember { mutableStateOf(listOf<File>()) }
var selectedEntry by remember { mutableStateOf<File?>(null) }
var showMenuFor by remember { mutableStateOf<File?>(null) }
@@ -208,6 +214,19 @@ fun FileManagerScreen(
loadDirectory(dir)
}
fun returnToStart() {
val dir = launchDir ?: return
if (!dir.isDirectory) {
Toast.makeText(context, R.string.fm_start_unavailable, Toast.LENGTH_SHORT).show()
return
}
showFavorites = false
showSearch = false
searchQuery = ""
currentRoot = initialRoot
loadDirectory(dir)
}
LaunchedEffect(Unit) { loadDirectory(rootDir) }
BackHandler(enabled = showFavorites || currentDir != currentRoot) {
@@ -669,6 +688,13 @@ fun FileManagerScreen(
)
}
if (launchDir != null) {
IconButton(onClick = { returnToStart() }) {
Icon(Icons.AutoMirrored.Filled.KeyboardReturn, stringResource(R.string.fm_return_to_start), tint = MaterialTheme.colorScheme.primary)
}
if (LocalConfiguration.current.screenWidthDp >= 700) Spacer(Modifier.width(56.dp))
}
if (!showFavorites) {
if (!pickMode) {
OutlinedButton(
@@ -744,6 +770,11 @@ fun FileManagerScreen(
Icon(Icons.Filled.StarBorder, stringResource(R.string.fm_show_favorites), tint = MaterialTheme.colorScheme.onSurfaceVariant)
}
}
if (!pickMode && onExit != null) {
IconButton(onClick = onExit) {
Icon(Icons.AutoMirrored.Filled.ExitToApp, stringResource(R.string.fm_exit), tint = MaterialTheme.colorScheme.onSurfaceVariant)
}
}
}
if (showSearch && !showFavorites) {