summaryrefslogtreecommitdiff
path: root/src/android
diff options
context:
space:
mode:
authorGravatar Charles Lombardo2023-03-07 16:43:07 -0500
committerGravatar bunnei2023-06-03 00:05:36 -0700
commit89eed93ce0d92f917fb6b71520d203e8dd4d4de0 (patch)
tree12210bc4362645c98e53bd420f0eb3703636d89c /src/android
parentandroid: Convert SingleChoiceSetting to Kotlin (diff)
downloadyuzu-89eed93ce0d92f917fb6b71520d203e8dd4d4de0.tar.gz
yuzu-89eed93ce0d92f917fb6b71520d203e8dd4d4de0.tar.xz
yuzu-89eed93ce0d92f917fb6b71520d203e8dd4d4de0.zip
android: Convert SliderSetting to Kotlin
Diffstat (limited to 'src/android')
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SliderSetting.java101
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SliderSetting.kt72
2 files changed, 72 insertions, 101 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SliderSetting.java b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SliderSetting.java
deleted file mode 100644
index 8ac25b66e..000000000
--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SliderSetting.java
+++ /dev/null
@@ -1,101 +0,0 @@
1package org.yuzu.yuzu_emu.features.settings.model.view;
2
3import org.yuzu.yuzu_emu.features.settings.model.FloatSetting;
4import org.yuzu.yuzu_emu.features.settings.model.IntSetting;
5import org.yuzu.yuzu_emu.features.settings.model.Setting;
6import org.yuzu.yuzu_emu.utils.Log;
7
8public final class SliderSetting extends SettingsItem {
9 private int mMin;
10 private int mMax;
11 private int mDefaultValue;
12
13 private String mUnits;
14
15 public SliderSetting(String key, String section, int titleId, int descriptionId,
16 int min, int max, String units, int defaultValue, Setting setting) {
17 super(key, section, setting, titleId, descriptionId);
18 mMin = min;
19 mMax = max;
20 mUnits = units;
21 mDefaultValue = defaultValue;
22 }
23
24 public int getMin() {
25 return mMin;
26 }
27
28 public int getMax() {
29 return mMax;
30 }
31
32 public int getDefaultValue() {
33 return mDefaultValue;
34 }
35
36 public int getSelectedValue() {
37 Setting setting = getSetting();
38
39 if (setting == null) {
40 return mDefaultValue;
41 }
42
43 if (setting instanceof IntSetting) {
44 IntSetting intSetting = (IntSetting) setting;
45 return intSetting.getValue();
46 } else if (setting instanceof FloatSetting) {
47 FloatSetting floatSetting = (FloatSetting) setting;
48 return Math.round(floatSetting.getValue());
49 } else {
50 Log.error("[SliderSetting] Error casting setting type.");
51 return -1;
52 }
53 }
54
55 /**
56 * Write a value to the backing int. If that int was previously null,
57 * initializes a new one and returns it, so it can be added to the Hashmap.
58 *
59 * @param selection New value of the int.
60 * @return null if overwritten successfully otherwise; a newly created IntSetting.
61 */
62 public IntSetting setSelectedValue(int selection) {
63 if (getSetting() == null) {
64 IntSetting setting = new IntSetting(getKey(), getSection(), selection);
65 setSetting(setting);
66 return setting;
67 } else {
68 IntSetting setting = (IntSetting) getSetting();
69 setting.setValue(selection);
70 return null;
71 }
72 }
73
74 /**
75 * Write a value to the backing float. If that float was previously null,
76 * initializes a new one and returns it, so it can be added to the Hashmap.
77 *
78 * @param selection New value of the float.
79 * @return null if overwritten successfully otherwise; a newly created FloatSetting.
80 */
81 public FloatSetting setSelectedValue(float selection) {
82 if (getSetting() == null) {
83 FloatSetting setting = new FloatSetting(getKey(), getSection(), selection);
84 setSetting(setting);
85 return setting;
86 } else {
87 FloatSetting setting = (FloatSetting) getSetting();
88 setting.setValue(selection);
89 return null;
90 }
91 }
92
93 public String getUnits() {
94 return mUnits;
95 }
96
97 @Override
98 public int getType() {
99 return TYPE_SLIDER;
100 }
101}
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SliderSetting.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SliderSetting.kt
new file mode 100644
index 000000000..625ae1f69
--- /dev/null
+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SliderSetting.kt
@@ -0,0 +1,72 @@
1package org.yuzu.yuzu_emu.features.settings.model.view
2
3import org.yuzu.yuzu_emu.features.settings.model.FloatSetting
4import org.yuzu.yuzu_emu.features.settings.model.IntSetting
5import org.yuzu.yuzu_emu.features.settings.model.Setting
6import org.yuzu.yuzu_emu.utils.Log
7import kotlin.math.roundToInt
8
9class SliderSetting(
10 key: String,
11 section: String,
12 setting: Setting?,
13 titleId: Int,
14 descriptionId: Int,
15 val min: Int,
16 val max: Int,
17 val units: String,
18 val defaultValue: Int,
19) : SettingsItem(key, section, setting, titleId, descriptionId) {
20 override val type = TYPE_SLIDER
21
22 val selectedValue: Int
23 get() {
24 val setting = setting ?: return defaultValue
25 return when (setting) {
26 is IntSetting -> setting.value
27 is FloatSetting -> setting.value.roundToInt()
28 else -> {
29 Log.error("[SliderSetting] Error casting setting type.")
30 -1
31 }
32 }
33 }
34
35 /**
36 * Write a value to the backing int. If that int was previously null,
37 * initializes a new one and returns it, so it can be added to the Hashmap.
38 *
39 * @param selection New value of the int.
40 * @return null if overwritten successfully otherwise; a newly created IntSetting.
41 */
42 fun setSelectedValue(selection: Int): IntSetting? {
43 return if (setting == null) {
44 val newSetting = IntSetting(key!!, section!!, selection)
45 setting = newSetting
46 newSetting
47 } else {
48 val newSetting = setting as IntSetting
49 newSetting.value = selection
50 null
51 }
52 }
53
54 /**
55 * Write a value to the backing float. If that float was previously null,
56 * initializes a new one and returns it, so it can be added to the Hashmap.
57 *
58 * @param selection New value of the float.
59 * @return null if overwritten successfully otherwise; a newly created FloatSetting.
60 */
61 fun setSelectedValue(selection: Float): FloatSetting? {
62 return if (setting == null) {
63 val newSetting = FloatSetting(key!!, section!!, selection)
64 setting = newSetting
65 newSetting
66 } else {
67 val newSetting = setting as FloatSetting
68 newSetting.value = selection
69 null
70 }
71 }
72}