summaryrefslogtreecommitdiffstats
path: root/src/android
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/CheckBoxSetting.java80
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/CheckBoxSetting.kt91
2 files changed, 91 insertions, 80 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/CheckBoxSetting.java b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/CheckBoxSetting.java
deleted file mode 100644
index c5c4e14f3..000000000
--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/CheckBoxSetting.java
+++ /dev/null
@@ -1,80 +0,0 @@
-package org.yuzu.yuzu_emu.features.settings.model.view;
-
-import org.yuzu.yuzu_emu.YuzuApplication;
-import org.yuzu.yuzu_emu.R;
-import org.yuzu.yuzu_emu.features.settings.model.BooleanSetting;
-import org.yuzu.yuzu_emu.features.settings.model.IntSetting;
-import org.yuzu.yuzu_emu.features.settings.model.Setting;
-import org.yuzu.yuzu_emu.features.settings.ui.SettingsFragmentView;
-
-public final class CheckBoxSetting extends SettingsItem {
- private boolean mDefaultValue;
- private boolean mShowPerformanceWarning;
- private SettingsFragmentView mView;
-
- public CheckBoxSetting(String key, String section, int titleId, int descriptionId,
- boolean defaultValue, Setting setting) {
- super(key, section, setting, titleId, descriptionId);
- mDefaultValue = defaultValue;
- mShowPerformanceWarning = false;
- }
-
- public CheckBoxSetting(String key, String section, int titleId, int descriptionId,
- boolean defaultValue, Setting setting, boolean show_performance_warning, SettingsFragmentView view) {
- super(key, section, setting, titleId, descriptionId);
- mDefaultValue = defaultValue;
- mView = view;
- mShowPerformanceWarning = show_performance_warning;
- }
-
- public boolean isChecked() {
- if (getSetting() == null) {
- return mDefaultValue;
- }
-
- // Try integer setting
- try {
- IntSetting setting = (IntSetting) getSetting();
- return setting.getValue() == 1;
- } catch (ClassCastException exception) {
- }
-
- // Try boolean setting
- try {
- BooleanSetting setting = (BooleanSetting) getSetting();
- return setting.getValue() == true;
- } catch (ClassCastException exception) {
- }
-
- return mDefaultValue;
- }
-
- /**
- * Write a value to the backing boolean. If that boolean was previously null,
- * initializes a new one and returns it, so it can be added to the Hashmap.
- *
- * @param checked Pretty self explanatory.
- * @return null if overwritten successfully; otherwise, a newly created BooleanSetting.
- */
- public IntSetting setChecked(boolean checked) {
- // Show a performance warning if the setting has been disabled
- if (mShowPerformanceWarning && !checked) {
- mView.showToastMessage(YuzuApplication.getAppContext().getString(R.string.performance_warning), true);
- }
-
- if (getSetting() == null) {
- IntSetting setting = new IntSetting(getKey(), getSection(), checked ? 1 : 0);
- setSetting(setting);
- return setting;
- } else {
- IntSetting setting = (IntSetting) getSetting();
- setting.setValue(checked ? 1 : 0);
- return null;
- }
- }
-
- @Override
- public int getType() {
- return TYPE_CHECKBOX;
- }
-}
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/CheckBoxSetting.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/CheckBoxSetting.kt
new file mode 100644
index 000000000..239dc8e2f
--- /dev/null
+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/CheckBoxSetting.kt
@@ -0,0 +1,91 @@
+package org.yuzu.yuzu_emu.features.settings.model.view
+
+import org.yuzu.yuzu_emu.R
+import org.yuzu.yuzu_emu.YuzuApplication
+import org.yuzu.yuzu_emu.features.settings.model.BooleanSetting
+import org.yuzu.yuzu_emu.features.settings.model.IntSetting
+import org.yuzu.yuzu_emu.features.settings.model.Setting
+import org.yuzu.yuzu_emu.features.settings.ui.SettingsFragmentView
+
+class CheckBoxSetting : SettingsItem {
+ override val type = TYPE_CHECKBOX
+
+ private var defaultValue: Boolean
+ private var showPerformanceWarning: Boolean
+ private var fragmentView: SettingsFragmentView? = null
+
+ constructor(
+ key: String,
+ section: String,
+ setting: Setting?,
+ titleId: Int,
+ descriptionId: Int,
+ defaultValue: Boolean
+ ) : super(key, section, setting, titleId, descriptionId) {
+ this.defaultValue = defaultValue
+ showPerformanceWarning = false
+ }
+
+ constructor(
+ key: String,
+ section: String,
+ titleId: Int,
+ descriptionId: Int,
+ defaultValue: Boolean,
+ setting: Setting,
+ show_performance_warning: Boolean,
+ view: SettingsFragmentView
+ ) : super(key, section, setting, titleId, descriptionId) {
+ this.defaultValue = defaultValue
+ fragmentView = view
+ showPerformanceWarning = show_performance_warning
+ }
+
+ val isChecked: Boolean
+ get() {
+ if (setting == null) {
+ return defaultValue
+ }
+
+ // Try integer setting
+ try {
+ val setting = setting as IntSetting
+ return setting.value == 1
+ } catch (_: ClassCastException) {
+ }
+
+ // Try boolean setting
+ try {
+ val setting = setting as BooleanSetting
+ return setting.value
+ } catch (_: ClassCastException) {
+ }
+ return defaultValue
+ }
+
+ /**
+ * Write a value to the backing boolean. If that boolean was previously null,
+ * initializes a new one and returns it, so it can be added to the Hashmap.
+ *
+ * @param checked Pretty self explanatory.
+ * @return null if overwritten successfully; otherwise, a newly created BooleanSetting.
+ */
+ fun setChecked(checked: Boolean): IntSetting? {
+ // Show a performance warning if the setting has been disabled
+ if (showPerformanceWarning && !checked) {
+ fragmentView!!.showToastMessage(
+ YuzuApplication.appContext.getString(R.string.performance_warning), true
+ )
+ }
+
+ return if (setting == null) {
+ val newSetting = IntSetting(key!!, section!!, if (checked) 1 else 0)
+ setting = newSetting
+ newSetting
+ } else {
+ val newSetting = setting as IntSetting
+ newSetting.value = if (checked) 1 else 0
+ null
+ }
+ }
+}