diff options
Diffstat (limited to 'src')
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 + ) + } + } +} |