Added overflow menu for reboot

This commit is contained in:
Viktor De Pasquale 2020-02-01 14:41:22 +01:00 committed by John Wu
parent c35d020731
commit 1d831d65f3
6 changed files with 73 additions and 1 deletions

View File

@ -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<Boolean>) = kof.toggle()
fun hideNotice() {

View File

@ -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()
}
}
}

View File

@ -11,6 +11,10 @@
<import type="com.topjohnwu.magisk.extensions.XSUKt" />
<import type="com.topjohnwu.magisk.R" />
<import type="com.topjohnwu.superuser.Shell" />
<variable
name="viewModel"
type="com.topjohnwu.magisk.ui.home.HomeViewModel" />
@ -44,10 +48,12 @@
app:layout_constraintStart_toEndOf="@+id/home_device_icon"
app:layout_constraintTop_toTopOf="parent" />
<!--todo (diareuse) add dropdown menu so users can choose which reboot they want -->
<com.google.android.material.button.MaterialButton
android:id="@+id/home_device_action_reboot"
style="@style/WidgetFoundation.Button.Text"
gone="@{!Shell.rootAccess()}"
popupMenu="@{R.menu.menu_reboot}"
popupMenuOnClickListener="@{(it) -> viewModel.rebootPressed(it)}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/l_50"

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/action_reboot_normal"
android:title="@string/reboot" />
<item
android:id="@+id/action_reboot_bootloader"
android:title="@string/reboot_bootloader" />
<item
android:id="@+id/action_reboot_download"
android:title="@string/reboot_download" />
<item
android:id="@+id/action_reboot_edl"
android:title="@string/reboot_edl" />
<item
android:id="@+id/action_reboot_recovery"
android:title="@string/reboot_recovery" />
</menu>

View File

@ -14,6 +14,7 @@
<dimen name="l_75">12dp</dimen>
<dimen name="l1">16dp</dimen>
<dimen name="l2">32dp</dimen>
<dimen name="l3">48dp</dimen>
<dimen name="r1">8dp</dimen>

View File

@ -23,6 +23,13 @@
</style>
<!--endregion-->
<style name="Foundation.PopupMenu" parent="Widget.AppCompat.PopupMenu">
<item name="android:textColor">?colorOnSurface</item>
<item name="android:itemBackground">?colorSurfaceVariant</item>
<item name="android:itemTextAppearance">@style/AppearanceFoundation.Caption</item>
<item name="android:textStyle">bold</item>
</style>
<style name="Foundation.Base" parent="Foundation.Compat">
<item name="android:fontFamily">@font/exo</item>
<item name="android:includeFontPadding">false</item>
@ -32,6 +39,7 @@
<item name="selectableItemBackground">@drawable/bg_selectable</item>
<item name="selectableItemBackgroundBorderless">@drawable/bg_selectable_borderless</item>
<item name="actionBarSize">@dimen/internal_action_bar_size</item>
<item name="popupMenuStyle">@style/Foundation.PopupMenu</item>
</style>
<style name="Foundation.Default" parent="Foundation.Base">