Replace preference checkboxes with material switches

This commit is contained in:
lynxnb 2023-03-07 12:34:24 +01:00 committed by Niccolò Betto
parent ee2716403e
commit b12a2bdc3e
13 changed files with 68 additions and 32 deletions

View File

@ -29,6 +29,7 @@ class ControllerCheckBoxViewItem(var title : String, var summary : String, var c
binding.checkbox.isChecked = checked
binding.root.setOnClickListener {
checked = !checked
binding.checkbox.isChecked = checked
onCheckedChange.invoke(this, position)
}
}

View File

@ -13,6 +13,7 @@ import android.view.KeyEvent
import android.view.ViewTreeObserver
import androidx.appcompat.app.AppCompatActivity
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.content.res.use
import androidx.core.view.WindowCompat
import androidx.core.view.marginTop
import androidx.recyclerview.widget.DividerItemDecoration
@ -91,17 +92,14 @@ class ControllerActivity : AppCompatActivity() {
items.add(ControllerCheckBoxViewItem(getString(R.string.osc_enable), oscSummary.invoke(appSettings.onScreenControl), appSettings.onScreenControl) { item, position ->
item.summary = oscSummary.invoke(item.checked)
appSettings.onScreenControl = item.checked
adapter.notifyItemChanged(position)
})
items.add(ControllerCheckBoxViewItem(getString(R.string.osc_feedback), getString(R.string.osc_feedback_description), appSettings.onScreenControlFeedback) { item, position ->
appSettings.onScreenControlFeedback = item.checked
adapter.notifyItemChanged(position)
})
items.add(ControllerCheckBoxViewItem(getString(R.string.osc_recenter_sticks), "", appSettings.onScreenControlRecenterSticks) { item, position ->
appSettings.onScreenControlRecenterSticks = item.checked
adapter.notifyItemChanged(position)
})
items.add(ControllerViewItem(content = getString(R.string.osc_edit), onClick = {

View File

@ -16,7 +16,7 @@ import emu.skyline.di.getSettings
*/
class RefreshCheckBoxPreference @JvmOverloads constructor(context : Context, attrs : AttributeSet? = null, defStyleAttr : Int = R.attr.checkBoxPreferenceStyle) : CheckBoxPreference(context, attrs, defStyleAttr) {
override fun onClick() {
context?.getSettings()?.refreshRequired = true
super.onClick()
context.getSettings().refreshRequired = true
}
}

View File

@ -0,0 +1,22 @@
/*
* SPDX-License-Identifier: MPL-2.0
* Copyright © 2023 Skyline Team and Contributors (https://github.com/skyline-emu/)
*/
package emu.skyline.preference
import android.content.Context
import android.util.AttributeSet
import androidx.preference.R
import androidx.preference.SwitchPreferenceCompat
import emu.skyline.di.getSettings
/**
* This preference is used with switches that need to refresh the main activity when changed
*/
class RefreshSwitchPreferenceCompat @JvmOverloads constructor(context : Context, attrs : AttributeSet? = null, defStyleAttr : Int = R.attr.switchPreferenceCompatStyle) : SwitchPreferenceCompat(context, attrs, defStyleAttr) {
override fun onClick() {
super.onClick()
context.getSettings().refreshRequired = true
}
}

View File

@ -56,8 +56,8 @@ class GameSettingsFragment : PreferenceFragmentCompat() {
).forEach { it?.dependency = "use_custom_settings" }
// Uncheck `disable_frame_throttling` if `force_triple_buffering` gets disabled
val disableFrameThrottlingPref = findPreference<CheckBoxPreference>("disable_frame_throttling")!!
findPreference<CheckBoxPreference>("force_triple_buffering")?.setOnPreferenceChangeListener { _, newValue ->
val disableFrameThrottlingPref = findPreference<TwoStatePreference>("disable_frame_throttling")!!
findPreference<TwoStatePreference>("force_triple_buffering")?.setOnPreferenceChangeListener { _, newValue ->
if (newValue == false)
disableFrameThrottlingPref.isChecked = false
true
@ -69,7 +69,7 @@ class GameSettingsFragment : PreferenceFragmentCompat() {
findPreference<Preference>("validation_layer")?.isVisible = true
if (!GpuDriverHelper.supportsForceMaxGpuClocks()) {
val forceMaxGpuClocksPref = findPreference<CheckBoxPreference>("force_max_gpu_clocks")!!
val forceMaxGpuClocksPref = findPreference<TwoStatePreference>("force_max_gpu_clocks")!!
forceMaxGpuClocksPref.isSelectable = false
forceMaxGpuClocksPref.isChecked = false
forceMaxGpuClocksPref.summary = context!!.getString(R.string.force_max_gpu_clocks_desc_unsupported)

View File

@ -7,10 +7,10 @@ package emu.skyline.settings
import android.os.Bundle
import android.view.View
import androidx.preference.CheckBoxPreference
import androidx.preference.Preference
import androidx.preference.PreferenceCategory
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.TwoStatePreference
import emu.skyline.BuildConfig
import emu.skyline.R
import emu.skyline.preference.IntegerListPreference
@ -41,8 +41,8 @@ class GlobalSettingsFragment : PreferenceFragmentCompat() {
addPreferencesFromResource(R.xml.credits_preferences)
// Uncheck `disable_frame_throttling` if `force_triple_buffering` gets disabled
val disableFrameThrottlingPref = findPreference<CheckBoxPreference>("disable_frame_throttling")!!
findPreference<CheckBoxPreference>("force_triple_buffering")?.setOnPreferenceChangeListener { _, newValue ->
val disableFrameThrottlingPref = findPreference<TwoStatePreference>("disable_frame_throttling")!!
findPreference<TwoStatePreference>("force_triple_buffering")?.setOnPreferenceChangeListener { _, newValue ->
if (newValue == false)
disableFrameThrottlingPref.isChecked = false
true
@ -54,7 +54,7 @@ class GlobalSettingsFragment : PreferenceFragmentCompat() {
findPreference<Preference>("validation_layer")?.isVisible = true
if (!GpuDriverHelper.supportsForceMaxGpuClocks()) {
val forceMaxGpuClocksPref = findPreference<CheckBoxPreference>("force_max_gpu_clocks")!!
val forceMaxGpuClocksPref = findPreference<TwoStatePreference>("force_max_gpu_clocks")!!
forceMaxGpuClocksPref.isSelectable = false
forceMaxGpuClocksPref.isChecked = false
forceMaxGpuClocksPref.summary = context!!.getString(R.string.force_max_gpu_clocks_desc_unsupported)

View File

@ -38,12 +38,13 @@
tools:text="Summary" />
</LinearLayout>
<com.google.android.material.checkbox.MaterialCheckBox
<com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:clickable="false"
android:gravity="end|center_vertical"
android:focusable="false"
android:paddingStart="16dp"
android:paddingEnd="0dp" />
</LinearLayout>

View File

@ -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" />

View File

@ -11,4 +11,9 @@
<style name="ChipChoice" parent="Widget.Material3.Chip.Filter.Elevated">
<item name="android:textAllCaps">true</item>
</style>
<!-- Override the default switch preference style to use the MD3 switch -->
<style name="App.Preference.SwitchPreferenceCompat.Material3" parent="Preference.SwitchPreferenceCompat.Material">
<item name="android:widgetLayout">@layout/preference_widget_material_switch</item>
</style>
</resources>

View File

@ -39,6 +39,8 @@
<item name="alertDialogTheme">@style/ThemeOverlay.App.MaterialAlertDialog</item>
<!-- Workaround for AndroidX PreferenceScreen since it uses colorAccent as categories text color -->
<item name="colorAccent">?attr/colorPrimary</item>
<!-- Override the default switch preference style to use the MD3 switch -->
<item name="switchPreferenceCompatStyle">@style/App.Preference.SwitchPreferenceCompat.Material3</item>
</style>
<style name="AppTheme" parent="BaseAppTheme">

View File

@ -45,14 +45,13 @@
app:refreshRequired="true"
app:title="@string/sort_apps_by"
app:useSimpleSummaryProvider="true" />
<emu.skyline.preference.RefreshCheckBoxPreference
<emu.skyline.preference.RefreshSwitchPreferenceCompat
android:defaultValue="true"
android:summaryOff="@string/group_by_format_desc_off"
android:summaryOn="@string/group_by_format_desc_on"
app:key="group_by_format"
app:refreshRequired="true"
app:title="@string/group_by_format" />
<CheckBoxPreference
<SwitchPreferenceCompat
android:defaultValue="false"
android:summaryOff="@string/select_action_desc_off"
android:summaryOn="@string/select_action_desc_on"

View File

@ -3,7 +3,7 @@
<PreferenceCategory
android:key="category_game"
android:title="@string/game">
<CheckBoxPreference
<SwitchPreferenceCompat
android:defaultValue="false"
android:summaryOff="@string/use_custom_settings_desc_off"
android:summaryOn="@string/use_custom_settings_desc_on"

View File

@ -3,7 +3,7 @@
<PreferenceCategory
android:key="category_system"
android:title="@string/system">
<CheckBoxPreference
<SwitchPreferenceCompat
android:defaultValue="true"
android:summaryOff="@string/handheld_enabled"
android:summaryOn="@string/docked_enabled"
@ -36,13 +36,13 @@
<PreferenceCategory
android:key="category_presentation"
android:title="@string/display">
<CheckBoxPreference
<SwitchPreferenceCompat
android:defaultValue="false"
android:summaryOff="@string/perf_stats_desc_off"
android:summaryOn="@string/perf_stats_desc_on"
app:key="perf_stats"
app:title="@string/perf_stats" />
<CheckBoxPreference
<SwitchPreferenceCompat
android:defaultValue="false"
android:summaryOff="@string/max_refresh_rate_disabled"
android:summaryOn="@string/max_refresh_rate_enabled"
@ -61,7 +61,7 @@
app:key="aspect_ratio"
app:title="@string/aspect_ratio"
app:useSimpleSummaryProvider="true" />
<CheckBoxPreference
<SwitchPreferenceCompat
android:defaultValue="false"
android:summaryOff="@string/respect_display_cutout_disabled"
android:summaryOn="@string/respect_display_cutout_enabled"
@ -71,7 +71,7 @@
<PreferenceCategory
android:key="category_audio"
android:title="@string/audio">
<CheckBoxPreference
<SwitchPreferenceCompat
android:defaultValue="false"
android:summaryOff="@string/disable_audio_output_disabled"
android:summaryOn="@string/disable_audio_output_enabled"
@ -84,13 +84,13 @@
<emu.skyline.preference.GpuDriverPreference
app:key="gpu_driver"
app:title="@string/gpu_driver_config" />
<CheckBoxPreference
<SwitchPreferenceCompat
android:defaultValue="true"
android:summaryOff="@string/triple_buffering_disabled"
android:summaryOn="@string/triple_buffering_enabled"
app:key="force_triple_buffering"
app:title="@string/force_triple_buffering" />
<CheckBoxPreference
<SwitchPreferenceCompat
android:defaultValue="false"
android:dependency="force_triple_buffering"
android:summaryOff="@string/disable_frame_throttling_disabled"
@ -113,22 +113,22 @@
app:key="executor_flush_threshold"
app:showSeekBarValue="true"
app:title="@string/executor_flush_threshold" />
<CheckBoxPreference
<SwitchPreferenceCompat
android:defaultValue="false"
android:summary="@string/use_direct_memory_import_desc"
app:key="use_direct_memory_import"
app:title="@string/use_direct_memory_import" />
<CheckBoxPreference
<SwitchPreferenceCompat
android:defaultValue="false"
android:summary="@string/force_max_gpu_clocks_desc"
app:key="force_max_gpu_clocks"
app:title="@string/force_max_gpu_clocks" />
<CheckBoxPreference
<SwitchPreferenceCompat
android:defaultValue="false"
android:summary="@string/free_guest_texture_memory_desc"
app:key="free_guest_texture_memory"
app:title="@string/free_guest_texture_memory" />
<CheckBoxPreference
<SwitchPreferenceCompat
android:defaultValue="false"
android:summaryOff="@string/shader_cache_enabled"
android:summaryOn="@string/shader_cache_disabled"
@ -138,20 +138,20 @@
<PreferenceCategory
android:key="category_hacks"
android:title="@string/hacks">
<CheckBoxPreference
<SwitchPreferenceCompat
android:defaultValue="false"
android:summaryOff="@string/enable_fast_gpu_readback_disabled"
android:summaryOn="@string/enable_fast_gpu_readback_enabled"
app:key="enable_fast_gpu_readback_hack"
app:title="@string/enable_fast_gpu_readback" />
<CheckBoxPreference
<SwitchPreferenceCompat
android:defaultValue="false"
android:dependency="enable_fast_gpu_readback_hack"
android:summaryOff="@string/enable_fast_readback_writes_disabled"
android:summaryOn="@string/enable_fast_readback_writes_enabled"
app:key="enable_fast_readback_writes"
app:title="@string/enable_fast_readback_writes" />
<CheckBoxPreference
<SwitchPreferenceCompat
android:defaultValue="false"
android:summaryOff="@string/disable_subgroup_shuffle_disabled"
android:summaryOn="@string/disable_subgroup_shuffle_enabled"
@ -167,7 +167,7 @@
app:key="log_level"
app:title="@string/log_level"
app:useSimpleSummaryProvider="true" />
<CheckBoxPreference
<SwitchPreferenceCompat
android:defaultValue="false"
android:summaryOff="@string/validation_layer_disabled"
android:summaryOn="@string/validation_layer_enabled"