yuzu-emu
/
yuzu-mainline
Archived
1
0
Fork 0

android: Trim settings enums and items

Take advantage of the new settings interface to reduce the amount of code we need for each setting item. Additionally make all settings items non-null to improve brevity.
This commit is contained in:
Charles Lombardo 2023-08-21 21:48:21 -04:00
parent 6c8f2b355a
commit f5e6b12c74
16 changed files with 133 additions and 321 deletions

View File

@ -15,5 +15,5 @@ interface AbstractSetting {
val isRuntimeModifiable: Boolean
get() = NativeConfig.getIsRuntimeModifiable(key!!)
fun reset() = run { }
fun reset()
}

View File

@ -4,28 +4,15 @@
package org.yuzu.yuzu_emu.features.settings.model.view
import org.yuzu.yuzu_emu.features.settings.model.AbstractLongSetting
import org.yuzu.yuzu_emu.features.settings.model.AbstractSetting
class DateTimeSetting(
setting: AbstractSetting?,
private val longSetting: AbstractLongSetting,
titleId: Int,
descriptionId: Int,
val key: String? = null,
private val defaultValue: Long? = null
) : SettingsItem(setting, titleId, descriptionId) {
descriptionId: Int
) : SettingsItem(longSetting, titleId, descriptionId) {
override val type = TYPE_DATETIME_SETTING
val value: Long
get() = if (setting != null) {
val setting = setting as AbstractLongSetting
setting.long
} else {
defaultValue!!
}
fun setSelectedValue(datetime: Long): AbstractLongSetting {
val longSetting = setting as AbstractLongSetting
longSetting.setLong(datetime)
return longSetting
}
var value: Long
get() = longSetting.long
set(value) = (setting as AbstractLongSetting).setLong(value)
}

View File

@ -5,6 +5,6 @@ package org.yuzu.yuzu_emu.features.settings.model.view
class HeaderSetting(
titleId: Int
) : SettingsItem(null, titleId, 0) {
) : SettingsItem(emptySetting, titleId, 0) {
override val type = TYPE_HEADER
}

View File

@ -8,6 +8,6 @@ class RunnableSetting(
descriptionId: Int,
val isRuntimeRunnable: Boolean,
val runnable: () -> Unit
) : SettingsItem(null, titleId, descriptionId) {
) : SettingsItem(emptySetting, titleId, descriptionId) {
override val type = TYPE_RUNNABLE
}

View File

@ -5,6 +5,7 @@ package org.yuzu.yuzu_emu.features.settings.model.view
import org.yuzu.yuzu_emu.NativeLibrary
import org.yuzu.yuzu_emu.features.settings.model.AbstractSetting
import org.yuzu.yuzu_emu.features.settings.model.Settings
/**
* ViewModel abstraction for an Item in the RecyclerView powering SettingsFragments.
@ -14,7 +15,7 @@ import org.yuzu.yuzu_emu.features.settings.model.AbstractSetting
* file.)
*/
abstract class SettingsItem(
var setting: AbstractSetting?,
val setting: AbstractSetting,
val nameId: Int,
val descriptionId: Int
) {
@ -23,7 +24,7 @@ abstract class SettingsItem(
val isEditable: Boolean
get() {
if (!NativeLibrary.isRunning()) return true
return setting?.isRuntimeModifiable ?: false
return setting.isRuntimeModifiable
}
companion object {
@ -35,5 +36,12 @@ abstract class SettingsItem(
const val TYPE_STRING_SINGLE_CHOICE = 5
const val TYPE_DATETIME_SETTING = 6
const val TYPE_RUNNABLE = 7
val emptySetting = object : AbstractSetting {
override val key: String = ""
override val category: Settings.Category = Settings.Category.Ui
override val defaultValue: Any = false
override fun reset() {}
}
}
}

View File

@ -4,36 +4,27 @@
package org.yuzu.yuzu_emu.features.settings.model.view
import org.yuzu.yuzu_emu.features.settings.model.AbstractIntSetting
import org.yuzu.yuzu_emu.features.settings.model.AbstractSetting
class SingleChoiceSetting(
setting: AbstractIntSetting?,
setting: AbstractSetting,
titleId: Int,
descriptionId: Int,
val choicesId: Int,
val valuesId: Int,
val key: String? = null,
val defaultValue: Int? = null
val valuesId: Int
) : SettingsItem(setting, titleId, descriptionId) {
override val type = TYPE_SINGLE_CHOICE
val selectedValue: Int
get() = if (setting != null) {
val setting = setting as AbstractIntSetting
setting.int
} else {
defaultValue!!
var selectedValue: Int
get() {
return when (setting) {
is AbstractIntSetting -> setting.int
else -> -1
}
}
set(value) {
when (setting) {
is AbstractIntSetting -> setting.setInt(value)
}
}
/**
* Write a value to the backing int. If that int was previously null,
* initializes a new one and returns it, so it can be added to the Hashmap.
*
* @param selection New value of the int.
* @return the existing setting with the new value applied.
*/
fun setSelectedValue(selection: Int): AbstractIntSetting {
val intSetting = setting as AbstractIntSetting
intSetting.setInt(selection)
return intSetting
}
}

View File

@ -4,75 +4,38 @@
package org.yuzu.yuzu_emu.features.settings.model.view
import org.yuzu.yuzu_emu.features.settings.model.AbstractByteSetting
import kotlin.math.roundToInt
import org.yuzu.yuzu_emu.features.settings.model.AbstractFloatSetting
import org.yuzu.yuzu_emu.features.settings.model.AbstractIntSetting
import org.yuzu.yuzu_emu.features.settings.model.AbstractSetting
import org.yuzu.yuzu_emu.features.settings.model.AbstractShortSetting
import org.yuzu.yuzu_emu.utils.Log
import kotlin.math.roundToInt
class SliderSetting(
setting: AbstractSetting?,
setting: AbstractSetting,
titleId: Int,
descriptionId: Int,
val min: Int,
val max: Int,
val units: String,
val key: String? = null,
val defaultValue: Any? = null
val units: String
) : SettingsItem(setting, titleId, descriptionId) {
override val type = TYPE_SLIDER
val selectedValue: Any
var selectedValue: Int
get() {
val setting = setting ?: return defaultValue!!
return when (setting) {
is AbstractByteSetting -> setting.byte.toInt()
is AbstractShortSetting -> setting.short.toInt()
is AbstractIntSetting -> setting.int
is AbstractFloatSetting -> setting.float.roundToInt()
else -> {
Log.error("[SliderSetting] Error casting setting type.")
-1
}
else -> -1
}
}
set(value) {
when (setting) {
is AbstractByteSetting -> setting.setByte(value.toByte())
is AbstractShortSetting -> setting.setShort(value.toShort())
is AbstractIntSetting -> setting.setInt(value)
is AbstractFloatSetting -> setting.setFloat(value.toFloat())
}
}
/**
* Write a value to the backing int. If that int was previously null,
* initializes a new one and returns it, so it can be added to the Hashmap.
*
* @param selection New value of the int.
* @return the existing setting with the new value applied.
*/
fun setSelectedValue(selection: Int): AbstractIntSetting {
val intSetting = setting as AbstractIntSetting
intSetting.setInt(selection)
return intSetting
}
/**
* Write a value to the backing float. If that float was previously null,
* initializes a new one and returns it, so it can be added to the Hashmap.
*
* @param selection New value of the float.
* @return the existing setting with the new value applied.
*/
fun setSelectedValue(selection: Float): AbstractFloatSetting {
val floatSetting = setting as AbstractFloatSetting
floatSetting.setFloat(selection)
return floatSetting
}
fun setSelectedValue(selection: Short): AbstractShortSetting {
val shortSetting = setting as AbstractShortSetting
shortSetting.setShort(selection)
return shortSetting
}
fun setSelectedValue(selection: Byte): AbstractByteSetting {
val byteSetting = setting as AbstractByteSetting
byteSetting.setByte(selection)
return byteSetting
}
}

View File

@ -3,57 +3,31 @@
package org.yuzu.yuzu_emu.features.settings.model.view
import org.yuzu.yuzu_emu.features.settings.model.AbstractSetting
import org.yuzu.yuzu_emu.features.settings.model.AbstractStringSetting
class StringSingleChoiceSetting(
setting: AbstractSetting?,
private val stringSetting: AbstractStringSetting,
titleId: Int,
descriptionId: Int,
val choices: Array<String>,
val values: Array<String>?,
val key: String? = null,
private val defaultValue: String? = null
) : SettingsItem(setting, titleId, descriptionId) {
val values: Array<String>
) : SettingsItem(stringSetting, titleId, descriptionId) {
override val type = TYPE_STRING_SINGLE_CHOICE
fun getValueAt(index: Int): String? {
if (values == null) return null
return if (index >= 0 && index < values.size) {
values[index]
} else {
""
}
}
fun getValueAt(index: Int): String =
if (index >= 0 && index < values.size) values[index] else ""
var selectedValue: String
get() = stringSetting.string
set(value) = stringSetting.setString(value)
val selectedValue: String
get() = if (setting != null) {
val setting = setting as AbstractStringSetting
setting.string
} else {
defaultValue!!
}
val selectValueIndex: Int
get() {
val selectedValue = selectedValue
for (i in values!!.indices) {
for (i in values.indices) {
if (values[i] == selectedValue) {
return i
}
}
return -1
}
/**
* Write a value to the backing int. If that int was previously null,
* initializes a new one and returns it, so it can be added to the Hashmap.
*
* @param selection New value of the int.
* @return the existing setting with the new value applied.
*/
fun setSelectedValue(selection: String): AbstractStringSetting {
val stringSetting = setting as AbstractStringSetting
stringSetting.setString(selection)
return stringSetting
}
}

View File

@ -7,6 +7,6 @@ class SubmenuSetting(
titleId: Int,
descriptionId: Int,
val menuKey: String
) : SettingsItem(null, titleId, descriptionId) {
) : SettingsItem(emptySetting, titleId, descriptionId) {
override val type = TYPE_SUBMENU
}

View File

@ -10,53 +10,22 @@ import org.yuzu.yuzu_emu.features.settings.model.AbstractSetting
class SwitchSetting(
setting: AbstractSetting,
titleId: Int,
descriptionId: Int,
val key: String? = null,
val defaultValue: Any? = null
descriptionId: Int
) : SettingsItem(setting, titleId, descriptionId) {
override val type = TYPE_SWITCH
val isChecked: Boolean
var checked: Boolean
get() {
if (setting == null) {
return defaultValue as Boolean
return when (setting) {
is AbstractIntSetting -> setting.int == 1
is AbstractBooleanSetting -> setting.boolean
else -> false
}
// Try integer setting
try {
val setting = setting as AbstractIntSetting
return setting.int == 1
} catch (_: ClassCastException) {
}
// Try boolean setting
try {
val setting = setting as AbstractBooleanSetting
return setting.boolean
} catch (_: ClassCastException) {
}
return defaultValue as Boolean
}
/**
* Write a value to the backing boolean. If that boolean was previously null,
* initializes a new one and returns it, so it can be added to the Hashmap.
*
* @param checked Pretty self explanatory.
* @return the existing setting with the new value applied.
*/
fun setChecked(checked: Boolean): AbstractSetting {
// Try integer setting
try {
val setting = setting as AbstractIntSetting
setting.setInt(if (checked) 1 else 0)
return setting
} catch (_: ClassCastException) {
set(value) {
when (setting) {
is AbstractIntSetting -> setting.setInt(if (value) 1 else 0)
is AbstractBooleanSetting -> setting.setBoolean(value)
}
}
// Try boolean setting
val setting = setting as AbstractBooleanSetting
setting.setBoolean(checked)
return setting
}
}

View File

@ -113,7 +113,7 @@ class SettingsAdapter(
}
fun onBooleanClick(item: SwitchSetting, position: Int, checked: Boolean) {
item.setChecked(checked)
item.checked = checked
fragmentView.onSettingChanged()
}
@ -183,7 +183,7 @@ class SettingsAdapter(
if (item.value != epochTime) {
fragmentView.onSettingChanged()
notifyItemChanged(clickedPosition)
item.setSelectedValue(epochTime)
item.value = epochTime
}
clickedItem = null
}
@ -244,7 +244,7 @@ class SettingsAdapter(
}
// Get the backing Setting, which may be null (if for example it was missing from the file)
scSetting.setSelectedValue(value)
scSetting.selectedValue = value
closeDialog()
}
@ -252,7 +252,7 @@ class SettingsAdapter(
val scSetting = clickedItem as StringSingleChoiceSetting
val value = scSetting.getValueAt(which)
if (scSetting.selectedValue != value) fragmentView.onSettingChanged()
scSetting.setSelectedValue(value!!)
scSetting.selectedValue = value!!
closeDialog()
}
@ -264,21 +264,21 @@ class SettingsAdapter(
when (sliderSetting.setting) {
is ByteSetting -> {
val value = sliderProgress.toByte()
sliderSetting.setSelectedValue(value)
sliderSetting.selectedValue = value.toInt()
}
is ShortSetting -> {
val value = sliderProgress.toShort()
sliderSetting.setSelectedValue(value)
sliderSetting.selectedValue = value.toInt()
}
is FloatSetting -> {
val value = sliderProgress.toFloat()
sliderSetting.setSelectedValue(value)
sliderSetting.selectedValue = value.toInt()
}
else -> {
sliderSetting.setSelectedValue(sliderProgress)
sliderSetting.selectedValue = sliderProgress
}
}
closeDialog()

View File

@ -75,47 +75,13 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
private fun addConfigSettings(sl: ArrayList<SettingsItem>) {
settingsActivity.setToolbarTitle(settingsActivity.getString(R.string.advanced_settings))
sl.apply {
add(SubmenuSetting(R.string.preferences_general, 0, Settings.SECTION_GENERAL))
add(SubmenuSetting(R.string.preferences_system, 0, Settings.SECTION_SYSTEM))
add(SubmenuSetting(R.string.preferences_graphics, 0, Settings.SECTION_RENDERER))
add(SubmenuSetting(R.string.preferences_audio, 0, Settings.SECTION_AUDIO))
add(SubmenuSetting(R.string.preferences_debug, 0, Settings.SECTION_DEBUG))
add(
SubmenuSetting(
R.string.preferences_general,
0,
Settings.SECTION_GENERAL
)
)
add(
SubmenuSetting(
R.string.preferences_system,
0,
Settings.SECTION_SYSTEM
)
)
add(
SubmenuSetting(
R.string.preferences_graphics,
0,
Settings.SECTION_RENDERER
)
)
add(
SubmenuSetting(
R.string.preferences_audio,
0,
Settings.SECTION_AUDIO
)
)
add(
SubmenuSetting(
R.string.preferences_debug,
0,
Settings.SECTION_DEBUG
)
)
add(
RunnableSetting(
R.string.reset_to_default,
0,
false
) {
RunnableSetting(R.string.reset_to_default, 0, false) {
ResetSettingsDialogFragment().show(
settingsActivity.supportFragmentManager,
ResetSettingsDialogFragment.TAG
@ -132,9 +98,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
SwitchSetting(
BooleanSetting.RENDERER_USE_SPEED_LIMIT,
R.string.frame_limit_enable,
R.string.frame_limit_enable_description,
BooleanSetting.RENDERER_USE_SPEED_LIMIT.key,
BooleanSetting.RENDERER_USE_SPEED_LIMIT.defaultValue
R.string.frame_limit_enable_description
)
)
add(
@ -144,9 +108,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
R.string.frame_limit_slider_description,
1,
200,
"%",
ShortSetting.RENDERER_SPEED_LIMIT.key,
ShortSetting.RENDERER_SPEED_LIMIT.defaultValue
"%"
)
)
add(
@ -155,18 +117,14 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
R.string.cpu_accuracy,
0,
R.array.cpuAccuracyNames,
R.array.cpuAccuracyValues,
IntSetting.CPU_ACCURACY.key,
IntSetting.CPU_ACCURACY.defaultValue
R.array.cpuAccuracyValues
)
)
add(
SwitchSetting(
BooleanSetting.PICTURE_IN_PICTURE,
R.string.picture_in_picture,
R.string.picture_in_picture_description,
BooleanSetting.PICTURE_IN_PICTURE.key,
BooleanSetting.PICTURE_IN_PICTURE.defaultValue
R.string.picture_in_picture_description
)
)
}
@ -179,9 +137,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
SwitchSetting(
BooleanSetting.USE_DOCKED_MODE,
R.string.use_docked_mode,
R.string.use_docked_mode_description,
BooleanSetting.USE_DOCKED_MODE.key,
BooleanSetting.USE_DOCKED_MODE.defaultValue
R.string.use_docked_mode_description
)
)
add(
@ -190,9 +146,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
R.string.emulated_region,
0,
R.array.regionNames,
R.array.regionValues,
IntSetting.REGION_INDEX.key,
IntSetting.REGION_INDEX.defaultValue
R.array.regionValues
)
)
add(
@ -201,29 +155,17 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
R.string.emulated_language,
0,
R.array.languageNames,
R.array.languageValues,
IntSetting.LANGUAGE_INDEX.key,
IntSetting.LANGUAGE_INDEX.defaultValue
R.array.languageValues
)
)
add(
SwitchSetting(
BooleanSetting.USE_CUSTOM_RTC,
R.string.use_custom_rtc,
R.string.use_custom_rtc_description,
BooleanSetting.USE_CUSTOM_RTC.key,
BooleanSetting.USE_CUSTOM_RTC.defaultValue
)
)
add(
DateTimeSetting(
LongSetting.CUSTOM_RTC,
R.string.set_custom_rtc,
0,
LongSetting.CUSTOM_RTC.key,
LongSetting.CUSTOM_RTC.defaultValue
R.string.use_custom_rtc_description
)
)
add(DateTimeSetting(LongSetting.CUSTOM_RTC, R.string.set_custom_rtc, 0))
}
}
@ -236,9 +178,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
R.string.renderer_accuracy,
0,
R.array.rendererAccuracyNames,
R.array.rendererAccuracyValues,
IntSetting.RENDERER_ACCURACY.key,
IntSetting.RENDERER_ACCURACY.defaultValue
R.array.rendererAccuracyValues
)
)
add(
@ -247,9 +187,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
R.string.renderer_resolution,
0,
R.array.rendererResolutionNames,
R.array.rendererResolutionValues,
IntSetting.RENDERER_RESOLUTION.key,
IntSetting.RENDERER_RESOLUTION.defaultValue
R.array.rendererResolutionValues
)
)
add(
@ -258,9 +196,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
R.string.renderer_vsync,
0,
R.array.rendererVSyncNames,
R.array.rendererVSyncValues,
IntSetting.RENDERER_VSYNC.key,
IntSetting.RENDERER_VSYNC.defaultValue
R.array.rendererVSyncValues
)
)
add(
@ -269,9 +205,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
R.string.renderer_scaling_filter,
0,
R.array.rendererScalingFilterNames,
R.array.rendererScalingFilterValues,
IntSetting.RENDERER_SCALING_FILTER.key,
IntSetting.RENDERER_SCALING_FILTER.defaultValue
R.array.rendererScalingFilterValues
)
)
add(
@ -280,9 +214,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
R.string.renderer_anti_aliasing,
0,
R.array.rendererAntiAliasingNames,
R.array.rendererAntiAliasingValues,
IntSetting.RENDERER_ANTI_ALIASING.key,
IntSetting.RENDERER_ANTI_ALIASING.defaultValue
R.array.rendererAntiAliasingValues
)
)
add(
@ -291,9 +223,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
R.string.renderer_screen_layout,
0,
R.array.rendererScreenLayoutNames,
R.array.rendererScreenLayoutValues,
IntSetting.RENDERER_SCREEN_LAYOUT.key,
IntSetting.RENDERER_SCREEN_LAYOUT.defaultValue
R.array.rendererScreenLayoutValues
)
)
add(
@ -302,45 +232,35 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
R.string.renderer_aspect_ratio,
0,
R.array.rendererAspectRatioNames,
R.array.rendererAspectRatioValues,
IntSetting.RENDERER_ASPECT_RATIO.key,
IntSetting.RENDERER_ASPECT_RATIO.defaultValue
R.array.rendererAspectRatioValues
)
)
add(
SwitchSetting(
BooleanSetting.RENDERER_USE_DISK_SHADER_CACHE,
R.string.use_disk_shader_cache,
R.string.use_disk_shader_cache_description,
BooleanSetting.RENDERER_USE_DISK_SHADER_CACHE.key,
BooleanSetting.RENDERER_USE_DISK_SHADER_CACHE.defaultValue
R.string.use_disk_shader_cache_description
)
)
add(
SwitchSetting(
BooleanSetting.RENDERER_FORCE_MAX_CLOCK,
R.string.renderer_force_max_clock,
R.string.renderer_force_max_clock_description,
BooleanSetting.RENDERER_FORCE_MAX_CLOCK.key,
BooleanSetting.RENDERER_FORCE_MAX_CLOCK.defaultValue
R.string.renderer_force_max_clock_description
)
)
add(
SwitchSetting(
BooleanSetting.RENDERER_ASYNCHRONOUS_SHADERS,
R.string.renderer_asynchronous_shaders,
R.string.renderer_asynchronous_shaders_description,
BooleanSetting.RENDERER_ASYNCHRONOUS_SHADERS.key,
BooleanSetting.RENDERER_ASYNCHRONOUS_SHADERS.defaultValue
R.string.renderer_asynchronous_shaders_description
)
)
add(
SwitchSetting(
BooleanSetting.RENDERER_REACTIVE_FLUSHING,
R.string.renderer_reactive_flushing,
R.string.renderer_reactive_flushing_description,
BooleanSetting.RENDERER_REACTIVE_FLUSHING.key,
BooleanSetting.RENDERER_REACTIVE_FLUSHING.defaultValue
R.string.renderer_reactive_flushing_description
)
)
}
@ -355,9 +275,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
R.string.audio_output_engine,
0,
R.array.outputEngineEntries,
R.array.outputEngineValues,
IntSetting.AUDIO_OUTPUT_ENGINE.key,
IntSetting.AUDIO_OUTPUT_ENGINE.defaultValue
R.array.outputEngineValues
)
)
add(
@ -367,9 +285,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
R.string.audio_volume_description,
0,
100,
"%",
ByteSetting.AUDIO_VOLUME.key,
ByteSetting.AUDIO_VOLUME.defaultValue
"%"
)
)
}
@ -392,7 +308,12 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
override val key: String? = null
override val category = Settings.Category.UiGeneral
override val isRuntimeModifiable: Boolean = false
override val defaultValue: Any = 0
override val defaultValue: Int = 0
override fun reset() {
preferences.edit()
.putInt(Settings.PREF_THEME, defaultValue)
.apply()
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
@ -431,7 +352,12 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
override val key: String? = null
override val category = Settings.Category.UiGeneral
override val isRuntimeModifiable: Boolean = false
override val defaultValue: Any = -1
override val defaultValue: Int = -1
override fun reset() {
preferences.edit()
.putInt(Settings.PREF_BLACK_BACKGROUNDS, defaultValue)
.apply()
}
}
add(
@ -458,7 +384,12 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
override val key: String? = null
override val category = Settings.Category.UiGeneral
override val isRuntimeModifiable: Boolean = false
override val defaultValue: Any = false
override val defaultValue: Boolean = false
override fun reset() {
preferences.edit()
.putBoolean(Settings.PREF_BLACK_BACKGROUNDS, defaultValue)
.apply()
}
}
add(
@ -481,18 +412,14 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
R.string.renderer_api,
0,
R.array.rendererApiNames,
R.array.rendererApiValues,
IntSetting.RENDERER_BACKEND.key,
IntSetting.RENDERER_BACKEND.defaultValue
R.array.rendererApiValues
)
)
add(
SwitchSetting(
BooleanSetting.RENDERER_DEBUG,
R.string.renderer_debug,
R.string.renderer_debug_description,
BooleanSetting.RENDERER_DEBUG.key,
BooleanSetting.RENDERER_DEBUG.defaultValue
R.string.renderer_debug_description
)
)
@ -501,9 +428,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
SwitchSetting(
BooleanSetting.CPU_DEBUG_MODE,
R.string.cpu_debug_mode,
R.string.cpu_debug_mode_description,
BooleanSetting.CPU_DEBUG_MODE.key,
BooleanSetting.CPU_DEBUG_MODE.defaultValue
R.string.cpu_debug_mode_description
)
)
@ -520,15 +445,10 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
override val key: String? = null
override val category = Settings.Category.Cpu
override val isRuntimeModifiable: Boolean = false
override val defaultValue: Any = true
override val defaultValue: Boolean = true
override fun reset() = setBoolean(defaultValue)
}
add(
SwitchSetting(
fastmem,
R.string.fastmem,
0
)
)
add(SwitchSetting(fastmem, R.string.fastmem, 0))
}
}
}

View File

@ -46,7 +46,7 @@ class DateTimeViewHolder(val binding: ListItemSettingBinding, adapter: SettingsA
override fun onLongClick(clicked: View): Boolean {
if (setting.isEditable) {
return adapter.onLongClick(setting.setting!!, bindingAdapterPosition)
return adapter.onLongClick(setting.setting, bindingAdapterPosition)
}
return false
}

View File

@ -35,7 +35,7 @@ class SingleChoiceViewHolder(val binding: ListItemSettingBinding, adapter: Setti
}
}
} else if (item is StringSingleChoiceSetting) {
for (i in item.values!!.indices) {
for (i in item.values.indices) {
if (item.values[i] == item.selectedValue) {
binding.textSettingValue.text = item.choices[i]
break
@ -66,7 +66,7 @@ class SingleChoiceViewHolder(val binding: ListItemSettingBinding, adapter: Setti
override fun onLongClick(clicked: View): Boolean {
if (setting.isEditable) {
return adapter.onLongClick(setting.setting!!, bindingAdapterPosition)
return adapter.onLongClick(setting.setting, bindingAdapterPosition)
}
return false
}

View File

@ -41,7 +41,7 @@ class SliderViewHolder(val binding: ListItemSettingBinding, adapter: SettingsAda
override fun onLongClick(clicked: View): Boolean {
if (setting.isEditable) {
return adapter.onLongClick(setting.setting!!, bindingAdapterPosition)
return adapter.onLongClick(setting.setting, bindingAdapterPosition)
}
return false
}

View File

@ -28,7 +28,7 @@ class SwitchSettingViewHolder(val binding: ListItemSettingSwitchBinding, adapter
binding.switchWidget.setOnCheckedChangeListener { _: CompoundButton, _: Boolean ->
adapter.onBooleanClick(item, bindingAdapterPosition, binding.switchWidget.isChecked)
}
binding.switchWidget.isChecked = setting.isChecked
binding.switchWidget.isChecked = setting.checked
setStyle(setting.isEditable, binding)
}