Added disabled state for sections where unrooted user shouldn't have access

This commit is contained in:
Viktor De Pasquale 2019-10-16 15:47:41 +02:00
parent 37fa227fb5
commit 51247d36c5
5 changed files with 15 additions and 0 deletions

View File

@ -16,6 +16,7 @@ import com.topjohnwu.magisk.ui.log.LogFragment
import com.topjohnwu.magisk.ui.module.ModulesFragment import com.topjohnwu.magisk.ui.module.ModulesFragment
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.superuser.Shell
import org.koin.androidx.viewmodel.ext.android.viewModel import org.koin.androidx.viewmodel.ext.android.viewModel
import kotlin.reflect.KClass import kotlin.reflect.KClass
@ -66,6 +67,16 @@ open class MainActivity : CompatActivity<MainViewModel, ActivityMainMd2Binding>(
} }
} }
override fun onResume() {
super.onResume()
binding.mainNavigation.menu.apply {
val isRoot = Shell.rootAccess()
findItem(R.id.modulesFragment)?.isEnabled = isRoot
findItem(R.id.superuserFragment)?.isEnabled = isRoot
findItem(R.id.logFragment)?.isEnabled = isRoot
}
}
override fun onDestroy() { override fun onDestroy() {
binding.mainNavigation.viewTreeObserver.removeOnGlobalLayoutListener(navObserver) binding.mainNavigation.viewTreeObserver.removeOnGlobalLayoutListener(navObserver)
super.onDestroy() super.onDestroy()

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="?colorDisabledVariant" android:state_enabled="false" />
<item android:color="?colorSecondary" android:state_checked="true" /> <item android:color="?colorSecondary" android:state_checked="true" />
<item android:color="?colorOnSurfaceVariant" /> <item android:color="?colorOnSurfaceVariant" />
</selector> </selector>

View File

@ -17,6 +17,7 @@
<item name="colorOnSurface">#BABABA</item> <item name="colorOnSurface">#BABABA</item>
<item name="colorOnSurfaceVariant">#80BABABA</item> <item name="colorOnSurfaceVariant">#80BABABA</item>
<item name="colorDisabled">#808080</item> <item name="colorDisabled">#808080</item>
<item name="colorDisabledVariant">#66808080</item>
<item name="colorTextTransient">@color/color_text_transient</item> <item name="colorTextTransient">@color/color_text_transient</item>
<item name="colorPrimaryTransient">@color/color_primary_transient</item> <item name="colorPrimaryTransient">@color/color_primary_transient</item>
<item name="colorErrorTransient">@color/color_error_transient</item> <item name="colorErrorTransient">@color/color_error_transient</item>

View File

@ -81,6 +81,7 @@
<!--Static--> <!--Static-->
<attr name="colorDisabled" format="color" /> <attr name="colorDisabled" format="color" />
<attr name="colorDisabledVariant" format="color" />
<attr name="colorSurfaceVariant" format="color" /> <attr name="colorSurfaceVariant" format="color" />
<attr name="colorOnPrimaryVariant" format="color" /> <attr name="colorOnPrimaryVariant" format="color" />
<attr name="colorOnSurfaceVariant" format="color" /> <attr name="colorOnSurfaceVariant" format="color" />

View File

@ -100,6 +100,7 @@
<item name="colorOnSurface">#444444</item> <item name="colorOnSurface">#444444</item>
<item name="colorOnSurfaceVariant">#80444444</item> <item name="colorOnSurfaceVariant">#80444444</item>
<item name="colorDisabled">#808080</item> <item name="colorDisabled">#808080</item>
<item name="colorDisabledVariant">#66808080</item>
<item name="colorTextTransient">@color/color_text_transient</item> <item name="colorTextTransient">@color/color_text_transient</item>
<item name="colorPrimaryTransient">@color/color_primary_transient</item> <item name="colorPrimaryTransient">@color/color_primary_transient</item>
<item name="colorErrorTransient">@color/color_error_transient</item> <item name="colorErrorTransient">@color/color_error_transient</item>