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 val isRuntimeModifiable: Boolean
get() = NativeConfig.getIsRuntimeModifiable(key!!) get() = NativeConfig.getIsRuntimeModifiable(key!!)
fun reset() = run { } fun reset()
} }

View File

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

View File

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

View File

@ -8,6 +8,6 @@ class RunnableSetting(
descriptionId: Int, descriptionId: Int,
val isRuntimeRunnable: Boolean, val isRuntimeRunnable: Boolean,
val runnable: () -> Unit val runnable: () -> Unit
) : SettingsItem(null, titleId, descriptionId) { ) : SettingsItem(emptySetting, titleId, descriptionId) {
override val type = TYPE_RUNNABLE 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.NativeLibrary
import org.yuzu.yuzu_emu.features.settings.model.AbstractSetting 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. * ViewModel abstraction for an Item in the RecyclerView powering SettingsFragments.
@ -14,7 +15,7 @@ import org.yuzu.yuzu_emu.features.settings.model.AbstractSetting
* file.) * file.)
*/ */
abstract class SettingsItem( abstract class SettingsItem(
var setting: AbstractSetting?, val setting: AbstractSetting,
val nameId: Int, val nameId: Int,
val descriptionId: Int val descriptionId: Int
) { ) {
@ -23,7 +24,7 @@ abstract class SettingsItem(
val isEditable: Boolean val isEditable: Boolean
get() { get() {
if (!NativeLibrary.isRunning()) return true if (!NativeLibrary.isRunning()) return true
return setting?.isRuntimeModifiable ?: false return setting.isRuntimeModifiable
} }
companion object { companion object {
@ -35,5 +36,12 @@ abstract class SettingsItem(
const val TYPE_STRING_SINGLE_CHOICE = 5 const val TYPE_STRING_SINGLE_CHOICE = 5
const val TYPE_DATETIME_SETTING = 6 const val TYPE_DATETIME_SETTING = 6
const val TYPE_RUNNABLE = 7 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 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.AbstractIntSetting
import org.yuzu.yuzu_emu.features.settings.model.AbstractSetting
class SingleChoiceSetting( class SingleChoiceSetting(
setting: AbstractIntSetting?, setting: AbstractSetting,
titleId: Int, titleId: Int,
descriptionId: Int, descriptionId: Int,
val choicesId: Int, val choicesId: Int,
val valuesId: Int, val valuesId: Int
val key: String? = null,
val defaultValue: Int? = null
) : SettingsItem(setting, titleId, descriptionId) { ) : SettingsItem(setting, titleId, descriptionId) {
override val type = TYPE_SINGLE_CHOICE override val type = TYPE_SINGLE_CHOICE
val selectedValue: Int var selectedValue: Int
get() = if (setting != null) { get() {
val setting = setting as AbstractIntSetting return when (setting) {
setting.int is AbstractIntSetting -> setting.int
} else { else -> -1
defaultValue!! }
} }
set(value) {
/** when (setting) {
* Write a value to the backing int. If that int was previously null, is AbstractIntSetting -> setting.setInt(value)
* 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 package org.yuzu.yuzu_emu.features.settings.model.view
import org.yuzu.yuzu_emu.features.settings.model.AbstractByteSetting 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.AbstractFloatSetting
import org.yuzu.yuzu_emu.features.settings.model.AbstractIntSetting 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.AbstractSetting
import org.yuzu.yuzu_emu.features.settings.model.AbstractShortSetting import org.yuzu.yuzu_emu.features.settings.model.AbstractShortSetting
import org.yuzu.yuzu_emu.utils.Log import kotlin.math.roundToInt
class SliderSetting( class SliderSetting(
setting: AbstractSetting?, setting: AbstractSetting,
titleId: Int, titleId: Int,
descriptionId: Int, descriptionId: Int,
val min: Int, val min: Int,
val max: Int, val max: Int,
val units: String, val units: String
val key: String? = null,
val defaultValue: Any? = null
) : SettingsItem(setting, titleId, descriptionId) { ) : SettingsItem(setting, titleId, descriptionId) {
override val type = TYPE_SLIDER override val type = TYPE_SLIDER
val selectedValue: Any var selectedValue: Int
get() { get() {
val setting = setting ?: return defaultValue!!
return when (setting) { return when (setting) {
is AbstractByteSetting -> setting.byte.toInt() is AbstractByteSetting -> setting.byte.toInt()
is AbstractShortSetting -> setting.short.toInt() is AbstractShortSetting -> setting.short.toInt()
is AbstractIntSetting -> setting.int is AbstractIntSetting -> setting.int
is AbstractFloatSetting -> setting.float.roundToInt() is AbstractFloatSetting -> setting.float.roundToInt()
else -> { else -> -1
Log.error("[SliderSetting] Error casting setting type.") }
-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 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 import org.yuzu.yuzu_emu.features.settings.model.AbstractStringSetting
class StringSingleChoiceSetting( class StringSingleChoiceSetting(
setting: AbstractSetting?, private val stringSetting: AbstractStringSetting,
titleId: Int, titleId: Int,
descriptionId: Int, descriptionId: Int,
val choices: Array<String>, val choices: Array<String>,
val values: Array<String>?, val values: Array<String>
val key: String? = null, ) : SettingsItem(stringSetting, titleId, descriptionId) {
private val defaultValue: String? = null
) : SettingsItem(setting, titleId, descriptionId) {
override val type = TYPE_STRING_SINGLE_CHOICE override val type = TYPE_STRING_SINGLE_CHOICE
fun getValueAt(index: Int): String? { fun getValueAt(index: Int): String =
if (values == null) return null if (index >= 0 && index < values.size) values[index] else ""
return if (index >= 0 && index < values.size) {
values[index] var selectedValue: String
} else { 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 val selectValueIndex: Int
get() { get() {
val selectedValue = selectedValue for (i in values.indices) {
for (i in values!!.indices) {
if (values[i] == selectedValue) { if (values[i] == selectedValue) {
return i return i
} }
} }
return -1 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, titleId: Int,
descriptionId: Int, descriptionId: Int,
val menuKey: String val menuKey: String
) : SettingsItem(null, titleId, descriptionId) { ) : SettingsItem(emptySetting, titleId, descriptionId) {
override val type = TYPE_SUBMENU override val type = TYPE_SUBMENU
} }

View File

@ -10,53 +10,22 @@ import org.yuzu.yuzu_emu.features.settings.model.AbstractSetting
class SwitchSetting( class SwitchSetting(
setting: AbstractSetting, setting: AbstractSetting,
titleId: Int, titleId: Int,
descriptionId: Int, descriptionId: Int
val key: String? = null,
val defaultValue: Any? = null
) : SettingsItem(setting, titleId, descriptionId) { ) : SettingsItem(setting, titleId, descriptionId) {
override val type = TYPE_SWITCH override val type = TYPE_SWITCH
val isChecked: Boolean var checked: Boolean
get() { get() {
if (setting == null) { return when (setting) {
return defaultValue as Boolean is AbstractIntSetting -> setting.int == 1
} is AbstractBooleanSetting -> setting.boolean
else -> false
// Try integer setting }
try { }
val setting = setting as AbstractIntSetting set(value) {
return setting.int == 1 when (setting) {
} catch (_: ClassCastException) { is AbstractIntSetting -> setting.setInt(if (value) 1 else 0)
} is AbstractBooleanSetting -> setting.setBoolean(value)
}
// 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) {
}
// 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) { fun onBooleanClick(item: SwitchSetting, position: Int, checked: Boolean) {
item.setChecked(checked) item.checked = checked
fragmentView.onSettingChanged() fragmentView.onSettingChanged()
} }
@ -183,7 +183,7 @@ class SettingsAdapter(
if (item.value != epochTime) { if (item.value != epochTime) {
fragmentView.onSettingChanged() fragmentView.onSettingChanged()
notifyItemChanged(clickedPosition) notifyItemChanged(clickedPosition)
item.setSelectedValue(epochTime) item.value = epochTime
} }
clickedItem = null 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) // Get the backing Setting, which may be null (if for example it was missing from the file)
scSetting.setSelectedValue(value) scSetting.selectedValue = value
closeDialog() closeDialog()
} }
@ -252,7 +252,7 @@ class SettingsAdapter(
val scSetting = clickedItem as StringSingleChoiceSetting val scSetting = clickedItem as StringSingleChoiceSetting
val value = scSetting.getValueAt(which) val value = scSetting.getValueAt(which)
if (scSetting.selectedValue != value) fragmentView.onSettingChanged() if (scSetting.selectedValue != value) fragmentView.onSettingChanged()
scSetting.setSelectedValue(value!!) scSetting.selectedValue = value!!
closeDialog() closeDialog()
} }
@ -264,21 +264,21 @@ class SettingsAdapter(
when (sliderSetting.setting) { when (sliderSetting.setting) {
is ByteSetting -> { is ByteSetting -> {
val value = sliderProgress.toByte() val value = sliderProgress.toByte()
sliderSetting.setSelectedValue(value) sliderSetting.selectedValue = value.toInt()
} }
is ShortSetting -> { is ShortSetting -> {
val value = sliderProgress.toShort() val value = sliderProgress.toShort()
sliderSetting.setSelectedValue(value) sliderSetting.selectedValue = value.toInt()
} }
is FloatSetting -> { is FloatSetting -> {
val value = sliderProgress.toFloat() val value = sliderProgress.toFloat()
sliderSetting.setSelectedValue(value) sliderSetting.selectedValue = value.toInt()
} }
else -> { else -> {
sliderSetting.setSelectedValue(sliderProgress) sliderSetting.selectedValue = sliderProgress
} }
} }
closeDialog() closeDialog()

View File

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

View File

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

View File

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

View File

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