android: Prevent editing unsafe settings at runtime
There currently isn't a visual "disabled" cue for any of the view holders that aren't the switch setting. This will be improved in the future.
This commit is contained in:
parent
c609847e49
commit
766655fa41
|
@ -3,6 +3,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
|
||||
|
||||
/**
|
||||
|
@ -19,6 +20,12 @@ abstract class SettingsItem(
|
|||
) {
|
||||
abstract val type: Int
|
||||
|
||||
val isEditable: Boolean
|
||||
get() {
|
||||
if (!NativeLibrary.isRunning()) return true
|
||||
return setting?.isRuntimeEditable ?: false
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val TYPE_HEADER = 0
|
||||
const val TYPE_SWITCH = 1
|
||||
|
|
|
@ -11,10 +11,10 @@ import org.yuzu.yuzu_emu.features.settings.ui.SettingsAdapter
|
|||
|
||||
class DateTimeViewHolder(val binding: ListItemSettingBinding, adapter: SettingsAdapter) :
|
||||
SettingViewHolder(binding.root, adapter) {
|
||||
private lateinit var item: DateTimeSetting
|
||||
private lateinit var setting: DateTimeSetting
|
||||
|
||||
override fun bind(item: SettingsItem) {
|
||||
this.item = item as DateTimeSetting
|
||||
setting = item as DateTimeSetting
|
||||
binding.textSettingName.setText(item.nameId)
|
||||
if (item.descriptionId!! > 0) {
|
||||
binding.textSettingDescription.setText(item.descriptionId)
|
||||
|
@ -25,6 +25,8 @@ class DateTimeViewHolder(val binding: ListItemSettingBinding, adapter: SettingsA
|
|||
}
|
||||
|
||||
override fun onClick(clicked: View) {
|
||||
adapter.onDateTimeClick(item, bindingAdapterPosition)
|
||||
if (setting.isEditable) {
|
||||
adapter.onDateTimeClick(setting, bindingAdapterPosition)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,10 +12,10 @@ import org.yuzu.yuzu_emu.features.settings.ui.SettingsAdapter
|
|||
|
||||
class SingleChoiceViewHolder(val binding: ListItemSettingBinding, adapter: SettingsAdapter) :
|
||||
SettingViewHolder(binding.root, adapter) {
|
||||
private lateinit var item: SettingsItem
|
||||
private lateinit var setting: SettingsItem
|
||||
|
||||
override fun bind(item: SettingsItem) {
|
||||
this.item = item
|
||||
setting = item
|
||||
binding.textSettingName.setText(item.nameId)
|
||||
binding.textSettingDescription.visibility = View.VISIBLE
|
||||
if (item.descriptionId!! > 0) {
|
||||
|
@ -34,14 +34,18 @@ class SingleChoiceViewHolder(val binding: ListItemSettingBinding, adapter: Setti
|
|||
}
|
||||
|
||||
override fun onClick(clicked: View) {
|
||||
if (item is SingleChoiceSetting) {
|
||||
if (!setting.isEditable) {
|
||||
return
|
||||
}
|
||||
|
||||
if (setting is SingleChoiceSetting) {
|
||||
adapter.onSingleChoiceClick(
|
||||
(item as SingleChoiceSetting),
|
||||
(setting as SingleChoiceSetting),
|
||||
bindingAdapterPosition
|
||||
)
|
||||
} else if (item is StringSingleChoiceSetting) {
|
||||
} else if (setting is StringSingleChoiceSetting) {
|
||||
adapter.onStringSingleChoiceClick(
|
||||
(item as StringSingleChoiceSetting),
|
||||
(setting as StringSingleChoiceSetting),
|
||||
bindingAdapterPosition
|
||||
)
|
||||
}
|
||||
|
|
|
@ -11,10 +11,10 @@ import org.yuzu.yuzu_emu.features.settings.ui.SettingsAdapter
|
|||
|
||||
class SliderViewHolder(val binding: ListItemSettingBinding, adapter: SettingsAdapter) :
|
||||
SettingViewHolder(binding.root, adapter) {
|
||||
private lateinit var item: SliderSetting
|
||||
private lateinit var setting: SliderSetting
|
||||
|
||||
override fun bind(item: SettingsItem) {
|
||||
this.item = item as SliderSetting
|
||||
setting = item as SliderSetting
|
||||
binding.textSettingName.setText(item.nameId)
|
||||
if (item.descriptionId!! > 0) {
|
||||
binding.textSettingDescription.setText(item.descriptionId)
|
||||
|
@ -25,6 +25,8 @@ class SliderViewHolder(val binding: ListItemSettingBinding, adapter: SettingsAda
|
|||
}
|
||||
|
||||
override fun onClick(clicked: View) {
|
||||
adapter.onSliderClick(item, bindingAdapterPosition)
|
||||
if (setting.isEditable) {
|
||||
adapter.onSliderClick(setting, bindingAdapterPosition)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,8 +13,10 @@ import org.yuzu.yuzu_emu.features.settings.ui.SettingsAdapter
|
|||
class SwitchSettingViewHolder(val binding: ListItemSettingSwitchBinding, adapter: SettingsAdapter) :
|
||||
SettingViewHolder(binding.root, adapter) {
|
||||
|
||||
private lateinit var setting: SwitchSetting
|
||||
|
||||
override fun bind(item: SettingsItem) {
|
||||
val setting = item as SwitchSetting
|
||||
setting = item as SwitchSetting
|
||||
binding.textSettingName.setText(item.nameId)
|
||||
if (item.descriptionId!! > 0) {
|
||||
binding.textSettingDescription.setText(item.descriptionId)
|
||||
|
@ -27,9 +29,13 @@ class SwitchSettingViewHolder(val binding: ListItemSettingSwitchBinding, adapter
|
|||
binding.switchWidget.setOnCheckedChangeListener { _: CompoundButton, _: Boolean ->
|
||||
adapter.onBooleanClick(item, bindingAdapterPosition, binding.switchWidget.isChecked)
|
||||
}
|
||||
|
||||
binding.switchWidget.isEnabled = setting.isEditable
|
||||
}
|
||||
|
||||
override fun onClick(clicked: View) {
|
||||
binding.switchWidget.toggle()
|
||||
if (setting.isEditable) {
|
||||
binding.switchWidget.toggle()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Reference in New Issue