summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorCharles Lombardo <clombardo169@gmail.com>2023-03-08 02:05:01 +0100
committerbunnei <bunneidev@gmail.com>2023-06-03 09:05:37 +0200
commitfd1801aec4a0c1f81c651bc370d6b2a7797767db (patch)
tree17f3aa44819c22952524b3a7d8fe209bb23f8501 /src
parentandroid: Convert SettingViewHolder to Kotlin (diff)
downloadyuzu-fd1801aec4a0c1f81c651bc370d6b2a7797767db.tar
yuzu-fd1801aec4a0c1f81c651bc370d6b2a7797767db.tar.gz
yuzu-fd1801aec4a0c1f81c651bc370d6b2a7797767db.tar.bz2
yuzu-fd1801aec4a0c1f81c651bc370d6b2a7797767db.tar.lz
yuzu-fd1801aec4a0c1f81c651bc370d6b2a7797767db.tar.xz
yuzu-fd1801aec4a0c1f81c651bc370d6b2a7797767db.tar.zst
yuzu-fd1801aec4a0c1f81c651bc370d6b2a7797767db.zip
Diffstat (limited to 'src')
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/viewholder/SingleChoiceViewHolder.java62
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/viewholder/SingleChoiceViewHolder.kt54
2 files changed, 54 insertions, 62 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/viewholder/SingleChoiceViewHolder.java b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/viewholder/SingleChoiceViewHolder.java
deleted file mode 100644
index 539710395..000000000
--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/viewholder/SingleChoiceViewHolder.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package org.yuzu.yuzu_emu.features.settings.ui.viewholder;
-
-import android.content.res.Resources;
-import android.view.View;
-import android.widget.TextView;
-
-import org.yuzu.yuzu_emu.R;
-import org.yuzu.yuzu_emu.features.settings.model.view.SettingsItem;
-import org.yuzu.yuzu_emu.features.settings.model.view.SingleChoiceSetting;
-import org.yuzu.yuzu_emu.features.settings.model.view.StringSingleChoiceSetting;
-import org.yuzu.yuzu_emu.features.settings.ui.SettingsAdapter;
-
-public final class SingleChoiceViewHolder extends SettingViewHolder {
- private SettingsItem mItem;
-
- private TextView mTextSettingName;
- private TextView mTextSettingDescription;
-
- public SingleChoiceViewHolder(View itemView, SettingsAdapter adapter) {
- super(itemView, adapter);
- }
-
- @Override
- protected void findViews(View root) {
- mTextSettingName = root.findViewById(R.id.text_setting_name);
- mTextSettingDescription = root.findViewById(R.id.text_setting_description);
- }
-
- @Override
- public void bind(SettingsItem item) {
- mItem = item;
-
- mTextSettingName.setText(item.getNameId());
- mTextSettingDescription.setVisibility(View.VISIBLE);
- if (item.getDescriptionId() > 0) {
- mTextSettingDescription.setText(item.getDescriptionId());
- } else if (item instanceof SingleChoiceSetting) {
- SingleChoiceSetting setting = (SingleChoiceSetting) item;
- int selected = setting.getSelectedValue();
- Resources resMgr = mTextSettingDescription.getContext().getResources();
- String[] choices = resMgr.getStringArray(setting.getChoicesId());
- int[] values = resMgr.getIntArray(setting.getValuesId());
- for (int i = 0; i < values.length; ++i) {
- if (values[i] == selected) {
- mTextSettingDescription.setText(choices[i]);
- }
- }
- } else {
- mTextSettingDescription.setVisibility(View.GONE);
- }
- }
-
- @Override
- public void onClick(View clicked) {
- int position = getAdapterPosition();
- if (mItem instanceof SingleChoiceSetting) {
- getAdapter().onSingleChoiceClick((SingleChoiceSetting) mItem, position);
- } else if (mItem instanceof StringSingleChoiceSetting) {
- getAdapter().onStringSingleChoiceClick((StringSingleChoiceSetting) mItem, position);
- }
- }
-}
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/viewholder/SingleChoiceViewHolder.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/viewholder/SingleChoiceViewHolder.kt
new file mode 100644
index 000000000..b5b110700
--- /dev/null
+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/viewholder/SingleChoiceViewHolder.kt
@@ -0,0 +1,54 @@
+package org.yuzu.yuzu_emu.features.settings.ui.viewholder
+
+import android.view.View
+import android.widget.TextView
+import org.yuzu.yuzu_emu.R
+import org.yuzu.yuzu_emu.features.settings.model.view.SettingsItem
+import org.yuzu.yuzu_emu.features.settings.model.view.SingleChoiceSetting
+import org.yuzu.yuzu_emu.features.settings.model.view.StringSingleChoiceSetting
+import org.yuzu.yuzu_emu.features.settings.ui.SettingsAdapter
+
+class SingleChoiceViewHolder(itemView: View, adapter: SettingsAdapter) :
+ SettingViewHolder(itemView, adapter) {
+ private lateinit var item: SettingsItem
+ private lateinit var textSettingName: TextView
+ private lateinit var textSettingDescription: TextView
+
+ override fun findViews(root: View) {
+ textSettingName = root.findViewById(R.id.text_setting_name)
+ textSettingDescription = root.findViewById(R.id.text_setting_description)
+ }
+
+ override fun bind(item: SettingsItem) {
+ this.item = item
+ textSettingName.setText(item.nameId)
+ textSettingDescription.visibility = View.VISIBLE
+ if (item.descriptionId!! > 0) {
+ textSettingDescription.setText(item.descriptionId)
+ } else if (item is SingleChoiceSetting) {
+ val resMgr = textSettingDescription.context.resources
+ val values = resMgr.getIntArray(item.valuesId)
+ for (i in values.indices) {
+ if (values[i] == item.selectedValue) {
+ textSettingDescription.text = resMgr.getStringArray(item.choicesId)[i]
+ }
+ }
+ } else {
+ textSettingDescription.visibility = View.GONE
+ }
+ }
+
+ override fun onClick(clicked: View) {
+ if (item is SingleChoiceSetting) {
+ adapter.onSingleChoiceClick(
+ (item as SingleChoiceSetting),
+ bindingAdapterPosition
+ )
+ } else if (item is StringSingleChoiceSetting) {
+ adapter.onStringSingleChoiceClick(
+ (item as StringSingleChoiceSetting),
+ bindingAdapterPosition
+ )
+ }
+ }
+}