Added basic navigation

This commit is contained in:
Viktor De Pasquale 2019-10-03 19:38:57 +02:00
parent 191c7c50b6
commit dc8d2ae683
3 changed files with 38 additions and 6 deletions

View File

@ -14,12 +14,23 @@ import com.topjohnwu.magisk.ui.module.ReposFragment
import com.topjohnwu.magisk.ui.settings.SettingsFragment import com.topjohnwu.magisk.ui.settings.SettingsFragment
import com.topjohnwu.magisk.ui.superuser.SuperuserFragment import com.topjohnwu.magisk.ui.superuser.SuperuserFragment
import com.topjohnwu.magisk.redesign.MainActivity as RedesignActivity import com.topjohnwu.magisk.redesign.MainActivity as RedesignActivity
import com.topjohnwu.magisk.redesign.home.HomeFragment as RedesignHomeFragment
object Navigation { object Navigation {
fun home() = MagiskNavigationEvent { fun home() = MagiskNavigationEvent {
navDirections { destination = HomeFragment::class } navDirections {
navOptions { popUpTo = HomeFragment::class } destination = when {
Config.redesign -> RedesignHomeFragment::class
else -> HomeFragment::class
}
}
navOptions {
popUpTo = when {
Config.redesign -> RedesignHomeFragment::class
else -> HomeFragment::class
}
}
} }
fun superuser() = MagiskNavigationEvent { fun superuser() = MagiskNavigationEvent {

View File

@ -6,8 +6,13 @@ import androidx.fragment.app.Fragment
import com.ncapdevi.fragnav.FragNavController import com.ncapdevi.fragnav.FragNavController
import com.topjohnwu.magisk.R import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.databinding.ActivityMainMd2Binding 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.compat.CompatActivity
import com.topjohnwu.magisk.redesign.home.HomeFragment 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 org.koin.androidx.viewmodel.ext.android.viewModel
import kotlin.reflect.KClass import kotlin.reflect.KClass
@ -19,13 +24,29 @@ open class MainActivity : CompatActivity<MainViewModel, ActivityMainMd2Binding>(
override val defaultPosition: Int = 0 override val defaultPosition: Int = 0
override val baseFragments: List<KClass<out Fragment>> = listOf( override val baseFragments: List<KClass<out Fragment>> = listOf(
HomeFragment::class HomeFragment::class,
ModulesFragment::class,
SuperuserFragment::class,
LogFragment::class,
SettingsFragment::class
) )
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setSupportActionBar(binding.mainToolbar) 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) { override fun onTabTransaction(fragment: Fragment?, index: Int) {

View File

@ -3,13 +3,13 @@
xmlns:tools="http://schemas.android.com/tools"> xmlns:tools="http://schemas.android.com/tools">
<item <item
android:id="@+id/magiskFragment" android:id="@+id/homeFragment"
android:icon="@drawable/ic_home" android:icon="@drawable/ic_home"
android:title="Home" android:title="Home"
tools:showAsAction="always" /> tools:showAsAction="always" />
<item <item
android:id="@+id/magiskFragment" android:id="@+id/modulesFragment"
android:icon="@drawable/ic_cloud_download" android:icon="@drawable/ic_cloud_download"
android:title="@string/modules" android:title="@string/modules"
tools:showAsAction="always" /> tools:showAsAction="always" />
@ -21,7 +21,7 @@
tools:showAsAction="always" /> tools:showAsAction="always" />
<item <item
android:id="@+id/magiskFragment" android:id="@+id/logFragment"
android:icon="@drawable/ic_bug_report" android:icon="@drawable/ic_bug_report"
android:title="@string/log" android:title="@string/log"
tools:showAsAction="always" /> tools:showAsAction="always" />