mirror of
https://git.suyu.dev/suyu/suyu
synced 2024-12-25 19:02:45 -06:00
android: Convert CheckBoxSettingViewHolder to Kotlin
This commit is contained in:
parent
f0a9fcf100
commit
3a5b9ecba2
2 changed files with 41 additions and 54 deletions
|
@ -1,54 +0,0 @@
|
||||||
package org.yuzu.yuzu_emu.features.settings.ui.viewholder;
|
|
||||||
|
|
||||||
import android.view.View;
|
|
||||||
import android.widget.CheckBox;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import org.yuzu.yuzu_emu.R;
|
|
||||||
import org.yuzu.yuzu_emu.features.settings.model.view.CheckBoxSetting;
|
|
||||||
import org.yuzu.yuzu_emu.features.settings.model.view.SettingsItem;
|
|
||||||
import org.yuzu.yuzu_emu.features.settings.ui.SettingsAdapter;
|
|
||||||
|
|
||||||
public final class CheckBoxSettingViewHolder extends SettingViewHolder {
|
|
||||||
private CheckBoxSetting mItem;
|
|
||||||
|
|
||||||
private TextView mTextSettingName;
|
|
||||||
private TextView mTextSettingDescription;
|
|
||||||
|
|
||||||
private CheckBox mCheckbox;
|
|
||||||
|
|
||||||
public CheckBoxSettingViewHolder(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);
|
|
||||||
mCheckbox = root.findViewById(R.id.checkbox);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void bind(SettingsItem item) {
|
|
||||||
mItem = (CheckBoxSetting) item;
|
|
||||||
|
|
||||||
mTextSettingName.setText(item.getNameId());
|
|
||||||
|
|
||||||
if (item.getDescriptionId() > 0) {
|
|
||||||
mTextSettingDescription.setText(item.getDescriptionId());
|
|
||||||
mTextSettingDescription.setVisibility(View.VISIBLE);
|
|
||||||
} else {
|
|
||||||
mTextSettingDescription.setText("");
|
|
||||||
mTextSettingDescription.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
mCheckbox.setChecked(mItem.isChecked());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onClick(View clicked) {
|
|
||||||
mCheckbox.toggle();
|
|
||||||
|
|
||||||
getAdapter().onBooleanClick(mItem, getAdapterPosition(), mCheckbox.isChecked());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
package org.yuzu.yuzu_emu.features.settings.ui.viewholder
|
||||||
|
|
||||||
|
import android.view.View
|
||||||
|
import android.widget.CheckBox
|
||||||
|
import android.widget.TextView
|
||||||
|
import org.yuzu.yuzu_emu.R
|
||||||
|
import org.yuzu.yuzu_emu.features.settings.model.view.CheckBoxSetting
|
||||||
|
import org.yuzu.yuzu_emu.features.settings.model.view.SettingsItem
|
||||||
|
import org.yuzu.yuzu_emu.features.settings.ui.SettingsAdapter
|
||||||
|
|
||||||
|
class CheckBoxSettingViewHolder(itemView: View, adapter: SettingsAdapter) :
|
||||||
|
SettingViewHolder(itemView, adapter) {
|
||||||
|
private lateinit var item: CheckBoxSetting
|
||||||
|
private lateinit var textSettingName: TextView
|
||||||
|
private lateinit var textSettingDescription: TextView
|
||||||
|
private lateinit var checkbox: CheckBox
|
||||||
|
|
||||||
|
override fun findViews(root: View) {
|
||||||
|
textSettingName = root.findViewById(R.id.text_setting_name)
|
||||||
|
textSettingDescription = root.findViewById(R.id.text_setting_description)
|
||||||
|
checkbox = root.findViewById(R.id.checkbox)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun bind(item: SettingsItem) {
|
||||||
|
this.item = item as CheckBoxSetting
|
||||||
|
textSettingName.setText(item.nameId)
|
||||||
|
if (item.descriptionId!! > 0) {
|
||||||
|
textSettingDescription.setText(item.descriptionId)
|
||||||
|
textSettingDescription.visibility = View.VISIBLE
|
||||||
|
} else {
|
||||||
|
textSettingDescription.text = ""
|
||||||
|
textSettingDescription.visibility = View.GONE
|
||||||
|
}
|
||||||
|
checkbox.isChecked = this.item.isChecked
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onClick(clicked: View) {
|
||||||
|
checkbox.toggle()
|
||||||
|
adapter.onBooleanClick(item, bindingAdapterPosition, checkbox.isChecked)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue