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 778c07f3e..5fd3f08be 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,7 +67,8 @@ 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 mCurrentPathPrefix = "" // used at "Group direct subfolders" for navigation + private var mOpenedSubfolders = arrayListOf("") // used at "Group direct subfolders" for navigating Up with the back button private var mLastMediaHandler = Handler() private var mTempShowHiddenHandler = Handler() private var mZoomListener: MyRecyclerView.MyZoomListener? = null @@ -243,6 +244,20 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { } } + override fun onBackPressed() { + if (config.groupDirectSubfolders) { + if (mCurrentPathPrefix.isEmpty()) { + super.onBackPressed() + } else { + mOpenedSubfolders.removeAt(mOpenedSubfolders.size - 1) + mCurrentPathPrefix = mOpenedSubfolders.last() + setupAdapter(mDirs) + } + } else { + super.onBackPressed() + } + } + override fun onCreateOptionsMenu(menu: Menu): Boolean { if (mIsThirdPartyIntent) { menuInflater.inflate(R.menu.menu_main_intent, menu) @@ -1064,6 +1079,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { } } else { mCurrentPathPrefix = path + mOpenedSubfolders.add(path) setupAdapter(mDirs, "") } }.apply {