mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-25 18:57:39 +00:00
Added basic navigation
This commit is contained in:
parent
191c7c50b6
commit
dc8d2ae683
@ -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 {
|
||||
|
@ -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<MainViewModel, ActivityMainMd2Binding>(
|
||||
override val defaultPosition: Int = 0
|
||||
|
||||
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?) {
|
||||
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) {
|
||||
|
@ -3,13 +3,13 @@
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<item
|
||||
android:id="@+id/magiskFragment"
|
||||
android:id="@+id/homeFragment"
|
||||
android:icon="@drawable/ic_home"
|
||||
android:title="Home"
|
||||
tools:showAsAction="always" />
|
||||
|
||||
<item
|
||||
android:id="@+id/magiskFragment"
|
||||
android:id="@+id/modulesFragment"
|
||||
android:icon="@drawable/ic_cloud_download"
|
||||
android:title="@string/modules"
|
||||
tools:showAsAction="always" />
|
||||
@ -21,7 +21,7 @@
|
||||
tools:showAsAction="always" />
|
||||
|
||||
<item
|
||||
android:id="@+id/magiskFragment"
|
||||
android:id="@+id/logFragment"
|
||||
android:icon="@drawable/ic_bug_report"
|
||||
android:title="@string/log"
|
||||
tools:showAsAction="always" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user