From d80c7ced3c410b52c38a39775772398739d85990 Mon Sep 17 00:00:00 2001
From: Andrew Gunnerson <accounts+github@chiller3.com>
Date: Sun, 28 Jul 2024 21:31:52 -0400
Subject: [PATCH] Use Material 3 switches for switch preferences

We have to do this explicitly since the Material 3 library doesn't have
any magic for automatically theming the switches in androidx.preference.

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
---
 .../main/res/layout/material_switch_preference.xml | 14 ++++++++++++++
 app/src/main/res/values/styles.xml                 | 10 ++++++++++
 app/src/main/res/values/themes.xml                 |  1 +
 3 files changed, 25 insertions(+)
 create mode 100644 app/src/main/res/layout/material_switch_preference.xml
 create mode 100644 app/src/main/res/values/styles.xml

diff --git a/app/src/main/res/layout/material_switch_preference.xml b/app/src/main/res/layout/material_switch_preference.xml
new file mode 100644
index 000000000..49d8bc725
--- /dev/null
+++ b/app/src/main/res/layout/material_switch_preference.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+    SPDX-FileCopyrightText: 2024 Andrew Gunnerson
+    SPDX-License-Identifier: GPL-3.0-only
+-->
+<!-- The ID must match the androidx preference library. -->
+<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:focusable="false"
+    android:clickable="false"
+    android:background="@null" />
diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml
new file mode 100644
index 000000000..b07ef0e90
--- /dev/null
+++ b/app/src/main/res/values/styles.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+    SPDX-FileCopyrightText: 2024 Andrew Gunnerson
+    SPDX-License-Identifier: GPL-3.0-only
+-->
+<resources>
+    <style name="SwitchPreferenceCompat.Material3" parent="Preference.SwitchPreferenceCompat.Material">
+        <item name="android:widgetLayout">@layout/material_switch_preference</item>
+    </style>
+</resources>
diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml
index b1f4645b5..495af916c 100644
--- a/app/src/main/res/values/themes.xml
+++ b/app/src/main/res/values/themes.xml
@@ -4,5 +4,6 @@
         <item name="android:statusBarColor">@android:color/transparent</item>
         <item name="android:windowLightStatusBar">?attr/isLightTheme</item>
         <item name="windowActionModeOverlay">true</item>
+        <item name="switchPreferenceCompatStyle">@style/SwitchPreferenceCompat.Material3</item>
     </style>
 </resources>