mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-11-27 01:02:48 +01:00
android: Convert SingleChoiceViewHolder to Kotlin
This commit is contained in:
parent
c42eb92557
commit
fd1801aec4
2 changed files with 54 additions and 62 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue