From dc8d2ae68319d297dddc1a0c12966d4274afbf5d Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Thu, 3 Oct 2019 19:38:57 +0200 Subject: [PATCH] Added basic navigation --- .../magisk/model/navigation/Navigation.kt | 15 ++++++++++-- .../topjohnwu/magisk/redesign/MainActivity.kt | 23 ++++++++++++++++++- app/src/main/res/menu/menu_bottom_nav.xml | 6 ++--- 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/model/navigation/Navigation.kt b/app/src/main/java/com/topjohnwu/magisk/model/navigation/Navigation.kt index f339fff30..83e309203 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/navigation/Navigation.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/navigation/Navigation.kt @@ -14,12 +14,23 @@ import com.topjohnwu.magisk.ui.module.ReposFragment import com.topjohnwu.magisk.ui.settings.SettingsFragment import com.topjohnwu.magisk.ui.superuser.SuperuserFragment import com.topjohnwu.magisk.redesign.MainActivity as RedesignActivity +import com.topjohnwu.magisk.redesign.home.HomeFragment as RedesignHomeFragment object Navigation { fun home() = MagiskNavigationEvent { - navDirections { destination = HomeFragment::class } - navOptions { popUpTo = HomeFragment::class } + navDirections { + destination = when { + Config.redesign -> RedesignHomeFragment::class + else -> HomeFragment::class + } + } + navOptions { + popUpTo = when { + Config.redesign -> RedesignHomeFragment::class + else -> HomeFragment::class + } + } } fun superuser() = MagiskNavigationEvent { diff --git a/app/src/main/java/com/topjohnwu/magisk/redesign/MainActivity.kt b/app/src/main/java/com/topjohnwu/magisk/redesign/MainActivity.kt index f84ab9cf5..9ccdaca87 100644 --- a/app/src/main/java/com/topjohnwu/magisk/redesign/MainActivity.kt +++ b/app/src/main/java/com/topjohnwu/magisk/redesign/MainActivity.kt @@ -6,8 +6,13 @@ import androidx.fragment.app.Fragment import com.ncapdevi.fragnav.FragNavController import com.topjohnwu.magisk.R import com.topjohnwu.magisk.databinding.ActivityMainMd2Binding +import com.topjohnwu.magisk.model.navigation.Navigation import com.topjohnwu.magisk.redesign.compat.CompatActivity import com.topjohnwu.magisk.redesign.home.HomeFragment +import com.topjohnwu.magisk.ui.log.LogFragment +import com.topjohnwu.magisk.ui.module.ModulesFragment +import com.topjohnwu.magisk.ui.settings.SettingsFragment +import com.topjohnwu.magisk.ui.superuser.SuperuserFragment import org.koin.androidx.viewmodel.ext.android.viewModel import kotlin.reflect.KClass @@ -19,13 +24,29 @@ open class MainActivity : CompatActivity( override val defaultPosition: Int = 0 override val baseFragments: List> = listOf( - HomeFragment::class + HomeFragment::class, + ModulesFragment::class, + SuperuserFragment::class, + LogFragment::class, + SettingsFragment::class ) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setSupportActionBar(binding.mainToolbar) + + binding.mainNavigation.setOnNavigationItemSelectedListener { + when (it.itemId) { + R.id.homeFragment -> Navigation.home() + R.id.modulesFragment -> Navigation.modules() + R.id.superuserFragment -> Navigation.superuser() + R.id.logFragment -> Navigation.log() + R.id.settingsFragment -> Navigation.settings() + else -> throw NotImplementedError("Id ${it.itemId} is not defined as selectable") + }.also { onEventDispatched(it) } + true + } } override fun onTabTransaction(fragment: Fragment?, index: Int) { diff --git a/app/src/main/res/menu/menu_bottom_nav.xml b/app/src/main/res/menu/menu_bottom_nav.xml index 6cf30c32d..2789218ee 100644 --- a/app/src/main/res/menu/menu_bottom_nav.xml +++ b/app/src/main/res/menu/menu_bottom_nav.xml @@ -3,13 +3,13 @@ xmlns:tools="http://schemas.android.com/tools"> @@ -21,7 +21,7 @@ tools:showAsAction="always" />