diff options
| author | 2023-03-07 20:05:01 -0500 | |
|---|---|---|
| committer | 2023-06-03 00:05:37 -0700 | |
| commit | fd1801aec4a0c1f81c651bc370d6b2a7797767db (patch) | |
| tree | 17f3aa44819c22952524b3a7d8fe209bb23f8501 /src/android | |
| parent | android: Convert SettingViewHolder to Kotlin (diff) | |
| download | yuzu-fd1801aec4a0c1f81c651bc370d6b2a7797767db.tar.gz yuzu-fd1801aec4a0c1f81c651bc370d6b2a7797767db.tar.xz yuzu-fd1801aec4a0c1f81c651bc370d6b2a7797767db.zip | |
android: Convert SingleChoiceViewHolder to Kotlin
Diffstat (limited to 'src/android')
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 @@ | |||
| 1 | package org.yuzu.yuzu_emu.features.settings.ui.viewholder; | ||
| 2 | |||
| 3 | import android.content.res.Resources; | ||
| 4 | import android.view.View; | ||
| 5 | import android.widget.TextView; | ||
| 6 | |||
| 7 | import org.yuzu.yuzu_emu.R; | ||
| 8 | import org.yuzu.yuzu_emu.features.settings.model.view.SettingsItem; | ||
| 9 | import org.yuzu.yuzu_emu.features.settings.model.view.SingleChoiceSetting; | ||
| 10 | import org.yuzu.yuzu_emu.features.settings.model.view.StringSingleChoiceSetting; | ||
| 11 | import org.yuzu.yuzu_emu.features.settings.ui.SettingsAdapter; | ||
| 12 | |||
| 13 | public final class SingleChoiceViewHolder extends SettingViewHolder { | ||
| 14 | private SettingsItem mItem; | ||
| 15 | |||
| 16 | private TextView mTextSettingName; | ||
| 17 | private TextView mTextSettingDescription; | ||
| 18 | |||
| 19 | public SingleChoiceViewHolder(View itemView, SettingsAdapter adapter) { | ||
| 20 | super(itemView, adapter); | ||
| 21 | } | ||
| 22 | |||
| 23 | @Override | ||
| 24 | protected void findViews(View root) { | ||
| 25 | mTextSettingName = root.findViewById(R.id.text_setting_name); | ||
| 26 | mTextSettingDescription = root.findViewById(R.id.text_setting_description); | ||
| 27 | } | ||
| 28 | |||
| 29 | @Override | ||
| 30 | public void bind(SettingsItem item) { | ||
| 31 | mItem = item; | ||
| 32 | |||
| 33 | mTextSettingName.setText(item.getNameId()); | ||
| 34 | mTextSettingDescription.setVisibility(View.VISIBLE); | ||
| 35 | if (item.getDescriptionId() > 0) { | ||
| 36 | mTextSettingDescription.setText(item.getDescriptionId()); | ||
| 37 | } else if (item instanceof SingleChoiceSetting) { | ||
| 38 | SingleChoiceSetting setting = (SingleChoiceSetting) item; | ||
| 39 | int selected = setting.getSelectedValue(); | ||
| 40 | Resources resMgr = mTextSettingDescription.getContext().getResources(); | ||
| 41 | String[] choices = resMgr.getStringArray(setting.getChoicesId()); | ||
| 42 | int[] values = resMgr.getIntArray(setting.getValuesId()); | ||
| 43 | for (int i = 0; i < values.length; ++i) { | ||
| 44 | if (values[i] == selected) { | ||
| 45 | mTextSettingDescription.setText(choices[i]); | ||
| 46 | } | ||
| 47 | } | ||
| 48 | } else { | ||
| 49 | mTextSettingDescription.setVisibility(View.GONE); | ||
| 50 | } | ||
| 51 | } | ||
| 52 | |||
| 53 | @Override | ||
| 54 | public void onClick(View clicked) { | ||
| 55 | int position = getAdapterPosition(); | ||
| 56 | if (mItem instanceof SingleChoiceSetting) { | ||
| 57 | getAdapter().onSingleChoiceClick((SingleChoiceSetting) mItem, position); | ||
| 58 | } else if (mItem instanceof StringSingleChoiceSetting) { | ||
| 59 | getAdapter().onStringSingleChoiceClick((StringSingleChoiceSetting) mItem, position); | ||
| 60 | } | ||
| 61 | } | ||
| 62 | } | ||
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 @@ | |||
| 1 | package org.yuzu.yuzu_emu.features.settings.ui.viewholder | ||
| 2 | |||
| 3 | import android.view.View | ||
| 4 | import android.widget.TextView | ||
| 5 | import org.yuzu.yuzu_emu.R | ||
| 6 | import org.yuzu.yuzu_emu.features.settings.model.view.SettingsItem | ||
| 7 | import org.yuzu.yuzu_emu.features.settings.model.view.SingleChoiceSetting | ||
| 8 | import org.yuzu.yuzu_emu.features.settings.model.view.StringSingleChoiceSetting | ||
| 9 | import org.yuzu.yuzu_emu.features.settings.ui.SettingsAdapter | ||
| 10 | |||
| 11 | class SingleChoiceViewHolder(itemView: View, adapter: SettingsAdapter) : | ||
| 12 | SettingViewHolder(itemView, adapter) { | ||
| 13 | private lateinit var item: SettingsItem | ||
| 14 | private lateinit var textSettingName: TextView | ||
| 15 | private lateinit var textSettingDescription: TextView | ||
| 16 | |||
| 17 | override fun findViews(root: View) { | ||
| 18 | textSettingName = root.findViewById(R.id.text_setting_name) | ||
| 19 | textSettingDescription = root.findViewById(R.id.text_setting_description) | ||
| 20 | } | ||
| 21 | |||
| 22 | override fun bind(item: SettingsItem) { | ||
| 23 | this.item = item | ||
| 24 | textSettingName.setText(item.nameId) | ||
| 25 | textSettingDescription.visibility = View.VISIBLE | ||
| 26 | if (item.descriptionId!! > 0) { | ||
| 27 | textSettingDescription.setText(item.descriptionId) | ||
| 28 | } else if (item is SingleChoiceSetting) { | ||
| 29 | val resMgr = textSettingDescription.context.resources | ||
| 30 | val values = resMgr.getIntArray(item.valuesId) | ||
| 31 | for (i in values.indices) { | ||
| 32 | if (values[i] == item.selectedValue) { | ||
| 33 | textSettingDescription.text = resMgr.getStringArray(item.choicesId)[i] | ||
| 34 | } | ||
| 35 | } | ||
| 36 | } else { | ||
| 37 | textSettingDescription.visibility = View.GONE | ||
| 38 | } | ||
| 39 | } | ||
| 40 | |||
| 41 | override fun onClick(clicked: View) { | ||
| 42 | if (item is SingleChoiceSetting) { | ||
| 43 | adapter.onSingleChoiceClick( | ||
| 44 | (item as SingleChoiceSetting), | ||
| 45 | bindingAdapterPosition | ||
| 46 | ) | ||
| 47 | } else if (item is StringSingleChoiceSetting) { | ||
| 48 | adapter.onStringSingleChoiceClick( | ||
| 49 | (item as StringSingleChoiceSetting), | ||
| 50 | bindingAdapterPosition | ||
| 51 | ) | ||
| 52 | } | ||
| 53 | } | ||
| 54 | } | ||