From 63055818eced2eb5bb232462ef8ab8146460a553 Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Sun, 5 May 2019 11:50:27 +0200 Subject: [PATCH] Fixed items in navView not being checked --- .../java/com/topjohnwu/magisk/ui/MainActivity.kt | 16 +++++++++++++++- .../topjohnwu/magisk/ui/base/MagiskActivity.kt | 10 +++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt b/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt index b21e89a5e..57c86b028 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt @@ -71,6 +71,20 @@ open class MainActivity : MagiskActivity() { supportActionBar?.setTitle(titleId) } + override fun onTabTransaction(fragment: Fragment?, index: Int) { + val fragmentId = when (fragment) { + is HomeFragment -> R.id.magiskFragment + is SuperuserFragment -> R.id.superuserFragment + is MagiskHideFragment -> R.id.magiskHideFragment + is ModulesFragment -> R.id.modulesFragment + is ReposFragment -> R.id.reposFragment + is LogFragment -> R.id.logFragment + is SettingsFragment -> R.id.settings + else -> return + } + binding.navView.setCheckedItem(fragmentId) + } + override fun onBackPressed() { if (binding.drawerLayout.isDrawerOpen(binding.navView)) { binding.drawerLayout.closeDrawer(binding.navView) @@ -88,7 +102,7 @@ open class MainActivity : MagiskActivity() { private fun openNav() = binding.drawerLayout.openDrawer(GravityCompat.START) - fun checkHideSection() { + private fun checkHideSection() { val menu = binding.navView.menu menu.findItem(R.id.magiskHideFragment).isVisible = Shell.rootAccess() && Config.get(Config.Key.MAGISKHIDE) as Boolean diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskActivity.kt b/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskActivity.kt index 22290629a..20384d02f 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskActivity.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskActivity.kt @@ -31,7 +31,7 @@ import kotlin.reflect.KClass abstract class MagiskActivity : MagiskLeanbackActivity(), FragNavController.RootFragmentListener, - Navigator { + Navigator, FragNavController.TransactionListener { override val numberOfRootFragments: Int get() = baseFragments.size override val baseFragments: List> = listOf() @@ -62,6 +62,7 @@ abstract class MagiskActivity Unit) {