Skip to content

Commit

Permalink
Remove OnBackPressedCallback
Browse files Browse the repository at this point in the history
Signed-off-by: DrDisagree <[email protected]>
  • Loading branch information
Mahmud0808 committed Sep 4, 2024
1 parent 7906c22 commit 5fb301b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 0 additions & 9 deletions app/src/main/res/menu/home_menu.xml

This file was deleted.

0 comments on commit 5fb301b

Please sign in to comment.