diff options
| author | 2023-03-07 15:38:08 -0500 | |
|---|---|---|
| committer | 2023-06-03 00:05:35 -0700 | |
| commit | 4d9cfc67981fecf1dc56cde71026f6ee66969cd3 (patch) | |
| tree | 1a3299490b097e589823e38cc7ef57550ba05564 /src/android/app | |
| parent | android: Convert GameAdapter to Kotlin (diff) | |
| download | yuzu-4d9cfc67981fecf1dc56cde71026f6ee66969cd3.tar.gz yuzu-4d9cfc67981fecf1dc56cde71026f6ee66969cd3.tar.xz yuzu-4d9cfc67981fecf1dc56cde71026f6ee66969cd3.zip | |
android: Convert CheckBoxSetting to Kotlin
Diffstat (limited to 'src/android/app')
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 @@ | |||
| 1 | package org.yuzu.yuzu_emu.features.settings.model.view; | ||
| 2 | |||
| 3 | import org.yuzu.yuzu_emu.YuzuApplication; | ||
| 4 | import org.yuzu.yuzu_emu.R; | ||
| 5 | import org.yuzu.yuzu_emu.features.settings.model.BooleanSetting; | ||
| 6 | import org.yuzu.yuzu_emu.features.settings.model.IntSetting; | ||
| 7 | import org.yuzu.yuzu_emu.features.settings.model.Setting; | ||
| 8 | import org.yuzu.yuzu_emu.features.settings.ui.SettingsFragmentView; | ||
| 9 | |||
| 10 | public final class CheckBoxSetting extends SettingsItem { | ||
| 11 | private boolean mDefaultValue; | ||
| 12 | private boolean mShowPerformanceWarning; | ||
| 13 | private SettingsFragmentView mView; | ||
| 14 | |||
| 15 | public CheckBoxSetting(String key, String section, int titleId, int descriptionId, | ||
| 16 | boolean defaultValue, Setting setting) { | ||
| 17 | super(key, section, setting, titleId, descriptionId); | ||
| 18 | mDefaultValue = defaultValue; | ||
| 19 | mShowPerformanceWarning = false; | ||
| 20 | } | ||
| 21 | |||
| 22 | public CheckBoxSetting(String key, String section, int titleId, int descriptionId, | ||
| 23 | boolean defaultValue, Setting setting, boolean show_performance_warning, SettingsFragmentView view) { | ||
| 24 | super(key, section, setting, titleId, descriptionId); | ||
| 25 | mDefaultValue = defaultValue; | ||
| 26 | mView = view; | ||
| 27 | mShowPerformanceWarning = show_performance_warning; | ||
| 28 | } | ||
| 29 | |||
| 30 | public boolean isChecked() { | ||
| 31 | if (getSetting() == null) { | ||
| 32 | return mDefaultValue; | ||
| 33 | } | ||
| 34 | |||
| 35 | // Try integer setting | ||
| 36 | try { | ||
| 37 | IntSetting setting = (IntSetting) getSetting(); | ||
| 38 | return setting.getValue() == 1; | ||
| 39 | } catch (ClassCastException exception) { | ||
| 40 | } | ||
| 41 | |||
| 42 | // Try boolean setting | ||
| 43 | try { | ||
| 44 | BooleanSetting setting = (BooleanSetting) getSetting(); | ||
| 45 | return setting.getValue() == true; | ||
| 46 | } catch (ClassCastException exception) { | ||
| 47 | } | ||
| 48 | |||
| 49 | return mDefaultValue; | ||
| 50 | } | ||
| 51 | |||
| 52 | /** | ||
| 53 | * Write a value to the backing boolean. If that boolean was previously null, | ||
| 54 | * initializes a new one and returns it, so it can be added to the Hashmap. | ||
| 55 | * | ||
| 56 | * @param checked Pretty self explanatory. | ||
| 57 | * @return null if overwritten successfully; otherwise, a newly created BooleanSetting. | ||
| 58 | */ | ||
| 59 | public IntSetting setChecked(boolean checked) { | ||
| 60 | // Show a performance warning if the setting has been disabled | ||
| 61 | if (mShowPerformanceWarning && !checked) { | ||
| 62 | mView.showToastMessage(YuzuApplication.getAppContext().getString(R.string.performance_warning), true); | ||
| 63 | } | ||
| 64 | |||
| 65 | if (getSetting() == null) { | ||
| 66 | IntSetting setting = new IntSetting(getKey(), getSection(), checked ? 1 : 0); | ||
| 67 | setSetting(setting); | ||
| 68 | return setting; | ||
| 69 | } else { | ||
| 70 | IntSetting setting = (IntSetting) getSetting(); | ||
| 71 | setting.setValue(checked ? 1 : 0); | ||
| 72 | return null; | ||
| 73 | } | ||
| 74 | } | ||
| 75 | |||
| 76 | @Override | ||
| 77 | public int getType() { | ||
| 78 | return TYPE_CHECKBOX; | ||
| 79 | } | ||
| 80 | } | ||
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 @@ | |||
| 1 | package org.yuzu.yuzu_emu.features.settings.model.view | ||
| 2 | |||
| 3 | import org.yuzu.yuzu_emu.R | ||
| 4 | import org.yuzu.yuzu_emu.YuzuApplication | ||
| 5 | import org.yuzu.yuzu_emu.features.settings.model.BooleanSetting | ||
| 6 | import org.yuzu.yuzu_emu.features.settings.model.IntSetting | ||
| 7 | import org.yuzu.yuzu_emu.features.settings.model.Setting | ||
| 8 | import org.yuzu.yuzu_emu.features.settings.ui.SettingsFragmentView | ||
| 9 | |||
| 10 | class CheckBoxSetting : SettingsItem { | ||
| 11 | override val type = TYPE_CHECKBOX | ||
| 12 | |||
| 13 | private var defaultValue: Boolean | ||
| 14 | private var showPerformanceWarning: Boolean | ||
| 15 | private var fragmentView: SettingsFragmentView? = null | ||
| 16 | |||
| 17 | constructor( | ||
| 18 | key: String, | ||
| 19 | section: String, | ||
| 20 | setting: Setting?, | ||
| 21 | titleId: Int, | ||
| 22 | descriptionId: Int, | ||
| 23 | defaultValue: Boolean | ||
| 24 | ) : super(key, section, setting, titleId, descriptionId) { | ||
| 25 | this.defaultValue = defaultValue | ||
| 26 | showPerformanceWarning = false | ||
| 27 | } | ||
| 28 | |||
| 29 | constructor( | ||
| 30 | key: String, | ||
| 31 | section: String, | ||
| 32 | titleId: Int, | ||
| 33 | descriptionId: Int, | ||
| 34 | defaultValue: Boolean, | ||
| 35 | setting: Setting, | ||
| 36 | show_performance_warning: Boolean, | ||
| 37 | view: SettingsFragmentView | ||
| 38 | ) : super(key, section, setting, titleId, descriptionId) { | ||
| 39 | this.defaultValue = defaultValue | ||
| 40 | fragmentView = view | ||
| 41 | showPerformanceWarning = show_performance_warning | ||
| 42 | } | ||
| 43 | |||
| 44 | val isChecked: Boolean | ||
| 45 | get() { | ||
| 46 | if (setting == null) { | ||
| 47 | return defaultValue | ||
| 48 | } | ||
| 49 | |||
| 50 | // Try integer setting | ||
| 51 | try { | ||
| 52 | val setting = setting as IntSetting | ||
| 53 | return setting.value == 1 | ||
| 54 | } catch (_: ClassCastException) { | ||
| 55 | } | ||
| 56 | |||
| 57 | // Try boolean setting | ||
| 58 | try { | ||
| 59 | val setting = setting as BooleanSetting | ||
| 60 | return setting.value | ||
| 61 | } catch (_: ClassCastException) { | ||
| 62 | } | ||
| 63 | return defaultValue | ||
| 64 | } | ||
| 65 | |||
| 66 | /** | ||
| 67 | * Write a value to the backing boolean. If that boolean was previously null, | ||
| 68 | * initializes a new one and returns it, so it can be added to the Hashmap. | ||
| 69 | * | ||
| 70 | * @param checked Pretty self explanatory. | ||
| 71 | * @return null if overwritten successfully; otherwise, a newly created BooleanSetting. | ||
| 72 | */ | ||
| 73 | fun setChecked(checked: Boolean): IntSetting? { | ||
| 74 | // Show a performance warning if the setting has been disabled | ||
| 75 | if (showPerformanceWarning && !checked) { | ||
| 76 | fragmentView!!.showToastMessage( | ||
| 77 | YuzuApplication.appContext.getString(R.string.performance_warning), true | ||
| 78 | ) | ||
| 79 | } | ||
| 80 | |||
| 81 | return if (setting == null) { | ||
| 82 | val newSetting = IntSetting(key!!, section!!, if (checked) 1 else 0) | ||
| 83 | setting = newSetting | ||
| 84 | newSetting | ||
| 85 | } else { | ||
| 86 | val newSetting = setting as IntSetting | ||
| 87 | newSetting.value = if (checked) 1 else 0 | ||
| 88 | null | ||
| 89 | } | ||
| 90 | } | ||
| 91 | } | ||