Updated layouts to fit new widget that should visually represent a switch

The switch is not actually a switch, but a representation of internal state, the layouts continue to accept touch events as beforehand.
This commit is contained in:
Viktor De Pasquale 2020-02-11 19:14:48 +01:00 committed by John Wu
parent d7653e6e42
commit 9952387356
15 changed files with 146 additions and 101 deletions

View File

@ -1,6 +1,8 @@
package com.topjohnwu.magisk.model.entity.recycler
import android.graphics.drawable.Drawable
import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.core.model.MagiskPolicy
import com.topjohnwu.magisk.databinding.ComparableRvItem
@ -47,6 +49,12 @@ class PolicyItem(val item: MagiskPolicy, val icon: Drawable) : ComparableRvItem<
viewModel.updatePolicy(PolicyUpdateEvent.Log(updatedPolicy))
}
override fun onBindingBound(binding: ViewDataBinding) {
super.onBindingBound(binding)
val params = binding.root.layoutParams as? StaggeredGridLayoutManager.LayoutParams
params?.isFullSpan = true
}
override fun contentSameAs(other: PolicyItem) = itemSameAs(other)
override fun itemSameAs(other: PolicyItem) = item.uid == other.item.uid

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/colorOverlay" />
<corners android:radius="20dp" />
<padding
android:bottom="@dimen/l_25"
android:left="@dimen/l_25"
android:right="@dimen/l_25"
android:top="@dimen/l_25" />
</shape>

View File

@ -5,6 +5,6 @@
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@color/colorText"
android:fillColor="?colorOnSurface"
android:pathData="M20,11V13H8L13.5,18.5L12.08,19.92L4.16,12L12.08,4.08L13.5,5.5L8,11H20Z" />
</vector>

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true">
<layer-list>
<item android:left="16dp">
<shape android:shape="oval">
<size android:width="16dp" android:height="16dp" />
<solid android:color="?colorPrimary" />
</shape>
</item>
</layer-list>
</item>
<item>
<layer-list>
<item android:right="16dp">
<shape android:shape="oval">
<size android:width="16dp" android:height="16dp" />
<solid android:color="?colorDisabledVariant" />
</shape>
</item>
</layer-list>
</item>
</selector>

View File

@ -36,12 +36,13 @@
app:navigationIcon="@drawable/ic_back_md2">
<androidx.appcompat.widget.AppCompatTextView
style="@style/Widget.Text.Emphasize"
movieBehavior="@{viewModel.loading}"
movieBehaviorText="@{viewModel.behaviorText}"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textAppearance="@style/AppearanceFoundation.Body"
android:textStyle="bold"
android:fontFamily="monospace"
android:gravity="center"
android:textColor="?colorOnSurface"

View File

@ -26,7 +26,7 @@
app:boxStrokeColor="?colorOnSurfaceVariant"
app:counterEnabled="true"
app:counterMaxLength="14"
app:counterOverflowTextColor="@color/colorError"
app:counterOverflowTextColor="?colorError"
app:error="@{data.error ? @string/settings_app_name_error : @string/empty}"
app:errorEnabled="true"
app:errorTextColor="?colorError"

View File

@ -35,7 +35,7 @@
android:paddingEnd="0dp"
android:paddingBottom="@{viewModel.insets.bottom + (int) @dimen/internal_action_bar_size + (int) @dimen/l1}"
app:layoutManager="androidx.recyclerview.widget.StaggeredGridLayoutManager"
app:spanCount="1"
app:spanCount="2"
tools:listitem="@layout/item_module_md2" />
<com.google.android.material.floatingactionbutton.FloatingActionButton

View File

@ -26,7 +26,6 @@
itemBinding="@{viewModel.itemBinding}"
items="@{viewModel.items}"
nestedScrollingEnabled="@{false}"
spanCount="@{Config.listSpanCount}"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
@ -35,7 +34,7 @@
android:paddingTop="@{viewModel.insets.top + (int) @dimen/internal_action_bar_size + (int) @dimen/l1}"
android:paddingBottom="@{viewModel.insets.bottom + (int) @dimen/l2}"
app:layoutManager="androidx.recyclerview.widget.StaggeredGridLayoutManager"
app:spanCount="1"
app:spanCount="2"
tools:layout_marginTop="24dp"
tools:listitem="@layout/item_policy_md2"
tools:paddingTop="@dimen/l1" />

View File

@ -17,18 +17,19 @@
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:background="?selectableItemBackground"
android:onClick="@{() -> item.toggle(viewModel)}"
android:layout_height="wrap_content"
android:layout_gravity="center">
android:layout_gravity="center"
android:alpha="@{item.isHidden() ? 1f : .7f}"
android:background="?selectableItemBackground"
android:onClick="@{() -> item.toggle(viewModel)}">
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/l1"
android:layout_marginTop="@dimen/l_50"
android:layout_marginTop="@dimen/l_75"
android:layout_marginEnd="@dimen/l1"
android:layout_marginBottom="@dimen/l_50"
android:layout_marginBottom="@dimen/l_75"
android:singleLine="true"
android:text="@{item.item.name}"
android:textAppearance="@style/AppearanceFoundation.Caption.Variant"
@ -41,17 +42,15 @@
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/hide_process_checkbox"
style="@style/WidgetFoundation.Image.Small"
android:layout_width="18dp"
android:layout_height="18dp"
isSelected="@{item.isHidden}"
android:layout_marginTop="@dimen/l_50"
android:layout_marginEnd="@dimen/l1"
android:layout_marginBottom="@dimen/l_50"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/l_50"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_radio_check_button"
app:tint="?colorPrimary" />
android:background="@drawable/bg_checkbox"
app:srcCompat="@drawable/ic_checkbox" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -30,57 +30,70 @@
tools:layout_marginBottom="@dimen/l1"
tools:layout_marginEnd="@dimen/l1">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/module_state_icon"
gone="@{!item.removed &amp;&amp; !item.updated}"
srcCompat="@{item.removed ? R.drawable.ic_delete_md2 : (item.updated ? R.drawable.ic_update_md2 : 0)}"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:alpha=".05"
android:background="@null"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:tint="?colorOnSurface"
tools:srcCompat="@drawable/ic_update_md2" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/module_state_icon"
style="@style/WidgetFoundation.Image.Small"
gone="@{!item.removed &amp;&amp; !item.updated}"
srcCompat="@{item.removed ? R.drawable.ic_delete_md2 : (item.updated ? R.drawable.ic_update_md2 : 0)}"
android:layout_marginStart="@dimen/l1"
android:background="@null"
app:layout_constraintBottom_toBottomOf="@+id/module_version_author"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/module_title"
tools:srcCompat="@drawable/ic_update_md2" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/module_title"
strikeThrough="@{!item.enabled}"
strikeThrough="@{item.removed}"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/l1"
android:layout_marginTop="@dimen/l1"
android:layout_marginEnd="@dimen/l1"
android:layout_marginEnd="@dimen/l_50"
android:text="@{item.item.name}"
android:textAppearance="@style/AppearanceFoundation.Body"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/module_state_icon"
app:layout_constraintEnd_toStartOf="@+id/module_indicator"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="@tools:sample/lorem" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/module_version_author"
strikeThrough="@{!item.enabled}"
strikeThrough="@{item.removed}"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/l1"
android:layout_marginEnd="@dimen/l1"
android:text="@{@string/module_version_author(item.item.version, item.item.author)}"
android:textAppearance="@style/AppearanceFoundation.Caption.Variant"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/module_state_icon"
app:layout_constraintEnd_toEndOf="@+id/module_title"
app:layout_constraintStart_toStartOf="@+id/module_title"
app:layout_constraintTop_toBottomOf="@+id/module_title"
tools:text="v1 by topjohnwu" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/module_indicator"
style="@style/WidgetFoundation.Switch"
isSelected="@{item.enabled &amp;&amp; !Config.coreOnly}"
android:layout_marginEnd="@dimen/l_50"
app:layout_constraintBottom_toBottomOf="@+id/module_version_author"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1"
app:layout_constraintStart_toEndOf="@+id/module_info"
app:layout_constraintTop_toTopOf="@+id/module_title" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/module_description"
gone="@{item.item.description.empty}"
strikeThrough="@{!item.enabled}"
strikeThrough="@{item.removed}"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/l1"
@ -97,6 +110,7 @@
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="@dimen/l1"
android:layout_marginRight="6dp"
android:background="?colorSurfaceVariant"
app:layout_constraintTop_toBottomOf="@+id/module_description" />
@ -130,13 +144,6 @@
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.appcompat.widget.AppCompatImageView
isSelected="@{item.enabled}"
android:layout_width="@dimen/l1"
android:layout_height="@dimen/l1"
android:layout_gravity="right|top"
app:srcCompat="@drawable/ic_card_check" />
</com.google.android.material.card.MaterialCardView>

View File

@ -24,8 +24,7 @@
android:onClick="@{() -> item.toggle(viewModel)}"
android:onLongClick="@{() -> item.toggle()}"
tools:layout_marginBottom="@dimen/l1"
tools:layout_marginEnd="@dimen/l1"
tools:layout_width="200dp">
tools:layout_marginEnd="@dimen/l1">
<LinearLayout
android:layout_width="match_parent"
@ -49,21 +48,8 @@
app:layout_constraintVertical_bias="0"
tools:srcCompat="@drawable/ic_logo" />
<androidx.appcompat.widget.AppCompatImageView
style="@style/WidgetFoundation.Image.Big"
gone="@{item.isEnabled()}"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="@+id/policy_app_icon"
app:layout_constraintEnd_toEndOf="@+id/policy_app_icon"
app:layout_constraintStart_toStartOf="@+id/policy_app_icon"
app:layout_constraintTop_toTopOf="@+id/policy_app_icon"
app:srcCompat="@drawable/ic_off"
app:tint="?colorSurface"
tools:visibility="visible" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/policy_app_name"
strikeThrough="@{!item.enabled}"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_generic"
@ -75,14 +61,13 @@
android:textAppearance="@style/AppearanceFoundation.Body"
android:textIsSelectable="false"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintEnd_toStartOf="@+id/policy_indicator"
app:layout_constraintStart_toEndOf="@+id/policy_app_icon"
app:layout_constraintTop_toTopOf="@+id/policy_app_icon"
tools:text="@string/app_name" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/policy_package_name"
strikeThrough="@{!item.enabled}"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/l1"
@ -100,6 +85,15 @@
app:layout_constraintVertical_bias="0"
tools:text="com.topjohnwu.magisk" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/policy_indicator"
style="@style/WidgetFoundation.Switch"
isSelected="@{item.enabled}"
android:layout_marginEnd="@dimen/l1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
@ -119,7 +113,7 @@
android:id="@+id/policy_notify"
style="@style/WidgetFoundation.Button.Text"
isSelected="@{item.shouldNotify}"
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:minHeight="24dp"
android:onClick="@{() -> item.toggleNotify(viewModel)}"
@ -129,17 +123,27 @@
android:textColor="@color/color_state_primary_transient"
app:icon="@drawable/ic_notifications_md2"
app:iconTint="@color/color_state_primary_transient"
app:layout_constrainedWidth="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/policy_log"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:tint="@color/color_state_primary_transient" />
<View
android:layout_width="1dp"
android:layout_height="0dp"
android:layout_marginTop="@dimen/l_50"
android:layout_marginBottom="@dimen/l_50"
android:background="?colorSurface"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/policy_notify"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.button.MaterialButton
android:id="@+id/policy_log"
style="@style/WidgetFoundation.Button.Text"
isSelected="@{item.shouldLog}"
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:minHeight="24dp"
android:onClick="@{() -> item.toggleLog(viewModel)}"
@ -150,15 +154,26 @@
app:icon="@drawable/ic_bug_md2"
app:iconTint="@color/color_state_primary_transient"
app:layout_constrainedWidth="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/policy_notify"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/policy_delete"
app:layout_constraintStart_toEndOf="@+id/policy_notify"
app:layout_constraintTop_toTopOf="parent"
app:tint="@color/color_state_primary_transient" />
<View
android:layout_width="1dp"
android:layout_height="0dp"
android:layout_marginTop="@dimen/l_50"
android:layout_marginBottom="@dimen/l_50"
android:background="?colorSurface"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/policy_log"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.button.MaterialButton
android:id="@+id/policy_delete"
style="@style/WidgetFoundation.Button.Text"
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:minHeight="24dp"
android:onClick="@{() -> viewModel.deletePressed(item)}"
@ -170,21 +185,14 @@
app:iconTint="?colorError"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/policy_log"
app:layout_constraintStart_toEndOf="@+id/policy_log"
app:layout_constraintTop_toTopOf="parent"
app:rippleColor="?colorError" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
<androidx.appcompat.widget.AppCompatImageView
isSelected="@{item.enabled}"
android:layout_width="@dimen/l1"
android:layout_height="@dimen/l1"
android:layout_gravity="right|top"
app:srcCompat="@drawable/ic_card_check" />
</com.google.android.material.card.MaterialCardView>
</layout>

View File

@ -42,16 +42,14 @@
app:srcCompat="@{item.icon}"
tools:srcCompat="@drawable/ic_fingerprint" />
<com.google.android.material.switchmaterial.SwitchMaterial
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/toggle_indicator"
style="@style/WidgetFoundation.Switch"
isEnabled="@{item.enabled}"
onTouch="@{(view, event) -> item.onTouched(view, callback, event)}"
isSelected="@{item.value}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/l_25"
android:checked="@{item.value}"
android:text=""
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

View File

@ -1,13 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorSecondary">#FFC107</color>
<color name="colorSecondaryDark">#AD8305</color>
<color name="colorText">#FFFFFF</color>
<color name="colorTextInactive">#ADADAD</color>
<color name="colorTextInverse">#1D1D1D</color>
<color name="colorTextTinted">#FFFFFF</color>
<color name="colorCardStrokeInverse">#2AE4E4E4</color>
<color name="colorOverlay">#1AFFFFFF</color>
</resources>

View File

@ -1,8 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="su_request_background">#e0e0e0</color>
<!-- Card colors -->
<color name="card_background_color_dark">#ff424242</color>
<color name="card_background_color_light">#ffffffff</color>
<color name="colorOverlay">#0D000000</color>
</resources>

View File

@ -199,8 +199,11 @@
</style>
<style name="WidgetFoundation.Switch" parent="Widget.AppCompat.CompoundButton.Switch">
<item name="thumbTint">@color/color_checkbox_primary</item>
<style name="WidgetFoundation.Switch">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:background">@drawable/bg_checkbox</item>
<item name="srcCompat">@drawable/ic_checkbox</item>
</style>
</resources>