Support material switch

This commit is contained in:
Mygod
2022-05-31 21:19:23 -04:00
parent a11e8dea9c
commit 5f76575866
8 changed files with 52 additions and 19 deletions

View File

@@ -72,7 +72,6 @@ dependencies {
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.1.5") coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.1.5")
kapt("androidx.room:room-compiler:$roomVersion") kapt("androidx.room:room-compiler:$roomVersion")
implementation(kotlin("stdlib-jdk8")) implementation(kotlin("stdlib-jdk8"))
implementation("androidx.appcompat:appcompat:1.4.1") // https://issuetracker.google.com/issues/151603528
implementation("androidx.browser:browser:1.4.0") implementation("androidx.browser:browser:1.4.0")
implementation("androidx.core:core-ktx:1.8.0-rc02") implementation("androidx.core:core-ktx:1.8.0-rc02")
implementation("androidx.fragment:fragment-ktx:1.5.0-rc01") implementation("androidx.fragment:fragment-ktx:1.5.0-rc01")
@@ -83,7 +82,7 @@ dependencies {
implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.1.0") implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.1.0")
implementation("com.android.billingclient:billing-ktx:5.0.0") implementation("com.android.billingclient:billing-ktx:5.0.0")
implementation("com.google.android.gms:play-services-oss-licenses:17.0.0") implementation("com.google.android.gms:play-services-oss-licenses:17.0.0")
implementation("com.google.android.material:material:1.6.1") implementation("com.google.android.material:material:1.7.0-alpha02")
implementation("com.google.firebase:firebase-analytics-ktx:21.0.0") implementation("com.google.firebase:firebase-analytics-ktx:21.0.0")
implementation("com.google.firebase:firebase-crashlytics:18.2.11") implementation("com.google.firebase:firebase-crashlytics:18.2.11")
implementation("com.google.zxing:core:3.5.0") implementation("com.google.zxing:core:3.5.0")

View File

@@ -7,7 +7,7 @@ import androidx.core.content.FileProvider
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import androidx.preference.Preference import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreference import androidx.preference.TwoStatePreference
import be.mygod.vpnhotspot.App.Companion.app import be.mygod.vpnhotspot.App.Companion.app
import be.mygod.vpnhotspot.net.TetherOffloadManager import be.mygod.vpnhotspot.net.TetherOffloadManager
import be.mygod.vpnhotspot.net.monitor.FallbackUpstreamMonitor import be.mygod.vpnhotspot.net.monitor.FallbackUpstreamMonitor
@@ -46,7 +46,7 @@ class SettingsPreferenceFragment : PreferenceFragmentCompat() {
addPreferencesFromResource(R.xml.pref_settings) addPreferencesFromResource(R.xml.pref_settings)
SummaryFallbackProvider(findPreference(UpstreamMonitor.KEY)!!) SummaryFallbackProvider(findPreference(UpstreamMonitor.KEY)!!)
SummaryFallbackProvider(findPreference(FallbackUpstreamMonitor.KEY)!!) SummaryFallbackProvider(findPreference(FallbackUpstreamMonitor.KEY)!!)
findPreference<SwitchPreference>("system.enableTetherOffload")!!.apply { findPreference<TwoStatePreference>("system.enableTetherOffload")!!.apply {
if (TetherOffloadManager.supported) { if (TetherOffloadManager.supported) {
isChecked = TetherOffloadManager.enabled isChecked = TetherOffloadManager.enabled
setOnPreferenceChangeListener { _, newValue -> setOnPreferenceChangeListener { _, newValue ->
@@ -66,7 +66,7 @@ class SettingsPreferenceFragment : PreferenceFragmentCompat() {
} }
} else parent!!.removePreference(this) } else parent!!.removePreference(this)
} }
findPreference<SwitchPreference>(BootReceiver.KEY)!!.setOnPreferenceChangeListener { _, value -> findPreference<TwoStatePreference>(BootReceiver.KEY)!!.setOnPreferenceChangeListener { _, value ->
BootReceiver.onUserSettingUpdated(value as Boolean) BootReceiver.onUserSettingUpdated(value as Boolean)
true true
} }

View File

@@ -97,7 +97,7 @@
android:maxLength="63" android:maxLength="63"
android:imeOptions="flagForceAscii" /> android:imeOptions="flagForceAscii" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
<Switch <com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/auto_shutdown" android:id="@+id/auto_shutdown"
style="@style/wifi_item_label" style="@style/wifi_item_label"
android:layout_width="match_parent" android:layout_width="match_parent"
@@ -192,7 +192,7 @@
android:inputType="number" android:inputType="number"
android:maxLength="10" /> android:maxLength="10" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
<Switch <com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/client_user_control" android:id="@+id/client_user_control"
style="@style/wifi_item_label" style="@style/wifi_item_label"
android:layout_width="match_parent" android:layout_width="match_parent"
@@ -261,7 +261,7 @@
android:inputType="textNoSuggestions" android:inputType="textNoSuggestions"
android:maxLength="17" /> android:maxLength="17" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
<Switch <com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/mac_randomization" android:id="@+id/mac_randomization"
style="@style/wifi_item_label" style="@style/wifi_item_label"
android:layout_width="match_parent" android:layout_width="match_parent"
@@ -269,7 +269,7 @@
android:layout_marginTop="8dip" android:layout_marginTop="8dip"
android:minHeight="@dimen/touch_target_min" android:minHeight="@dimen/touch_target_min"
android:text="@string/wifi_mac_randomization" /> android:text="@string/wifi_mac_randomization" />
<Switch <com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/hidden_ssid" android:id="@+id/hidden_ssid"
style="@style/wifi_item_label" style="@style/wifi_item_label"
android:layout_width="match_parent" android:layout_width="match_parent"
@@ -277,7 +277,7 @@
android:layout_marginTop="8dip" android:layout_marginTop="8dip"
android:minHeight="@dimen/touch_target_min" android:minHeight="@dimen/touch_target_min"
android:text="@string/wifi_hidden_network" /> android:text="@string/wifi_hidden_network" />
<Switch <com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/ieee_80211ax" android:id="@+id/ieee_80211ax"
style="@style/wifi_item_label" style="@style/wifi_item_label"
android:layout_width="match_parent" android:layout_width="match_parent"
@@ -285,7 +285,7 @@
android:layout_marginTop="8dip" android:layout_marginTop="8dip"
android:minHeight="@dimen/touch_target_min" android:minHeight="@dimen/touch_target_min"
android:text="@string/wifi_ieee_80211ax" /> android:text="@string/wifi_ieee_80211ax" />
<Switch <com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/bridged_mode_opportunistic_shutdown" android:id="@+id/bridged_mode_opportunistic_shutdown"
style="@style/wifi_item_label" style="@style/wifi_item_label"
android:layout_width="match_parent" android:layout_width="match_parent"
@@ -293,7 +293,7 @@
android:layout_marginTop="8dip" android:layout_marginTop="8dip"
android:minHeight="@dimen/touch_target_min" android:minHeight="@dimen/touch_target_min"
android:text="@string/wifi_bridged_mode_opportunistic_shutdown" /> android:text="@string/wifi_bridged_mode_opportunistic_shutdown" />
<Switch <com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/user_config" android:id="@+id/user_config"
style="@style/wifi_item_label" style="@style/wifi_item_label"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@@ -50,7 +50,7 @@
tools:text="192.168.43.1/24\n01:23:45:ab:cd:ef"/> tools:text="192.168.43.1/24\n01:23:45:ab:cd:ef"/>
</LinearLayout> </LinearLayout>
<Switch <com.google.android.material.materialswitch.MaterialSwitch
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"

View File

@@ -54,7 +54,7 @@
tools:text="192.168.43.1/24\n01:23:45:ab:cd:ef"/> tools:text="192.168.43.1/24\n01:23:45:ab:cd:ef"/>
</LinearLayout> </LinearLayout>
<Switch <com.google.android.material.materialswitch.MaterialSwitch
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"

View File

@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2015 The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<!-- https://android.googlesource.com/platform/frameworks/support/+/3c79906/preference/preference/res/layout/preference_widget_switch_compat.xml -->
<!-- Layout used by SwitchPreference for the switch widget style. This is inflated
inside android.R.layout.preference. -->
<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"/>

View File

@@ -7,6 +7,9 @@
<item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorSecondary">@color/colorSecondary</item> <item name="colorSecondary">@color/colorSecondary</item>
<!-- TODO: https://github.com/material-components/material-components-android/issues/2725 -->
<item name="materialSwitchStyle">@style/Widget.Material3.CompoundButton.MaterialSwitch</item>
<item name="switchPreferenceCompatStyle">@style/AppTheme.Preference.MaterialSwitchPreference</item>
<!-- Remove ActionBar but keep styles and themes --> <!-- Remove ActionBar but keep styles and themes -->
<item name="windowActionBar">false</item> <item name="windowActionBar">false</item>
@@ -16,6 +19,9 @@
<item name="windowActionBar">true</item> <item name="windowActionBar">true</item>
<item name="windowNoTitle">false</item> <item name="windowNoTitle">false</item>
</style> </style>
<style name="AppTheme.Preference.MaterialSwitchPreference" parent="Preference.SwitchPreferenceCompat.Material">
<item name="android:widgetLayout">@layout/preference_widget_material_switch</item>
</style>
<!-- https://android.googlesource.com/platform/packages/apps/Settings/+/7efcc35/res/values/styles.xml --> <!-- https://android.googlesource.com/platform/packages/apps/Settings/+/7efcc35/res/values/styles.xml -->
<style name="wifi_item"> <style name="wifi_item">

View File

@@ -31,19 +31,19 @@
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory <PreferenceCategory
app:title="@string/settings_downstream"> app:title="@string/settings_downstream">
<SwitchPreference <SwitchPreferenceCompat
app:key="service.disableIpv6" app:key="service.disableIpv6"
app:icon="@drawable/ic_image_looks_6" app:icon="@drawable/ic_image_looks_6"
app:title="@string/settings_service_disable_ipv6" app:title="@string/settings_service_disable_ipv6"
app:summary="@string/settings_service_disable_ipv6_summary" app:summary="@string/settings_service_disable_ipv6_summary"
app:defaultValue="true"/> app:defaultValue="true"/>
<SwitchPreference <SwitchPreferenceCompat
app:key="system.enableTetherOffload" app:key="system.enableTetherOffload"
app:persistent="false" app:persistent="false"
app:icon="@drawable/ic_device_battery_charging_full" app:icon="@drawable/ic_device_battery_charging_full"
app:title="@string/settings_system_tether_offload" app:title="@string/settings_system_tether_offload"
app:summary="@string/settings_system_tether_offload_summary"/> app:summary="@string/settings_system_tether_offload_summary"/>
<SwitchPreference <SwitchPreferenceCompat
app:key="service.dhcpWorkaround" app:key="service.dhcpWorkaround"
app:icon="@drawable/ic_action_build" app:icon="@drawable/ic_action_build"
app:title="@string/settings_service_dhcp_workaround" app:title="@string/settings_service_dhcp_workaround"
@@ -58,12 +58,12 @@
app:entryValues="@array/settings_service_wifi_lock_values" app:entryValues="@array/settings_service_wifi_lock_values"
app:title="@string/settings_service_wifi_lock" app:title="@string/settings_service_wifi_lock"
app:useSimpleSummaryProvider="true"/> app:useSimpleSummaryProvider="true"/>
<SwitchPreference <SwitchPreferenceCompat
app:key="service.autoStart" app:key="service.autoStart"
app:icon="@drawable/ic_action_autorenew" app:icon="@drawable/ic_action_autorenew"
app:title="@string/settings_service_auto_start" app:title="@string/settings_service_auto_start"
app:summary="@string/settings_service_auto_start_summary"/> app:summary="@string/settings_service_auto_start_summary"/>
<SwitchPreference <SwitchPreferenceCompat
app:key="service.repeater.safeMode" app:key="service.repeater.safeMode"
app:icon="@drawable/ic_alert_warning" app:icon="@drawable/ic_alert_warning"
app:title="@string/settings_service_repeater_safe_mode" app:title="@string/settings_service_repeater_safe_mode"