android: Convert CheckBoxSettingViewHolder to Kotlin

This commit is contained in:
Charles Lombardo 2023-03-07 20:04:04 -05:00 committed by bunnei
parent f0a9fcf100
commit 3a5b9ecba2
2 changed files with 41 additions and 54 deletions

View File

@ -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());
}
}

View File

@ -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)
}
}