Android: Convert InputMappingControlSettingViewHolder to Kotlin
This commit is contained in:
parent
6caa4307ac
commit
0e3b33d901
|
@ -1,77 +0,0 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package org.dolphinemu.dolphinemu.features.input.ui.viewholder;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.dolphinemu.dolphinemu.databinding.ListItemMappingBinding;
|
||||
import org.dolphinemu.dolphinemu.features.input.model.view.InputMappingControlSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem;
|
||||
import org.dolphinemu.dolphinemu.features.settings.ui.SettingsAdapter;
|
||||
import org.dolphinemu.dolphinemu.features.settings.ui.viewholder.SettingViewHolder;
|
||||
|
||||
public final class InputMappingControlSettingViewHolder extends SettingViewHolder
|
||||
{
|
||||
private InputMappingControlSetting mItem;
|
||||
|
||||
private final ListItemMappingBinding mBinding;
|
||||
|
||||
public InputMappingControlSettingViewHolder(@NonNull ListItemMappingBinding binding,
|
||||
SettingsAdapter adapter)
|
||||
{
|
||||
super(binding.getRoot(), adapter);
|
||||
mBinding = binding;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(SettingsItem item)
|
||||
{
|
||||
mItem = (InputMappingControlSetting) item;
|
||||
|
||||
mBinding.textSettingName.setText(mItem.getName());
|
||||
mBinding.textSettingDescription.setText(mItem.getValue());
|
||||
mBinding.buttonAdvancedSettings.setOnClickListener(this::onLongClick);
|
||||
|
||||
setStyle(mBinding.textSettingName, mItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View clicked)
|
||||
{
|
||||
if (!mItem.isEditable())
|
||||
{
|
||||
showNotRuntimeEditableError();
|
||||
return;
|
||||
}
|
||||
|
||||
if (mItem.isInput())
|
||||
getAdapter().onInputMappingClick(mItem, getBindingAdapterPosition());
|
||||
else
|
||||
getAdapter().onAdvancedInputMappingClick(mItem, getBindingAdapterPosition());
|
||||
|
||||
setStyle(mBinding.textSettingName, mItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLongClick(View clicked)
|
||||
{
|
||||
if (!mItem.isEditable())
|
||||
{
|
||||
showNotRuntimeEditableError();
|
||||
return true;
|
||||
}
|
||||
|
||||
getAdapter().onAdvancedInputMappingClick(mItem, getBindingAdapterPosition());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nullable @Override
|
||||
protected SettingsItem getItem()
|
||||
{
|
||||
return mItem;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package org.dolphinemu.dolphinemu.features.input.ui.viewholder
|
||||
|
||||
import android.view.View
|
||||
import org.dolphinemu.dolphinemu.databinding.ListItemMappingBinding
|
||||
import org.dolphinemu.dolphinemu.features.input.model.view.InputMappingControlSetting
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem
|
||||
import org.dolphinemu.dolphinemu.features.settings.ui.SettingsAdapter
|
||||
import org.dolphinemu.dolphinemu.features.settings.ui.viewholder.SettingViewHolder
|
||||
|
||||
class InputMappingControlSettingViewHolder(
|
||||
private val binding: ListItemMappingBinding,
|
||||
adapter: SettingsAdapter
|
||||
) : SettingViewHolder(binding.getRoot(), adapter) {
|
||||
lateinit var setting: InputMappingControlSetting
|
||||
|
||||
override val item: SettingsItem
|
||||
get() = setting
|
||||
|
||||
override fun bind(item: SettingsItem) {
|
||||
setting = item as InputMappingControlSetting
|
||||
|
||||
binding.textSettingName.text = setting.name
|
||||
binding.textSettingDescription.text = setting.value
|
||||
binding.buttonAdvancedSettings.setOnClickListener { clicked: View -> onLongClick(clicked) }
|
||||
|
||||
setStyle(binding.textSettingName, setting)
|
||||
}
|
||||
|
||||
override fun onClick(clicked: View) {
|
||||
if (!setting.isEditable) {
|
||||
showNotRuntimeEditableError()
|
||||
return
|
||||
}
|
||||
|
||||
if (setting.isInput)
|
||||
adapter.onInputMappingClick(setting, bindingAdapterPosition)
|
||||
else
|
||||
adapter.onAdvancedInputMappingClick(setting, bindingAdapterPosition)
|
||||
|
||||
setStyle(binding.textSettingName, setting)
|
||||
}
|
||||
|
||||
override fun onLongClick(clicked: View): Boolean {
|
||||
if (!setting.isEditable) {
|
||||
showNotRuntimeEditableError()
|
||||
return true
|
||||
}
|
||||
|
||||
adapter.onAdvancedInputMappingClick(setting, bindingAdapterPosition)
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue