diff options
author | Charles Lombardo <clombardo169@gmail.com> | 2023-03-07 22:59:00 +0100 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2023-06-03 09:05:36 +0200 |
commit | 91884976a1c41ffe7f24cabf9fd92139d376d498 (patch) | |
tree | 76722100e8e46c28c67d8ffc1a05129b7ff6b4fb /src | |
parent | android: Convert SliderSetting to Kotlin (diff) | |
download | yuzu-91884976a1c41ffe7f24cabf9fd92139d376d498.tar yuzu-91884976a1c41ffe7f24cabf9fd92139d376d498.tar.gz yuzu-91884976a1c41ffe7f24cabf9fd92139d376d498.tar.bz2 yuzu-91884976a1c41ffe7f24cabf9fd92139d376d498.tar.lz yuzu-91884976a1c41ffe7f24cabf9fd92139d376d498.tar.xz yuzu-91884976a1c41ffe7f24cabf9fd92139d376d498.tar.zst yuzu-91884976a1c41ffe7f24cabf9fd92139d376d498.zip |
Diffstat (limited to 'src')
2 files changed, 61 insertions, 82 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/StringSingleChoiceSetting.java b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/StringSingleChoiceSetting.java deleted file mode 100644 index 419abfd49..000000000 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/StringSingleChoiceSetting.java +++ /dev/null @@ -1,82 +0,0 @@ -package org.yuzu.yuzu_emu.features.settings.model.view; - -import org.yuzu.yuzu_emu.features.settings.model.Setting; -import org.yuzu.yuzu_emu.features.settings.model.StringSetting; - -public class StringSingleChoiceSetting extends SettingsItem { - private String mDefaultValue; - - private String[] mChoicesId; - private String[] mValuesId; - - public StringSingleChoiceSetting(String key, String section, int titleId, int descriptionId, - String[] choicesId, String[] valuesId, String defaultValue, Setting setting) { - super(key, section, setting, titleId, descriptionId); - mValuesId = valuesId; - mChoicesId = choicesId; - mDefaultValue = defaultValue; - } - - public String[] getChoicesId() { - return mChoicesId; - } - - public String[] getValuesId() { - return mValuesId; - } - - public String getValueAt(int index) { - if (mValuesId == null) - return null; - - if (index >= 0 && index < mValuesId.length) { - return mValuesId[index]; - } - - return ""; - } - - public String getSelectedValue() { - if (getSetting() != null) { - StringSetting setting = (StringSetting) getSetting(); - return setting.getValue(); - } else { - return mDefaultValue; - } - } - - public int getSelectValueIndex() { - String selectedValue = getSelectedValue(); - for (int i = 0; i < mValuesId.length; i++) { - if (mValuesId[i].equals(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 null if overwritten successfully otherwise; a newly created IntSetting. - */ - public StringSetting setSelectedValue(String selection) { - if (getSetting() == null) { - StringSetting setting = new StringSetting(getKey(), getSection(), selection); - setSetting(setting); - return setting; - } else { - StringSetting setting = (StringSetting) getSetting(); - setting.setValue(selection); - return null; - } - } - - @Override - public int getType() { - return TYPE_STRING_SINGLE_CHOICE; - } -} diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/StringSingleChoiceSetting.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/StringSingleChoiceSetting.kt new file mode 100644 index 000000000..69d81d575 --- /dev/null +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/StringSingleChoiceSetting.kt @@ -0,0 +1,61 @@ +package org.yuzu.yuzu_emu.features.settings.model.view + +import org.yuzu.yuzu_emu.features.settings.model.Setting +import org.yuzu.yuzu_emu.features.settings.model.StringSetting + +class StringSingleChoiceSetting( + key: String, + section: String, + setting: Setting?, + titleId: Int, + descriptionId: Int, + val choicesId: Array<String>, + private val valuesId: Array<String>?, + private val defaultValue: String +) : SettingsItem(key, section, setting, titleId, descriptionId) { + override val type = TYPE_STRING_SINGLE_CHOICE + + fun getValueAt(index: Int): String? { + if (valuesId == null) return null + return if (index >= 0 && index < valuesId.size) { + valuesId[index] + } else "" + } + + val selectedValue: String + get() = if (setting != null) { + val setting = setting as StringSetting + setting.value + } else { + defaultValue + } + val selectValueIndex: Int + get() { + val selectedValue = selectedValue + for (i in valuesId!!.indices) { + if (valuesId[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 null if overwritten successfully otherwise; a newly created IntSetting. + */ + fun setSelectedValue(selection: String?): StringSetting? { + return if (setting == null) { + val newSetting = StringSetting(key!!, section!!, selection!!) + setting = newSetting + newSetting + } else { + val newSetting = setting as StringSetting + newSetting.value = selection!! + null + } + } +} |