summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCharles Lombardo <clombardo169@gmail.com>2023-03-07 22:43:07 +0100
committerbunnei <bunneidev@gmail.com>2023-06-03 09:05:36 +0200
commit89eed93ce0d92f917fb6b71520d203e8dd4d4de0 (patch)
tree12210bc4362645c98e53bd420f0eb3703636d89c
parentandroid: Convert SingleChoiceSetting to Kotlin (diff)
downloadyuzu-89eed93ce0d92f917fb6b71520d203e8dd4d4de0.tar
yuzu-89eed93ce0d92f917fb6b71520d203e8dd4d4de0.tar.gz
yuzu-89eed93ce0d92f917fb6b71520d203e8dd4d4de0.tar.bz2
yuzu-89eed93ce0d92f917fb6b71520d203e8dd4d4de0.tar.lz
yuzu-89eed93ce0d92f917fb6b71520d203e8dd4d4de0.tar.xz
yuzu-89eed93ce0d92f917fb6b71520d203e8dd4d4de0.tar.zst
yuzu-89eed93ce0d92f917fb6b71520d203e8dd4d4de0.zip
-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 @@
-package org.yuzu.yuzu_emu.features.settings.model.view;
-
-import org.yuzu.yuzu_emu.features.settings.model.FloatSetting;
-import org.yuzu.yuzu_emu.features.settings.model.IntSetting;
-import org.yuzu.yuzu_emu.features.settings.model.Setting;
-import org.yuzu.yuzu_emu.utils.Log;
-
-public final class SliderSetting extends SettingsItem {
- private int mMin;
- private int mMax;
- private int mDefaultValue;
-
- private String mUnits;
-
- public SliderSetting(String key, String section, int titleId, int descriptionId,
- int min, int max, String units, int defaultValue, Setting setting) {
- super(key, section, setting, titleId, descriptionId);
- mMin = min;
- mMax = max;
- mUnits = units;
- mDefaultValue = defaultValue;
- }
-
- public int getMin() {
- return mMin;
- }
-
- public int getMax() {
- return mMax;
- }
-
- public int getDefaultValue() {
- return mDefaultValue;
- }
-
- public int getSelectedValue() {
- Setting setting = getSetting();
-
- if (setting == null) {
- return mDefaultValue;
- }
-
- if (setting instanceof IntSetting) {
- IntSetting intSetting = (IntSetting) setting;
- return intSetting.getValue();
- } else if (setting instanceof FloatSetting) {
- FloatSetting floatSetting = (FloatSetting) setting;
- return Math.round(floatSetting.getValue());
- } else {
- Log.error("[SliderSetting] Error casting setting type.");
- 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 IntSetting setSelectedValue(int selection) {
- if (getSetting() == null) {
- IntSetting setting = new IntSetting(getKey(), getSection(), selection);
- setSetting(setting);
- return setting;
- } else {
- IntSetting setting = (IntSetting) getSetting();
- setting.setValue(selection);
- return null;
- }
- }
-
- /**
- * Write a value to the backing float. If that float was previously null,
- * initializes a new one and returns it, so it can be added to the Hashmap.
- *
- * @param selection New value of the float.
- * @return null if overwritten successfully otherwise; a newly created FloatSetting.
- */
- public FloatSetting setSelectedValue(float selection) {
- if (getSetting() == null) {
- FloatSetting setting = new FloatSetting(getKey(), getSection(), selection);
- setSetting(setting);
- return setting;
- } else {
- FloatSetting setting = (FloatSetting) getSetting();
- setting.setValue(selection);
- return null;
- }
- }
-
- public String getUnits() {
- return mUnits;
- }
-
- @Override
- public int getType() {
- return TYPE_SLIDER;
- }
-}
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 @@
+package org.yuzu.yuzu_emu.features.settings.model.view
+
+import org.yuzu.yuzu_emu.features.settings.model.FloatSetting
+import org.yuzu.yuzu_emu.features.settings.model.IntSetting
+import org.yuzu.yuzu_emu.features.settings.model.Setting
+import org.yuzu.yuzu_emu.utils.Log
+import kotlin.math.roundToInt
+
+class SliderSetting(
+ key: String,
+ section: String,
+ setting: Setting?,
+ titleId: Int,
+ descriptionId: Int,
+ val min: Int,
+ val max: Int,
+ val units: String,
+ val defaultValue: Int,
+) : SettingsItem(key, section, setting, titleId, descriptionId) {
+ override val type = TYPE_SLIDER
+
+ val selectedValue: Int
+ get() {
+ val setting = setting ?: return defaultValue
+ return when (setting) {
+ is IntSetting -> setting.value
+ is FloatSetting -> setting.value.roundToInt()
+ else -> {
+ Log.error("[SliderSetting] Error casting setting type.")
+ -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: Int): IntSetting? {
+ return if (setting == null) {
+ val newSetting = IntSetting(key!!, section!!, selection)
+ setting = newSetting
+ newSetting
+ } else {
+ val newSetting = setting as IntSetting
+ newSetting.value = selection
+ null
+ }
+ }
+
+ /**
+ * Write a value to the backing float. If that float was previously null,
+ * initializes a new one and returns it, so it can be added to the Hashmap.
+ *
+ * @param selection New value of the float.
+ * @return null if overwritten successfully otherwise; a newly created FloatSetting.
+ */
+ fun setSelectedValue(selection: Float): FloatSetting? {
+ return if (setting == null) {
+ val newSetting = FloatSetting(key!!, section!!, selection)
+ setting = newSetting
+ newSetting
+ } else {
+ val newSetting = setting as FloatSetting
+ newSetting.value = selection
+ null
+ }
+ }
+}