From 5fb301b314a8176e8118f0633dc85643b9d8f969 Mon Sep 17 00:00:00 2001 From: DrDisagree Date: Wed, 4 Sep 2024 21:42:25 +0600 Subject: [PATCH] Remove OnBackPressedCallback Signed-off-by: DrDisagree --- .../iconify/ui/activities/MainActivity.kt | 23 +++++-------------- .../iconify/ui/fragments/home/Home.kt | 5 +--- app/src/main/res/menu/home_menu.xml | 9 -------- 3 files changed, 7 insertions(+), 30 deletions(-) delete mode 100644 app/src/main/res/menu/home_menu.xml diff --git a/app/src/main/java/com/drdisagree/iconify/ui/activities/MainActivity.kt b/app/src/main/java/com/drdisagree/iconify/ui/activities/MainActivity.kt index 167e1d0be..c9d7fc34e 100644 --- a/app/src/main/java/com/drdisagree/iconify/ui/activities/MainActivity.kt +++ b/app/src/main/java/com/drdisagree/iconify/ui/activities/MainActivity.kt @@ -7,7 +7,6 @@ import android.os.Handler import android.os.Looper import android.view.MenuItem import android.view.View -import androidx.activity.OnBackPressedCallback import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentManager.POP_BACK_STACK_INCLUSIVE @@ -172,16 +171,6 @@ class MainActivity : BaseActivity(), binding.bottomNavigationView.inflateMenu(R.menu.bottom_nav_menu_xposed_only) } - onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) { - override fun handleOnBackPressed() { - if (supportFragmentManager.backStackEntryCount > 1) { - popCurrentFragment(supportFragmentManager) - } else { - finishAffinity() - } - } - }) - supportFragmentManager.addOnBackStackChangedListener { val fragment = getTopFragment() val xposedOnlyMode = Preferences.isXposedOnlyMode @@ -435,11 +424,14 @@ class MainActivity : BaseActivity(), replace(R.id.fragmentContainerView, fragment, fragmentTag) when (fragmentTag) { - Home::class.java.simpleName, + Home::class.java.simpleName -> { + fragmentManager.popBackStack(null, POP_BACK_STACK_INCLUSIVE) + } + Tweaks::class.java.simpleName, Xposed::class.java.simpleName, Settings::class.java.simpleName -> { - fragmentManager.popBackStack(Home::class.java.simpleName, 0) + fragmentManager.popBackStack(null, POP_BACK_STACK_INCLUSIVE) addToBackStack(fragmentTag) } @@ -474,10 +466,7 @@ class MainActivity : BaseActivity(), fun popCurrentFragment(fragmentManager: FragmentManager) { if (fragmentManager.isStateSaved) return - try { - fragmentManager.popBackStack() - } catch (ignored: IllegalStateException) { - } + fragmentManager.popBackStack() } fun showOrHidePendingActionButton( diff --git a/app/src/main/java/com/drdisagree/iconify/ui/fragments/home/Home.kt b/app/src/main/java/com/drdisagree/iconify/ui/fragments/home/Home.kt index 92f8e3d02..95ef31716 100644 --- a/app/src/main/java/com/drdisagree/iconify/ui/fragments/home/Home.kt +++ b/app/src/main/java/com/drdisagree/iconify/ui/fragments/home/Home.kt @@ -34,10 +34,7 @@ class Home : ControlledPreferenceFragmentCompat(), AppBarLayout.OnOffsetChangedL get() = R.xml.home override val hasMenu: Boolean - get() = true - - override val menuResource: Int - get() = R.menu.home_menu + get() = false override val themeResource: Int get() = R.style.PrefsThemeCollapsingToolbar diff --git a/app/src/main/res/menu/home_menu.xml b/app/src/main/res/menu/home_menu.xml deleted file mode 100644 index e2f0f8f73..000000000 --- a/app/src/main/res/menu/home_menu.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - \ No newline at end of file