2019-04-11 18:01:49 +00:00
|
|
|
package com.topjohnwu.magisk.ui
|
|
|
|
|
|
|
|
import android.content.Intent
|
|
|
|
import android.os.Bundle
|
2019-04-11 19:17:54 +00:00
|
|
|
import androidx.core.view.GravityCompat
|
2019-04-16 17:00:32 +00:00
|
|
|
import androidx.fragment.app.Fragment
|
2019-04-11 18:01:49 +00:00
|
|
|
import com.topjohnwu.magisk.ClassMap
|
|
|
|
import com.topjohnwu.magisk.Config
|
2019-04-27 10:08:41 +00:00
|
|
|
import com.topjohnwu.magisk.Const.Key.OPEN_SECTION
|
2019-04-11 18:01:49 +00:00
|
|
|
import com.topjohnwu.magisk.R
|
|
|
|
import com.topjohnwu.magisk.databinding.ActivityMainBinding
|
2019-04-11 19:17:54 +00:00
|
|
|
import com.topjohnwu.magisk.model.navigation.Navigation
|
2019-04-11 18:01:49 +00:00
|
|
|
import com.topjohnwu.magisk.ui.base.MagiskActivity
|
2019-04-16 17:00:32 +00:00
|
|
|
import com.topjohnwu.magisk.ui.hide.MagiskHideFragment
|
|
|
|
import com.topjohnwu.magisk.ui.log.LogFragment
|
|
|
|
import com.topjohnwu.magisk.ui.module.ModulesFragment
|
|
|
|
import com.topjohnwu.magisk.ui.module.ReposFragment
|
|
|
|
import com.topjohnwu.magisk.ui.settings.SettingsFragment
|
|
|
|
import com.topjohnwu.magisk.ui.superuser.SuperuserFragment
|
2019-04-11 18:01:49 +00:00
|
|
|
import com.topjohnwu.magisk.utils.Utils
|
|
|
|
import com.topjohnwu.net.Networking
|
|
|
|
import com.topjohnwu.superuser.Shell
|
|
|
|
import org.koin.androidx.viewmodel.ext.android.viewModel
|
2019-04-16 17:00:32 +00:00
|
|
|
import kotlin.reflect.KClass
|
|
|
|
import com.topjohnwu.magisk.ui.home.MagiskFragment as HomeFragment
|
2019-04-11 18:01:49 +00:00
|
|
|
|
2019-04-27 10:08:41 +00:00
|
|
|
|
2019-04-11 19:17:54 +00:00
|
|
|
open class MainActivity : MagiskActivity<MainViewModel, ActivityMainBinding>() {
|
2019-04-11 18:01:49 +00:00
|
|
|
|
|
|
|
override val layoutRes: Int = R.layout.activity_main
|
|
|
|
override val viewModel: MainViewModel by viewModel()
|
|
|
|
override val navHostId: Int = R.id.main_nav_host
|
2019-04-16 17:00:32 +00:00
|
|
|
override val defaultPosition: Int = 0
|
|
|
|
|
|
|
|
override val baseFragments: List<KClass<out Fragment>> = listOf(
|
|
|
|
HomeFragment::class,
|
|
|
|
SuperuserFragment::class,
|
|
|
|
MagiskHideFragment::class,
|
|
|
|
ModulesFragment::class,
|
|
|
|
ReposFragment::class,
|
|
|
|
LogFragment::class,
|
|
|
|
SettingsFragment::class
|
|
|
|
)
|
2019-04-11 18:01:49 +00:00
|
|
|
|
|
|
|
/*override fun getDarkTheme(): Int {
|
|
|
|
return R.style.AppTheme_Dark
|
|
|
|
}*/
|
|
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
if (!SplashActivity.DONE) {
|
|
|
|
startActivity(Intent(this, ClassMap.get<Any>(SplashActivity::class.java)))
|
|
|
|
finish()
|
|
|
|
}
|
|
|
|
|
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
checkHideSection()
|
2019-04-11 19:17:54 +00:00
|
|
|
setSupportActionBar(binding.mainInclude.mainToolbar)
|
2019-04-11 18:01:49 +00:00
|
|
|
|
2019-04-27 10:08:41 +00:00
|
|
|
if (savedInstanceState == null) {
|
|
|
|
intent.getStringExtra(OPEN_SECTION)?.let {
|
|
|
|
onEventDispatched(Navigation.fromSection(it))
|
|
|
|
}
|
|
|
|
}
|
2019-04-11 18:01:49 +00:00
|
|
|
}
|
|
|
|
|
2019-04-18 13:51:02 +00:00
|
|
|
override fun setTitle(title: CharSequence?) {
|
|
|
|
supportActionBar?.title = title
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun setTitle(titleId: Int) {
|
|
|
|
supportActionBar?.setTitle(titleId)
|
|
|
|
}
|
|
|
|
|
2019-04-11 18:01:49 +00:00
|
|
|
override fun onBackPressed() {
|
|
|
|
if (binding.drawerLayout.isDrawerOpen(binding.navView)) {
|
|
|
|
binding.drawerLayout.closeDrawer(binding.navView)
|
|
|
|
} else {
|
2019-04-11 19:17:54 +00:00
|
|
|
super.onBackPressed()
|
2019-04-11 18:01:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-11 19:17:54 +00:00
|
|
|
override fun onSimpleEventDispatched(event: Int) {
|
|
|
|
super.onSimpleEventDispatched(event)
|
|
|
|
when (event) {
|
|
|
|
Navigation.Main.OPEN_NAV -> openNav()
|
|
|
|
}
|
2019-04-11 18:01:49 +00:00
|
|
|
}
|
|
|
|
|
2019-04-11 19:17:54 +00:00
|
|
|
private fun openNav() = binding.drawerLayout.openDrawer(GravityCompat.START)
|
|
|
|
|
2019-04-11 18:01:49 +00:00
|
|
|
fun checkHideSection() {
|
|
|
|
val menu = binding.navView.menu
|
2019-04-11 19:17:54 +00:00
|
|
|
menu.findItem(R.id.magiskHideFragment).isVisible =
|
2019-04-11 18:01:49 +00:00
|
|
|
Shell.rootAccess() && Config.get<Any>(Config.Key.MAGISKHIDE) as Boolean
|
2019-04-11 19:17:54 +00:00
|
|
|
menu.findItem(R.id.modulesFragment).isVisible =
|
|
|
|
Shell.rootAccess() && Config.magiskVersionCode >= 0
|
|
|
|
menu.findItem(R.id.reposFragment).isVisible =
|
|
|
|
(Networking.checkNetworkStatus(this) && Shell.rootAccess() && Config.magiskVersionCode >= 0)
|
|
|
|
menu.findItem(R.id.logFragment).isVisible =
|
|
|
|
Shell.rootAccess()
|
|
|
|
menu.findItem(R.id.superuserFragment).isVisible =
|
|
|
|
Utils.showSuperUser()
|
2019-04-11 18:01:49 +00:00
|
|
|
}
|
|
|
|
}
|