Fixed shortcuts

This has been broken due to recent transition to navigation components
This commit is contained in:
Viktor De Pasquale 2020-04-11 18:34:10 +02:00 committed by John Wu
parent ee3028e67d
commit d9cf33d1ba
2 changed files with 27 additions and 2 deletions

View File

@ -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<MainViewModel, ActivityMainMd2Binding>(
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<MainViewModel, ActivityMainMd2Binding>(
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\"")
}
}
}

View File

@ -182,4 +182,14 @@
app:popUpTo="@id/installFragment"
app:popUpToInclusive="true" />
<action
android:id="@+id/action_hideFragment"
app:destination="@id/hideFragment"
app:enterAnim="@anim/fragment_enter"
app:exitAnim="@anim/fragment_exit"
app:popEnterAnim="@anim/fragment_enter_pop"
app:popExitAnim="@anim/fragment_exit_pop"
app:popUpTo="@id/superuserFragment"
app:popUpToInclusive="false" />
</navigation>