Skip to content

Commit 2defa43

Browse files
committed
fix #206
1 parent c23fec3 commit 2defa43

File tree

5 files changed

+68
-17
lines changed

5 files changed

+68
-17
lines changed

app/src/main/java/com/raival/compose/file/explorer/screen/main/MainActivityManager.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,17 @@ class MainActivityManager {
193193
}
194194
}
195195

196-
fun replaceCurrentTabWith(tab: Tab) {
196+
fun replaceCurrentTabWith(tab: Tab, keepCurrentTabAsParent: Boolean = false) {
197197
val currentActiveTab = getActiveTab()
198198

199199
// Stop and remove the active tab BEFORE state update
200200
currentActiveTab?.apply {
201201
onTabStopped()
202-
onTabRemoved()
202+
if (!keepCurrentTabAsParent) onTabRemoved()
203+
}
204+
205+
if (keepCurrentTabAsParent) {
206+
tab.parentTab = currentActiveTab
203207
}
204208

205209
// Update the state
@@ -278,6 +282,12 @@ class MainActivityManager {
278282
return false
279283
}
280284

285+
// Replace with parent tab if exists
286+
if (getActiveTab()!!.parentTab != null) {
287+
replaceCurrentTabWith(getActiveTab()!!.parentTab!!, false)
288+
return false
289+
}
290+
281291
// Replace the active tab with the home tab (if turned on in settings)
282292
if (getActiveTab() !is HomeTab && !globalClass.preferencesManager.skipHomeWhenTabClosed) {
283293
replaceCurrentTabWith(HomeTab())

app/src/main/java/com/raival/compose/file/explorer/screen/main/tab/Tab.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import kotlinx.coroutines.launch
77

88
abstract class Tab {
99
var isCreated = false
10+
var parentTab: Tab? = null
1011

1112
abstract val id: Int
1213
abstract val header: String

app/src/main/java/com/raival/compose/file/explorer/screen/main/tab/files/FilesTab.kt

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class FilesTab(
8282
var highlightedPathSegment by mutableStateOf(activeFolder)
8383
val currentPathSegmentsListState = LazyListState()
8484

85+
var showCategories by mutableStateOf(false)
8586
var categories = mutableStateListOf<FileListCategory>()
8687
var selectedCategory by mutableStateOf<FileListCategory?>(null)
8788

@@ -319,7 +320,9 @@ class FilesTab(
319320
}
320321

321322
// Check if the back gesture can be handled
322-
handleBackGesture = runBlocking { activeFolder.hasParent() || selectedFiles.isNotEmpty() }
323+
handleBackGesture = runBlocking {
324+
selectedFiles.isNotEmpty() || (activeFolder.hasParent() && !shouldNavigateToParentTab())
325+
}
323326

324327
// Update the path list
325328
updatePathList()
@@ -355,13 +358,24 @@ class FilesTab(
355358
if (activeFolder is VirtualFileHolder) {
356359
categories.clear()
357360
categories.addAll((activeFolder as VirtualFileHolder).getCategories())
361+
showCategories = categories.isNotEmpty()
362+
} else {
363+
showCategories = false
358364
}
359365

360366
// Call any posted events
361367
postEvent()
362368
}
363369
}
364370

371+
private fun shouldNavigateToParentTab(): Boolean {
372+
return parentTab isNot null
373+
&& activeFolder is ZipFileHolder
374+
&& with(activeFolder as ZipFileHolder) {
375+
runBlocking { getParent()?.uniquePath == zipTree.source.getParent()?.uniquePath }
376+
}
377+
}
378+
365379
suspend fun validateActiveFolder() {
366380
if (!activeFolder.isValid()) {
367381
// Try to find a valid parent folder
@@ -488,7 +502,8 @@ class FilesTab(
488502
val temp = arrayListOf<ContentHolder>().apply { addAll(activeFolderContent) }
489503

490504
// Recheck the back gesture
491-
handleBackGesture = activeFolder.hasParent() || selectedFiles.isNotEmpty()
505+
handleBackGesture = selectedFiles.isNotEmpty()
506+
|| (activeFolder.hasParent() && !shouldNavigateToParentTab())
492507

493508
// Update the bottom bar options
494509
_bottomOptionsBarState.update {
@@ -515,7 +530,8 @@ class FilesTab(
515530
fun onSelectionChange() {
516531
scope.launch {
517532
// Recheck the back gesture
518-
handleBackGesture = activeFolder.hasParent() || selectedFiles.isNotEmpty()
533+
handleBackGesture =
534+
selectedFiles.isNotEmpty() || (activeFolder.hasParent() && !shouldNavigateToParentTab())
519535

520536
// Update the bottom bar options
521537
_bottomOptionsBarState.update {

app/src/main/java/com/raival/compose/file/explorer/screen/main/tab/files/ui/BreadcrumbBar.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,8 @@ import kotlin.math.max
5050
@Composable
5151
fun BreadcrumbBar(tab: FilesTab) {
5252
val highlightedPathListItemColor = MaterialTheme.colorScheme.primary
53-
val showCategoriesRow = tab.activeFolder is VirtualFileHolder && tab.categories.isNotEmpty()
5453

55-
if (showCategoriesRow) {
54+
if (tab.showCategories) {
5655
CategoriesRow(tab)
5756
} else if (tab.activeFolder !is VirtualFileHolder) {
5857
Row(

app/src/main/java/com/raival/compose/file/explorer/screen/main/tab/files/zip/ZipManager.kt

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import com.raival.compose.file.explorer.common.isNot
55
import com.raival.compose.file.explorer.common.removeIf
66
import com.raival.compose.file.explorer.screen.main.tab.files.FilesTab
77
import com.raival.compose.file.explorer.screen.main.tab.files.holder.LocalFileHolder
8+
import com.raival.compose.file.explorer.screen.main.tab.files.holder.VirtualFileHolder
89
import kotlinx.coroutines.runBlocking
910

1011
class ZipManager {
@@ -47,11 +48,23 @@ class ZipManager {
4748
archiveList[existingTreeKey]?.let { existingTree ->
4849
if (existingTree.timeStamp == archive.lastModified) {
4950
globalClass.mainActivityManager.let { mainManager ->
50-
(mainManager.getActiveTab() as? FilesTab)?.openFolder(
51-
existingTree.createRootContentHolder()
52-
) ?: mainManager.replaceCurrentTabWith(
53-
FilesTab(existingTree.createRootContentHolder())
54-
)
51+
val tab = mainManager.getActiveTab()
52+
if (tab is FilesTab) {
53+
if (tab.activeFolder is VirtualFileHolder) {
54+
mainManager.replaceCurrentTabWith(
55+
tab = FilesTab(
56+
existingTree.createRootContentHolder()
57+
),
58+
keepCurrentTabAsParent = true
59+
)
60+
} else {
61+
tab.openFolder(existingTree.createRootContentHolder())
62+
}
63+
} else {
64+
mainManager.replaceCurrentTabWith(
65+
FilesTab(existingTree.createRootContentHolder())
66+
)
67+
}
5568
return
5669
}
5770
} else {
@@ -62,11 +75,23 @@ class ZipManager {
6275

6376
archiveList[archive] = ZipTree(archive).apply {
6477
globalClass.mainActivityManager.let { mainManager ->
65-
(mainManager.getActiveTab() as? FilesTab)?.openFolder(
66-
createRootContentHolder()
67-
) ?: mainManager.replaceCurrentTabWith(
68-
FilesTab(createRootContentHolder())
69-
)
78+
val tab = mainManager.getActiveTab()
79+
if (tab is FilesTab) {
80+
if (tab.activeFolder is VirtualFileHolder) {
81+
mainManager.replaceCurrentTabWith(
82+
tab = FilesTab(
83+
createRootContentHolder()
84+
),
85+
keepCurrentTabAsParent = true
86+
)
87+
} else {
88+
tab.openFolder(createRootContentHolder())
89+
}
90+
} else {
91+
mainManager.replaceCurrentTabWith(
92+
FilesTab(createRootContentHolder())
93+
)
94+
}
7095
}
7196
}
7297
}

0 commit comments

Comments
 (0)