Remove device section

This commit is contained in:
topjohnwu 2020-02-12 13:26:10 -08:00
parent d2701616da
commit ce7cb1eeae
7 changed files with 107 additions and 269 deletions

View File

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

View File

@ -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<HomeViewModel, FragmentHomeMd2Binding>() {
@ -27,8 +29,6 @@ class HomeFragment : BaseUIFragment<HomeViewModel, FragmentHomeMd2Binding>() {
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<HomeViewModel, FragmentHomeMd2Binding>() {
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)

View File

@ -5,6 +5,6 @@
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#000"
android:fillColor="?colorOnSurface"
android:pathData="M12,4C14.1,4 16.1,4.8 17.6,6.3C20.7,9.4 20.7,14.5 17.6,17.6C15.8,19.5 13.3,20.2 10.9,19.9L11.4,17.9C13.1,18.1 14.9,17.5 16.2,16.2C18.5,13.9 18.5,10.1 16.2,7.7C15.1,6.6 13.5,6 12,6V10.6L7,5.6L12,0.6V4M6.3,17.6C3.7,15 3.3,11 5.1,7.9L6.6,9.4C5.5,11.6 5.9,14.4 7.8,16.2C8.3,16.7 8.9,17.1 9.6,17.4L9,19.4C8,19 7.1,18.4 6.3,17.6Z" />
</vector>
</vector>

View File

@ -67,16 +67,6 @@
</com.google.android.material.card.MaterialCardView>
<include
android:id="@+id/home_device_wrapper"
layout="@layout/include_home_device"
viewModel="@{viewModel}"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/l1"
android:layout_marginEnd="@dimen/l1"
app:layout_constraintTop_toTopOf="parent" />
<include
android:id="@+id/home_magisk_wrapper"
layout="@layout/include_home_magisk"
@ -85,7 +75,6 @@
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/l1"
android:layout_marginEnd="@dimen/l1"
android:layout_marginTop="@dimen/l1"
app:layout_constraintTop_toBottomOf="@+id/home_device_wrapper" />
<include

View File

@ -1,245 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<import type="android.os.Build" />
<import type="com.topjohnwu.magisk.extensions.XSUKt" />
<import type="com.topjohnwu.magisk.R" />
<import type="com.topjohnwu.magisk.model.events.RebootEvent" />
<import type="com.topjohnwu.magisk.core.Info" />
<variable
name="viewModel"
type="com.topjohnwu.magisk.ui.home.HomeViewModel" />
</data>
<com.google.android.material.card.MaterialCardView
style="@style/WidgetFoundation.Card"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/l_50"
android:paddingStart="@dimen/l1"
android:paddingEnd="@dimen/l1"
android:paddingBottom="@dimen/l1"
tools:layout_gravity="center">
<ImageView
android:id="@+id/home_device_icon"
style="@style/WidgetFoundation.Icon.Primary"
android:padding="@dimen/l_50"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_device" />
<TextView
android:id="@+id/home_device_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/l1"
android:text="@string/home_device_title"
android:textAppearance="@style/AppearanceFoundation.Title"
android:textColor="?colorPrimary"
app:layout_constraintBottom_toBottomOf="@+id/home_device_icon"
app:layout_constraintEnd_toStartOf="@+id/home_device_action"
app:layout_constraintStart_toEndOf="@+id/home_device_icon"
app:layout_constraintTop_toTopOf="@+id/home_device_icon" />
<com.google.android.material.button.MaterialButton
android:id="@+id/home_device_action"
style="@style/WidgetFoundation.Button.Text"
invisibleUnless="@{XSUKt.hasRoot}"
popupMenu="@{R.menu.menu_reboot}"
popupMenuOnClickListener="@{RebootEvent::reboot}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/reboot"
android:textAllCaps="false"
app:icon="@drawable/ic_restart"
app:layout_constraintBottom_toBottomOf="@+id/home_device_title"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/home_device_title" />
<androidx.constraintlayout.widget.Barrier
android:id="@+id/home_device_title_barrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="bottom"
app:constraint_referenced_ids="home_device_action,home_device_title,home_device_icon" />
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fadingEdgeLength="@dimen/l1"
android:paddingTop="@dimen/l_50"
android:requiresFadingEdge="horizontal"
android:scrollbars="none"
app:layout_constraintTop_toBottomOf="@+id/home_device_title_barrier">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.google.android.material.card.MaterialCardView
style="@style/W.Home.Card.First"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<View
style="@style/W.Home.Section"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:id="@+id/home_device_info_manufacturer"
style="@style/W.Home.Item.Top"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
style="@style/W.Home.ItemContent"
android:text="@string/home_device_extra_manufacturer" />
<TextView
style="@style/W.Home.ItemContent.Right"
android:text="@{Build.MANUFACTURER}"
tools:text="Google" />
</LinearLayout>
<LinearLayout
android:id="@+id/home_device_info_product"
style="@style/W.Home.Item"
app:layout_constraintStart_toStartOf="@+id/home_device_info_manufacturer"
app:layout_constraintTop_toBottomOf="@+id/home_device_info_manufacturer">
<TextView
style="@style/W.Home.ItemContent"
android:text="@string/home_device_extra_model" />
<TextView
style="@style/W.Home.ItemContent.Right"
android:text="@{Build.DEVICE ?? Build.PRODUCT}"
tools:text="Pixel 4" />
</LinearLayout>
<LinearLayout
android:id="@+id/home_device_info_version"
style="@style/W.Home.Item.Bottom"
app:layout_constraintStart_toStartOf="@+id/home_device_info_product"
app:layout_constraintTop_toBottomOf="@+id/home_device_info_product">
<TextView
style="@style/W.Home.ItemContent"
android:text="@string/home_device_system" />
<TextView
style="@style/W.Home.ItemContent.Right"
android:text="@{Build.VERSION.RELEASE}"
tools:text="10" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
style="@style/W.Home.Card"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<View
style="@style/W.Home.Section"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<LinearLayout
android:id="@+id/home_device_details_ab"
style="@style/W.Home.Item.Top"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
style="@style/W.Home.ItemContent"
android:text="A/B" />
<TextView
style="@style/W.Home.ItemContent.Right"
android:text="@{Info.isAB ? @string/yes : @string/no}"
tools:text="Yes" />
</LinearLayout>
<LinearLayout
android:id="@+id/home_device_details_sar"
style="@style/W.Home.Item"
app:layout_constraintStart_toStartOf="@+id/home_device_details_ab"
app:layout_constraintTop_toBottomOf="@+id/home_device_details_ab">
<TextView
style="@style/W.Home.ItemContent"
android:text="SAR" />
<TextView
style="@style/W.Home.ItemContent.Right"
android:text="@{Info.isSAR ? @string/yes : @string/no}"
tools:text="Yes" />
</LinearLayout>
<LinearLayout
android:id="@+id/home_device_details_recovery"
style="@style/W.Home.Item.Bottom"
app:layout_constraintStart_toStartOf="@+id/home_device_details_sar"
app:layout_constraintTop_toBottomOf="@+id/home_device_details_sar">
<TextView
style="@style/W.Home.ItemContent"
android:text="Ramdisk" />
<TextView
style="@style/W.Home.ItemContent.Right"
android:text="@{Info.ramdisk ? @string/yes : @string/no }"
tools:text="Yes" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
</LinearLayout>
</HorizontalScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
</layout>

View File

@ -197,6 +197,77 @@
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
style="@style/W.Home.Card"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<View
style="@style/W.Home.Section"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<LinearLayout
android:id="@+id/home_device_details_ab"
style="@style/W.Home.Item.Top"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
style="@style/W.Home.ItemContent"
android:text="A/B" />
<TextView
style="@style/W.Home.ItemContent.Right"
android:text="@{Info.isAB ? @string/yes : @string/no}"
tools:text="Yes" />
</LinearLayout>
<LinearLayout
android:id="@+id/home_device_details_sar"
style="@style/W.Home.Item"
app:layout_constraintStart_toStartOf="@+id/home_device_details_ab"
app:layout_constraintTop_toBottomOf="@+id/home_device_details_ab">
<TextView
style="@style/W.Home.ItemContent"
android:text="SAR" />
<TextView
style="@style/W.Home.ItemContent.Right"
android:text="@{Info.isSAR ? @string/yes : @string/no}"
tools:text="Yes" />
</LinearLayout>
<LinearLayout
android:id="@+id/home_device_details_recovery"
style="@style/W.Home.Item.Bottom"
app:layout_constraintStart_toStartOf="@+id/home_device_details_sar"
app:layout_constraintTop_toBottomOf="@+id/home_device_details_sar">
<TextView
style="@style/W.Home.ItemContent"
android:text="Ramdisk" />
<TextView
style="@style/W.Home.ItemContent.Right"
android:text="@{Info.ramdisk ? @string/yes : @string/no }"
tools:text="Yes" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
</LinearLayout>
</HorizontalScrollView>

View File

@ -2,6 +2,12 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_reboot"
android:icon="@drawable/ic_restart"
android:title="@string/reboot"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_settings"
android:icon="@drawable/ic_settings_md2"