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

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <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" /> <item android:color="?attr/colorPrimary" android:state_checked="true" />
</selector> </selector>

View File

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

View File

@ -1,27 +1,14 @@
<?xml version="1.0" encoding="utf-8"?> <?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_width="match_parent"
android:layout_height="48dp" android:layout_height="wrap_content">
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" />
<com.google.android.material.switchmaterial.SwitchMaterial <com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/enabled" android:id="@+id/enabled"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginHorizontal="@dimen/text_margin"
android:clickable="false" android:clickable="false"
android:paddingStart="12dp" android:singleLine="true"
android:paddingEnd="12dp" /> android:textSize="15sp" />
</FrameLayout>
</LinearLayout>