diff options
| author | 2023-03-07 16:59:00 -0500 | |
|---|---|---|
| committer | 2023-06-03 00:05:36 -0700 | |
| commit | 91884976a1c41ffe7f24cabf9fd92139d376d498 (patch) | |
| tree | 76722100e8e46c28c67d8ffc1a05129b7ff6b4fb /src/android/app | |
| parent | android: Convert SliderSetting to Kotlin (diff) | |
| download | yuzu-91884976a1c41ffe7f24cabf9fd92139d376d498.tar.gz yuzu-91884976a1c41ffe7f24cabf9fd92139d376d498.tar.xz yuzu-91884976a1c41ffe7f24cabf9fd92139d376d498.zip | |
android: Convert StringSingleChoiceSetting to Kotlin
Diffstat (limited to 'src/android/app')
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 @@ | |||
| 1 | package org.yuzu.yuzu_emu.features.settings.model.view; | ||
| 2 | |||
| 3 | import org.yuzu.yuzu_emu.features.settings.model.Setting; | ||
| 4 | import org.yuzu.yuzu_emu.features.settings.model.StringSetting; | ||
| 5 | |||
| 6 | public class StringSingleChoiceSetting extends SettingsItem { | ||
| 7 | private String mDefaultValue; | ||
| 8 | |||
| 9 | private String[] mChoicesId; | ||
| 10 | private String[] mValuesId; | ||
| 11 | |||
| 12 | public StringSingleChoiceSetting(String key, String section, int titleId, int descriptionId, | ||
| 13 | String[] choicesId, String[] valuesId, String defaultValue, Setting setting) { | ||
| 14 | super(key, section, setting, titleId, descriptionId); | ||
| 15 | mValuesId = valuesId; | ||
| 16 | mChoicesId = choicesId; | ||
| 17 | mDefaultValue = defaultValue; | ||
| 18 | } | ||
| 19 | |||
| 20 | public String[] getChoicesId() { | ||
| 21 | return mChoicesId; | ||
| 22 | } | ||
| 23 | |||
| 24 | public String[] getValuesId() { | ||
| 25 | return mValuesId; | ||
| 26 | } | ||
| 27 | |||
| 28 | public String getValueAt(int index) { | ||
| 29 | if (mValuesId == null) | ||
| 30 | return null; | ||
| 31 | |||
| 32 | if (index >= 0 && index < mValuesId.length) { | ||
| 33 | return mValuesId[index]; | ||
| 34 | } | ||
| 35 | |||
| 36 | return ""; | ||
| 37 | } | ||
| 38 | |||
| 39 | public String getSelectedValue() { | ||
| 40 | if (getSetting() != null) { | ||
| 41 | StringSetting setting = (StringSetting) getSetting(); | ||
| 42 | return setting.getValue(); | ||
| 43 | } else { | ||
| 44 | return mDefaultValue; | ||
| 45 | } | ||
| 46 | } | ||
| 47 | |||
| 48 | public int getSelectValueIndex() { | ||
| 49 | String selectedValue = getSelectedValue(); | ||
| 50 | for (int i = 0; i < mValuesId.length; i++) { | ||
| 51 | if (mValuesId[i].equals(selectedValue)) { | ||
| 52 | return i; | ||
| 53 | } | ||
| 54 | } | ||
| 55 | |||
| 56 | return -1; | ||
| 57 | } | ||
| 58 | |||
| 59 | /** | ||
| 60 | * Write a value to the backing int. If that int was previously null, | ||
| 61 | * initializes a new one and returns it, so it can be added to the Hashmap. | ||
| 62 | * | ||
| 63 | * @param selection New value of the int. | ||
| 64 | * @return null if overwritten successfully otherwise; a newly created IntSetting. | ||
| 65 | */ | ||
| 66 | public StringSetting setSelectedValue(String selection) { | ||
| 67 | if (getSetting() == null) { | ||
| 68 | StringSetting setting = new StringSetting(getKey(), getSection(), selection); | ||
| 69 | setSetting(setting); | ||
| 70 | return setting; | ||
| 71 | } else { | ||
| 72 | StringSetting setting = (StringSetting) getSetting(); | ||
| 73 | setting.setValue(selection); | ||
| 74 | return null; | ||
| 75 | } | ||
| 76 | } | ||
| 77 | |||
| 78 | @Override | ||
| 79 | public int getType() { | ||
| 80 | return TYPE_STRING_SINGLE_CHOICE; | ||
| 81 | } | ||
| 82 | } | ||
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 @@ | |||
| 1 | package org.yuzu.yuzu_emu.features.settings.model.view | ||
| 2 | |||
| 3 | import org.yuzu.yuzu_emu.features.settings.model.Setting | ||
| 4 | import org.yuzu.yuzu_emu.features.settings.model.StringSetting | ||
| 5 | |||
| 6 | class StringSingleChoiceSetting( | ||
| 7 | key: String, | ||
| 8 | section: String, | ||
| 9 | setting: Setting?, | ||
| 10 | titleId: Int, | ||
| 11 | descriptionId: Int, | ||
| 12 | val choicesId: Array<String>, | ||
| 13 | private val valuesId: Array<String>?, | ||
| 14 | private val defaultValue: String | ||
| 15 | ) : SettingsItem(key, section, setting, titleId, descriptionId) { | ||
| 16 | override val type = TYPE_STRING_SINGLE_CHOICE | ||
| 17 | |||
| 18 | fun getValueAt(index: Int): String? { | ||
| 19 | if (valuesId == null) return null | ||
| 20 | return if (index >= 0 && index < valuesId.size) { | ||
| 21 | valuesId[index] | ||
| 22 | } else "" | ||
| 23 | } | ||
| 24 | |||
| 25 | val selectedValue: String | ||
| 26 | get() = if (setting != null) { | ||
| 27 | val setting = setting as StringSetting | ||
| 28 | setting.value | ||
| 29 | } else { | ||
| 30 | defaultValue | ||
| 31 | } | ||
| 32 | val selectValueIndex: Int | ||
| 33 | get() { | ||
| 34 | val selectedValue = selectedValue | ||
| 35 | for (i in valuesId!!.indices) { | ||
| 36 | if (valuesId[i] == selectedValue) { | ||
| 37 | return i | ||
| 38 | } | ||
| 39 | } | ||
| 40 | return -1 | ||
| 41 | } | ||
| 42 | |||
| 43 | /** | ||
| 44 | * Write a value to the backing int. If that int was previously null, | ||
| 45 | * initializes a new one and returns it, so it can be added to the Hashmap. | ||
| 46 | * | ||
| 47 | * @param selection New value of the int. | ||
| 48 | * @return null if overwritten successfully otherwise; a newly created IntSetting. | ||
| 49 | */ | ||
| 50 | fun setSelectedValue(selection: String?): StringSetting? { | ||
| 51 | return if (setting == null) { | ||
| 52 | val newSetting = StringSetting(key!!, section!!, selection!!) | ||
| 53 | setting = newSetting | ||
| 54 | newSetting | ||
| 55 | } else { | ||
| 56 | val newSetting = setting as StringSetting | ||
| 57 | newSetting.value = selection!! | ||
| 58 | null | ||
| 59 | } | ||
| 60 | } | ||
| 61 | } | ||