From cf9326d3236df436b968bc5edf9c7a61e9b513ed Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 4 Jan 2023 23:49:48 +0100 Subject: [PATCH] moving onBackPressed up --- .../pro/activities/MainActivity.kt | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt index 9c248879..610f7e75 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt @@ -142,6 +142,30 @@ class MainActivity : SimpleActivity() { config.temporarilyShowHidden = false } + override fun onBackPressed() { + if (getCurrentFragment() !is ItemsFragment) { + super.onBackPressed() + return + } + + if (main_menu.isSearchOpen) { + main_menu.closeSearch() + } else if (getCurrentFragment()!!.breadcrumbs.getItemCount() <= 1) { + if (!wasBackJustPressed && config.pressBackTwice) { + wasBackJustPressed = true + toast(R.string.press_back_again) + Handler().postDelayed({ + wasBackJustPressed = false + }, BACK_PRESS_TIMEOUT.toLong()) + } else { + finish() + } + } else { + getCurrentFragment()!!.breadcrumbs.removeBreadcrumb() + openPath(getCurrentFragment()!!.breadcrumbs.getLastItem().path) + } + } + fun refreshMenuItems() { val currentFragment = getCurrentFragment() ?: return val isCreateDocumentIntent = intent.action == Intent.ACTION_CREATE_DOCUMENT @@ -624,30 +648,6 @@ class MainActivity : SimpleActivity() { startAboutActivity(R.string.app_name, licenses, BuildConfig.VERSION_NAME, faqItems, true) } - override fun onBackPressed() { - if (getCurrentFragment() !is ItemsFragment) { - super.onBackPressed() - return - } - - if (main_menu.isSearchOpen) { - main_menu.closeSearch() - } else if (getCurrentFragment()!!.breadcrumbs.getItemCount() <= 1) { - if (!wasBackJustPressed && config.pressBackTwice) { - wasBackJustPressed = true - toast(R.string.press_back_again) - Handler().postDelayed({ - wasBackJustPressed = false - }, BACK_PRESS_TIMEOUT.toLong()) - } else { - finish() - } - } else { - getCurrentFragment()!!.breadcrumbs.removeBreadcrumb() - openPath(getCurrentFragment()!!.breadcrumbs.getLastItem().path) - } - } - private fun checkIfRootAvailable() { ensureBackgroundThread { config.isRootAvailable = RootTools.isRootAvailable()