From ce4dee2573a43f368996f1f000d219460769dcbf Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 15 Dec 2018 22:32:11 +0100 Subject: [PATCH] implement navigation between grouped direct subfolders --- .../gallery/pro/activities/MainActivity.kt | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt index 12dd663d0..11207297f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt @@ -67,6 +67,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { private var mIsSearchOpen = false private var mLatestMediaId = 0L private var mLatestMediaDateId = 0L + private var mCurrentPathPrefix = "" // used at "Group direct subfolders" for navigation private var mLastMediaHandler = Handler() private var mTempShowHiddenHandler = Handler() private var mZoomListener: MyRecyclerView.MyZoomListener? = null @@ -920,8 +921,12 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { val currentPaths = LinkedHashSet() folders.forEach { val path = it - if (path != internalPath && path != sdPath) { - if (folders.any { it != path && (File(path).parent == it || File(it).parent == File(path).parent) }) { + if (!path.equals(internalPath, true) && !path.equals(sdPath, true)) { + if (mCurrentPathPrefix.isNotEmpty()) { + if (File(path).parent.equals(mCurrentPathPrefix, true) || path == mCurrentPathPrefix) { + currentPaths.add(path) + } + } else if (folders.any { !it.equals(path, true) && (File(path).parent.equals(it, true) || File(it).parent.equals(File(path).parent, true)) }) { val parent = File(path).parent currentPaths.add(parent) } else { @@ -934,12 +939,16 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { currentPaths.forEach { val path = it currentPaths.forEach { - if (it != path && File(it).parent == path) { + if (!it.equals(path) && File(it).parent.equals(path)) { areDirectSubfoldersAvailable = true } } } + if (folders.size == currentPaths.size) { + return currentPaths + } + folders.clear() folders.addAll(currentPaths) return if (areDirectSubfoldersAvailable) { @@ -1035,11 +1044,14 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { val fastscroller = if (config.scrollHorizontally) directories_horizontal_fastscroller else directories_vertical_fastscroller DirectoryAdapter(this, dirsToShow, this, directories_grid, isPickIntent(intent) || isGetAnyContentIntent(intent), fastscroller) { val clickedDir = it as Directory + val path = clickedDir.path if (clickedDir.subfoldersCount == 1 || !config.groupDirectSubfolders) { - val path = clickedDir.path if (path != config.tempFolderPath) { itemClicked(path) } + } else { + mCurrentPathPrefix = path + setupAdapter(mDirs, "") } }.apply { setupZoomListener(mZoomListener)