diff --git a/app/src/main/java/com/topjohnwu/magisk/model/events/RebootEvent.kt b/app/src/main/java/com/topjohnwu/magisk/model/events/RebootEvent.kt index af588d2f3..e6949f04e 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/events/RebootEvent.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/events/RebootEvent.kt @@ -1,19 +1,33 @@ package com.topjohnwu.magisk.model.events +import android.view.ContextThemeWrapper +import android.view.MenuItem +import android.widget.PopupMenu import com.topjohnwu.magisk.R +import com.topjohnwu.magisk.core.base.BaseActivity import com.topjohnwu.superuser.Shell import com.topjohnwu.magisk.extensions.reboot as systemReboot object RebootEvent { - @JvmStatic - fun reboot(menuItemId: Int) = when (menuItemId) { - R.id.action_reboot_normal -> systemReboot() - R.id.action_reboot_bootloader -> systemReboot("bootloader") - R.id.action_reboot_download -> systemReboot("download") - R.id.action_reboot_edl -> systemReboot("edl") - R.id.action_reboot_recovery -> Shell.su("/system/bin/reboot recovery").submit() - else -> Unit + private fun reboot(item: MenuItem): Boolean { + when (item.itemId) { + R.id.action_reboot_normal -> systemReboot() + R.id.action_reboot_bootloader -> systemReboot("bootloader") + R.id.action_reboot_download -> systemReboot("download") + R.id.action_reboot_edl -> systemReboot("edl") + R.id.action_reboot_recovery -> Shell.su("/system/bin/reboot recovery").submit() + else -> Unit + } + return true } -} \ No newline at end of file + fun inflateMenu(activity: BaseActivity): PopupMenu { + val themeWrapper = ContextThemeWrapper(activity, R.style.Foundation_PopupMenu) + val menu = PopupMenu(themeWrapper, activity.findViewById(R.id.action_reboot)) + activity.menuInflater.inflate(R.menu.menu_reboot, menu.menu) + menu.setOnMenuItemClickListener(::reboot) + return menu + } + +} diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeFragment.kt b/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeFragment.kt index 5b090c525..83a0f5631 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeFragment.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeFragment.kt @@ -4,8 +4,10 @@ import android.os.Bundle import android.view.* import com.topjohnwu.magisk.R import com.topjohnwu.magisk.databinding.FragmentHomeMd2Binding +import com.topjohnwu.magisk.model.events.RebootEvent import com.topjohnwu.magisk.model.navigation.Navigation import com.topjohnwu.magisk.ui.base.BaseUIFragment +import com.topjohnwu.superuser.Shell import org.koin.androidx.viewmodel.ext.android.viewModel class HomeFragment : BaseUIFragment() { @@ -27,8 +29,6 @@ class HomeFragment : BaseUIFragment() { super.onCreateView(inflater, container, savedInstanceState) // Set barrier reference IDs in code, since resource IDs will be stripped in release mode - binding.homeDeviceWrapper.homeDeviceTitleBarrier.referencedIds = - intArrayOf(R.id.home_device_action, R.id.home_device_title, R.id.home_device_icon) binding.homeMagiskWrapper.homeMagiskTitleBarrier.referencedIds = intArrayOf(R.id.home_magisk_action, R.id.home_magisk_title, R.id.home_magisk_icon) binding.homeManagerWrapper.homeManagerTitleBarrier.referencedIds = @@ -39,10 +39,13 @@ class HomeFragment : BaseUIFragment() { override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { inflater.inflate(R.menu.menu_home_md2, menu) + if (!Shell.rootAccess()) + menu.removeItem(R.id.action_reboot) } override fun onOptionsItemSelected(item: MenuItem) = when (item.itemId) { R.id.action_settings -> Navigation.settings().dispatchOnSelf() + R.id.action_reboot -> RebootEvent.inflateMenu(activity).show() else -> null }?.let { true } ?: super.onOptionsItemSelected(item) diff --git a/app/src/main/res/drawable/ic_restart.xml b/app/src/main/res/drawable/ic_restart.xml index 5d7c2e1f8..b4f8eaee9 100644 --- a/app/src/main/res/drawable/ic_restart.xml +++ b/app/src/main/res/drawable/ic_restart.xml @@ -5,6 +5,6 @@ android:viewportWidth="24" android:viewportHeight="24"> - \ No newline at end of file + diff --git a/app/src/main/res/layout/fragment_home_md2.xml b/app/src/main/res/layout/fragment_home_md2.xml index e5e876e34..5b1b4be11 100644 --- a/app/src/main/res/layout/fragment_home_md2.xml +++ b/app/src/main/res/layout/fragment_home_md2.xml @@ -67,16 +67,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/layout/include_home_magisk.xml b/app/src/main/res/layout/include_home_magisk.xml index 173ae9022..823768fb9 100644 --- a/app/src/main/res/layout/include_home_magisk.xml +++ b/app/src/main/res/layout/include_home_magisk.xml @@ -197,6 +197,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/menu/menu_home_md2.xml b/app/src/main/res/menu/menu_home_md2.xml index 2902b2df6..0a2f39823 100644 --- a/app/src/main/res/menu/menu_home_md2.xml +++ b/app/src/main/res/menu/menu_home_md2.xml @@ -2,6 +2,12 @@ + +