mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +00:00
fix(ui): leave the file manager after a drive hop instead of replaying hops (#2567)
Back replays the history stack, so a round trip between drives leaves one entry per hop: internal storage, Linux, internal storage, then Back lands on Linux again and leaving takes one press per hop. Two roots in a row means the user hopped rather than descended into a folder, so Back leaves instead. Returning to a folder from a drive root still works as before. Co-authored-by: Dantalian <Dantalian-dev@users.noreply.github.com>
This commit is contained in:
1 parent
9ce6d45be8
commit
52e8028609
2 files changed
+18
-2
No files matched your search
@@ -112,6 +112,10 @@ private const val HISTORY_LIMIT = 50
|
||||
internal fun canNavigateUp(currentDir: File, currentRoot: File): Boolean =
|
||||
currentDir != currentRoot && currentDir.parentFile?.exists() == true
|
||||
|
||||
// Back leaves after a drive hop instead of replaying a stack of hops one press at a time.
|
||||
internal fun backExitsAtRootHop(currentDir: File, currentRoot: File, previous: Pair<File, File>): Boolean =
|
||||
currentDir == currentRoot && previous.first == previous.second
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun FileManagerScreen(
|
||||
@@ -269,8 +273,10 @@ fun FileManagerScreen(
|
||||
if (showFavorites) showFavorites = false
|
||||
else {
|
||||
while (history.isNotEmpty() && !history.last().first.isDirectory) history.removeAt(history.lastIndex)
|
||||
val previous = history.removeLastOrNull()
|
||||
if (previous != null) {
|
||||
val previous = history.lastOrNull()
|
||||
if (previous != null && backExitsAtRootHop(currentDir, currentRoot, previous)) onExit?.invoke()
|
||||
else if (previous != null) {
|
||||
history.removeLastOrNull()
|
||||
currentRoot = previous.second
|
||||
loadDirectory(previous.first, record = false)
|
||||
} else if (canNavigateUp(currentDir, currentRoot)) currentDir.parentFile?.let { loadDirectory(it, record = false) }
|
||||
|
||||
@@ -17,4 +17,14 @@ class FileManagerNavigationTest {
|
||||
assertTrue(canNavigateUp(child, drive))
|
||||
assertFalse(canNavigateUp(drive, drive))
|
||||
}
|
||||
|
||||
@Test fun backLeavesInsteadOfHoppingBetweenTwoRoots() {
|
||||
val drive = tmp.newFolder("drive")
|
||||
val other = tmp.newFolder("other")
|
||||
val child = File(drive, "folder").apply { mkdir() }
|
||||
|
||||
assertTrue(backExitsAtRootHop(drive, drive, other to other))
|
||||
assertFalse(backExitsAtRootHop(drive, drive, child to other))
|
||||
assertFalse(backExitsAtRootHop(child, drive, other to other))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user