From d9cf33d1ba5f38047280a12720dbbba006ec071f Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Sat, 11 Apr 2020 18:34:10 +0200 Subject: [PATCH] Fixed shortcuts This has been broken due to recent transition to navigation components --- .../com/topjohnwu/magisk/ui/MainActivity.kt | 19 +++++++++++++++++-- app/src/main/res/navigation/main.xml | 10 ++++++++++ 2 files changed, 27 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 e691903d3..5107ee20a 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt @@ -10,6 +10,7 @@ import androidx.core.graphics.Insets import androidx.core.view.forEach import androidx.core.view.setPadding import androidx.core.view.updateLayoutParams +import androidx.navigation.NavDirections import com.google.android.material.card.MaterialCardView import com.topjohnwu.magisk.MainDirections import com.topjohnwu.magisk.R @@ -100,10 +101,14 @@ open class MainActivity : BaseUIActivity( binding.mainNavigation.viewTreeObserver.addOnGlobalLayoutListener(navObserver) - if (intent.getBooleanExtra(Const.Key.OPEN_SETTINGS, false)) { - HomeFragmentDirections.actionHomeFragmentToSettingsFragment().navigate() + when { + intent.hasExtra(Const.Key.OPEN_SECTION) -> + getScreen(intent.getStringExtra(Const.Key.OPEN_SECTION))?.navigate() + intent.getBooleanExtra(Const.Key.OPEN_SETTINGS, false) -> + HomeFragmentDirections.actionHomeFragmentToSettingsFragment().navigate() } + if (savedInstanceState != null) { if (!isRoot) { requestNavigationHidden() @@ -165,4 +170,14 @@ open class MainActivity : BaseUIActivity( binding.mainToolbar.invalidate() } + private fun getScreen(name: String?): NavDirections? { + return when (name) { + "superuser" -> HomeFragmentDirections.actionSuperuserFragment() + "magiskhide" -> HomeFragmentDirections.actionHideFragment() + "modules" -> HomeFragmentDirections.actionModuleFragment() + null -> null + else -> TODO("Implement screen shortcut \"$name\"") + } + } + } diff --git a/app/src/main/res/navigation/main.xml b/app/src/main/res/navigation/main.xml index f75adda2e..f3febf07d 100644 --- a/app/src/main/res/navigation/main.xml +++ b/app/src/main/res/navigation/main.xml @@ -182,4 +182,14 @@ app:popUpTo="@id/installFragment" app:popUpToInclusive="true" /> + + \ No newline at end of file