summaryrefslogtreecommitdiff
path: root/src/android
diff options
context:
space:
mode:
authorGravatar Charles Lombardo2023-03-07 16:36:14 -0500
committerGravatar bunnei2023-06-03 00:05:35 -0700
commita0e91e3a93673d6478ecaa7eea158b2289d61f97 (patch)
treeae0af9c79ffff978679563692345772ae2e7e19e /src/android
parentandroid: Convert SettingsItem to Kotlin (diff)
downloadyuzu-a0e91e3a93673d6478ecaa7eea158b2289d61f97.tar.gz
yuzu-a0e91e3a93673d6478ecaa7eea158b2289d61f97.tar.xz
yuzu-a0e91e3a93673d6478ecaa7eea158b2289d61f97.zip
android: Convert SingleChoiceSetting to Kotlin
Diffstat (limited to 'src/android')
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SingleChoiceSetting.java60
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SingleChoiceSetting.kt44
2 files changed, 44 insertions, 60 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SingleChoiceSetting.java b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SingleChoiceSetting.java
deleted file mode 100644
index 619df6d52..000000000
--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SingleChoiceSetting.java
+++ /dev/null
@@ -1,60 +0,0 @@
1package org.yuzu.yuzu_emu.features.settings.model.view;
2
3import org.yuzu.yuzu_emu.features.settings.model.IntSetting;
4import org.yuzu.yuzu_emu.features.settings.model.Setting;
5
6public final class SingleChoiceSetting extends SettingsItem {
7 private int mDefaultValue;
8
9 private int mChoicesId;
10 private int mValuesId;
11
12 public SingleChoiceSetting(String key, String section, int titleId, int descriptionId,
13 int choicesId, int valuesId, int defaultValue, Setting setting) {
14 super(key, section, setting, titleId, descriptionId);
15 mValuesId = valuesId;
16 mChoicesId = choicesId;
17 mDefaultValue = defaultValue;
18 }
19
20 public int getChoicesId() {
21 return mChoicesId;
22 }
23
24 public int getValuesId() {
25 return mValuesId;
26 }
27
28 public int getSelectedValue() {
29 if (getSetting() != null) {
30 IntSetting setting = (IntSetting) getSetting();
31 return setting.getValue();
32 } else {
33 return mDefaultValue;
34 }
35 }
36
37 /**
38 * Write a value to the backing int. If that int was previously null,
39 * initializes a new one and returns it, so it can be added to the Hashmap.
40 *
41 * @param selection New value of the int.
42 * @return null if overwritten successfully otherwise; a newly created IntSetting.
43 */
44 public IntSetting setSelectedValue(int selection) {
45 if (getSetting() == null) {
46 IntSetting setting = new IntSetting(getKey(), getSection(), selection);
47 setSetting(setting);
48 return setting;
49 } else {
50 IntSetting setting = (IntSetting) getSetting();
51 setting.setValue(selection);
52 return null;
53 }
54 }
55
56 @Override
57 public int getType() {
58 return TYPE_SINGLE_CHOICE;
59 }
60}
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SingleChoiceSetting.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SingleChoiceSetting.kt
new file mode 100644
index 000000000..060d324c1
--- /dev/null
+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SingleChoiceSetting.kt
@@ -0,0 +1,44 @@
1package org.yuzu.yuzu_emu.features.settings.model.view
2
3import org.yuzu.yuzu_emu.features.settings.model.IntSetting
4import org.yuzu.yuzu_emu.features.settings.model.Setting
5
6class SingleChoiceSetting(
7 key: String,
8 section: String,
9 setting: Setting?,
10 titleId: Int,
11 descriptionId: Int,
12 val choicesId: Int,
13 val valuesId: Int,
14 private val defaultValue: Int,
15) : SettingsItem(key, section, setting, titleId, descriptionId) {
16 override val type = TYPE_SINGLE_CHOICE
17
18 val selectedValue: Int
19 get() = if (setting != null) {
20 val setting = setting as IntSetting
21 setting.value
22 } else {
23 defaultValue
24 }
25
26 /**
27 * Write a value to the backing int. If that int was previously null,
28 * initializes a new one and returns it, so it can be added to the Hashmap.
29 *
30 * @param selection New value of the int.
31 * @return null if overwritten successfully otherwise; a newly created IntSetting.
32 */
33 fun setSelectedValue(selection: Int): IntSetting? {
34 return if (setting == null) {
35 val newSetting = IntSetting(key!!, section!!, selection)
36 setting = newSetting
37 newSetting
38 } else {
39 val newSetting = setting as IntSetting
40 newSetting.value = selection
41 null
42 }
43 }
44}