Improve: Switch Themeing and usage

This commit is contained in:
LooKeR 2021-10-19 16:50:44 +05:30
parent e667e0a06a
commit 4143c3330f
4 changed files with 12 additions and 26 deletions

View File

@ -334,11 +334,10 @@ class ProductAdapter(private val callbacks: Callbacks, private val columns: Int)
}
private class SwitchViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val title = itemView.findViewById<TextView>(R.id.title)!!
val enabled = itemView.findViewById<SwitchMaterial>(R.id.enabled)!!
val statefulViews: Sequence<View>
get() = sequenceOf(itemView, title, enabled)
get() = sequenceOf(itemView, enabled)
}
private class SectionViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
@ -1200,7 +1199,6 @@ class ProductAdapter(private val callbacks: Callbacks, private val columns: Int)
ViewType.SWITCH -> {
holder as SwitchViewHolder
item as Item.SwitchItem
holder.title.setText(item.switchType.titleResId)
val (checked, enabled) = when (item.switchType) {
SwitchType.IGNORE_ALL_UPDATES -> {
val productPreference = ProductPreferences[item.packageName]
@ -1214,6 +1212,7 @@ class ProductAdapter(private val callbacks: Callbacks, private val columns: Int)
)
}
}
holder.enabled.setText(item.switchType.titleResId)
holder.enabled.isChecked = checked
holder.statefulViews.forEach { it.isEnabled = enabled }
}

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:alpha="0.7" android:color="?attr/colorPrimary" android:state_checked="false" />
<item android:color="?attr/colorSurface" android:state_checked="false" />
<item android:color="?attr/colorPrimary" android:state_checked="true" />
</selector>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:alpha="0.3" android:color="?attr/colorPrimary" android:state_checked="false" />
<item android:alpha="1" android:color="?attr/colorPrimary" android:state_checked="true" />
<item android:alpha="0.7" android:color="?attr/colorSurface" android:state_checked="false" />
<item android:color="?attr/colorPrimary" android:state_checked="true" />
</selector>

View File

@ -1,27 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="?android:attr/selectableItemBackground"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_weight="1"
android:singleLine="true"
android:textColor="?android:attr/textColor"
android:textSize="16sp" />
android:layout_height="wrap_content">
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/enabled"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginHorizontal="@dimen/text_margin"
android:clickable="false"
android:paddingStart="12dp"
android:paddingEnd="12dp" />
</LinearLayout>
android:singleLine="true"
android:textSize="15sp" />
</FrameLayout>