From 1d831d65f3217d9b4d0fe9fcae4b4639d92dab79 Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Sat, 1 Feb 2020 14:41:22 +0100 Subject: [PATCH] Added overflow menu for reboot --- .../topjohnwu/magisk/ui/home/HomeViewModel.kt | 9 +++++++ .../magisk/utils/DataBindingAdapters.kt | 24 +++++++++++++++++++ .../main/res/layout/include_home_device.xml | 8 ++++++- app/src/main/res/menu/menu_reboot.xml | 24 +++++++++++++++++++ app/src/main/res/values/dimens.xml | 1 + app/src/main/res/values/styles_md2.xml | 8 +++++++ 6 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 app/src/main/res/menu/menu_reboot.xml diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt index e06e63274..d0e8403f6 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt @@ -136,6 +136,15 @@ class HomeViewModel( .subscribeK { Navigation.install().publish() } .add() + fun rebootPressed(menuItemId: Int) = when (menuItemId) { + R.id.action_reboot_normal -> reboot() + R.id.action_reboot_bootloader -> reboot("bootloader") + R.id.action_reboot_download -> reboot("download") + R.id.action_reboot_edl -> reboot("edl") + R.id.action_reboot_recovery -> Shell.su("/system/bin/reboot recovery").submit() + else -> Unit + } + fun toggle(kof: KObservableField) = kof.toggle() fun hideNotice() { diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/DataBindingAdapters.kt b/app/src/main/java/com/topjohnwu/magisk/utils/DataBindingAdapters.kt index ae23cfa29..e0eb1f21a 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/DataBindingAdapters.kt +++ b/app/src/main/java/com/topjohnwu/magisk/utils/DataBindingAdapters.kt @@ -5,9 +5,11 @@ import android.animation.ValueAnimator import android.graphics.Paint import android.graphics.drawable.Drawable import android.os.Build +import android.view.ContextThemeWrapper import android.view.View import android.view.ViewAnimationUtils import android.view.ViewGroup +import android.widget.PopupMenu import android.widget.ProgressBar import android.widget.TextView import androidx.annotation.ColorInt @@ -460,4 +462,26 @@ fun TextView.setStrikeThroughEnabled(useStrikeThrough: Boolean) { } else { paintFlags and Paint.STRIKE_THRU_TEXT_FLAG.inv() } +} + +interface OnPopupMenuItemClickListener { + fun onMenuItemClick(itemId: Int) +} + +@BindingAdapter("popupMenu", "popupMenuOnClickListener", requireAll = false) +fun View.setPopupMenu(popupMenu: Int, listener: OnPopupMenuItemClickListener) { + tag = tag as? PopupMenu ?: let { + val themeWrapper = ContextThemeWrapper(context, R.style.Foundation_PopupMenu) + PopupMenu(themeWrapper, this) + } + setOnClickListener { + (tag as PopupMenu).apply { + menuInflater.inflate(popupMenu, menu) + setOnMenuItemClickListener { + listener.onMenuItemClick(it.itemId) + true + } + show() + } + } } \ No newline at end of file diff --git a/app/src/main/res/layout/include_home_device.xml b/app/src/main/res/layout/include_home_device.xml index 40f630ea5..751e6cb83 100644 --- a/app/src/main/res/layout/include_home_device.xml +++ b/app/src/main/res/layout/include_home_device.xml @@ -11,6 +11,10 @@ + + + + @@ -44,10 +48,12 @@ app:layout_constraintStart_toEndOf="@+id/home_device_icon" app:layout_constraintTop_toTopOf="parent" /> - + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 1f6e3b328..089a6ba48 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -14,6 +14,7 @@ 12dp 16dp 32dp + 48dp 8dp diff --git a/app/src/main/res/values/styles_md2.xml b/app/src/main/res/values/styles_md2.xml index b502f095a..304428c68 100644 --- a/app/src/main/res/values/styles_md2.xml +++ b/app/src/main/res/values/styles_md2.xml @@ -23,6 +23,13 @@ + +