use material switches

Daniel Gultsch created

Change summary

src/main/java/eu/siacs/conversations/ui/adapter/AccountAdapter.java |  4 
src/main/res/layout/item_account.xml                                | 20 
src/main/res/layout/preference_material_switch.xml                  |  8 
src/main/res/values-night/themes.xml                                |  1 
src/main/res/values/themes.xml                                      |  9 
5 files changed, 30 insertions(+), 12 deletions(-)

Detailed changes

src/main/java/eu/siacs/conversations/ui/adapter/AccountAdapter.java 🔗

@@ -85,8 +85,8 @@ public class AccountAdapter extends ArrayAdapter<Account> {
         }
         viewHolder.binding.tglAccountStatus.setOnCheckedChangeListener(
                 (compoundButton, b) -> {
-                    if (b == isDisabled && activity instanceof OnTglAccountState) {
-                        ((OnTglAccountState) activity).onClickTglAccountState(account, b);
+                    if (b == isDisabled && activity instanceof OnTglAccountState tglAccountState) {
+                        tglAccountState.onClickTglAccountState(account, b);
                     }
                 });
         return view;

src/main/res/layout/item_account.xml 🔗

@@ -8,8 +8,8 @@
         android:layout_height="wrap_content"
         android:background="?selectableItemBackground"
         android:paddingStart="8dp"
-        android:paddingBottom="8dp"
-        android:paddingTop="8dp">
+        android:paddingTop="8dp"
+        android:paddingBottom="8dp">
 
         <com.makeramen.roundedimageview.RoundedImageView
             android:id="@+id/account_image"
@@ -23,19 +23,19 @@
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
             android:layout_centerVertical="true"
-            android:layout_toEndOf="@+id/account_image"
-            android:orientation="vertical"
             android:layout_marginStart="@dimen/avatar_item_distance"
-            android:layout_toStartOf="@+id/tgl_account_status">
+            android:layout_toStartOf="@+id/tgl_account_status"
+            android:layout_toEndOf="@+id/account_image"
+            android:orientation="vertical">
 
             <TextView
-                tools:text="juliet@example.com"
                 android:id="@+id/account_jid"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:scrollHorizontally="false"
                 android:singleLine="true"
-                android:textAppearance="?textAppearanceBodyLarge" />
+                android:textAppearance="?textAppearanceBodyLarge"
+                tools:text="juliet@example.com" />
 
             <TextView
                 android:id="@+id/account_status"
@@ -45,14 +45,14 @@
                 android:textAppearance="?textAppearanceBodyMedium" />
         </LinearLayout>
 
-        <androidx.appcompat.widget.SwitchCompat
+        <com.google.android.material.materialswitch.MaterialSwitch
             android:id="@+id/tgl_account_status"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_alignParentEnd="true"
             android:layout_centerVertical="true"
-            android:padding="16dp"
-            android:focusable="false" />
+            android:focusable="false"
+            android:padding="16dp" />
 
     </RelativeLayout>
 </layout>

src/main/res/layout/preference_material_switch.xml 🔗

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<com.google.android.material.materialswitch.MaterialSwitch xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/switchWidget"
+    android:layout_width="wrap_content"
+    android:layout_height="wrap_content"
+    android:background="@null"
+    android:clickable="false"
+    android:focusable="false" />

src/main/res/values-night/themes.xml 🔗

@@ -28,6 +28,7 @@
         <item name="colorOnSurfaceInverse">@color/md_theme_dark_inverseOnSurface</item>
         <item name="colorSurfaceInverse">@color/md_theme_dark_inverseSurface</item>
         <item name="colorPrimaryInverse">@color/md_theme_dark_inversePrimary</item>
+        <item name="preferenceTheme">@style/MaterialPreferenceThemeOverlay</item>
     </style>
 
     <style name="Theme.Conversations3.SplashScreen" parent="@style/Theme.Conversations3">

src/main/res/values/themes.xml 🔗

@@ -50,5 +50,14 @@
         <item name="colorOnSurfaceInverse">@color/md_theme_light_inverseOnSurface</item>
         <item name="colorSurfaceInverse">@color/md_theme_light_inverseSurface</item>
         <item name="colorPrimaryInverse">@color/md_theme_light_inversePrimary</item>
+        <item name="preferenceTheme">@style/MaterialPreferenceThemeOverlay</item>
+    </style>
+
+    <style name="MaterialPreferenceThemeOverlay" parent="@style/PreferenceThemeOverlay">
+        <item name="switchPreferenceCompatStyle">@style/MaterialSwitchPreference</item>
+    </style>
+
+    <style name="MaterialSwitchPreference" parent="@style/Preference.SwitchPreferenceCompat.Material">
+        <item name="widgetLayout">@layout/preference_material_switch</item>
     </style>
 </resources>