android: Make SwitchSetting only allow Boolean setting

This commit is contained in:
Kleidis 2025-03-08 17:09:32 +01:00 committed by OpenSauce
parent 43dbe42b29
commit 0f1084be9c

View File

@ -9,53 +9,30 @@ import org.citra.citra_emu.features.settings.model.AbstractIntSetting
import org.citra.citra_emu.features.settings.model.AbstractSetting
class SwitchSetting(
setting: AbstractSetting,
setting: AbstractBooleanSetting,
titleId: Int,
descriptionId: Int,
val key: String? = null,
val defaultValue: Any? = null
val defaultValue: Boolean = false
) : SettingsItem(setting, titleId, descriptionId) {
override val type = TYPE_SWITCH
val isChecked: Boolean
get() {
if (setting == null) {
return defaultValue as Boolean
return defaultValue
}
// 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
val setting = setting as AbstractBooleanSetting
return setting.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.
* Write a value to the backing boolean.
*
* @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.int = if (checked) 1 else 0
return setting
} catch (_: ClassCastException) {
}
// Try boolean setting
fun setChecked(checked: Boolean): AbstractBooleanSetting {
val setting = setting as AbstractBooleanSetting
setting.boolean = checked
return setting