Android: Convert InputStringSettingViewHolder to Kotlin
This commit is contained in:
parent
bc6d10e29a
commit
6a08b12c9b
|
@ -1,71 +0,0 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package org.dolphinemu.dolphinemu.features.settings.ui.viewholder;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.dolphinemu.dolphinemu.databinding.ListItemSettingBinding;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.view.InputStringSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem;
|
||||
import org.dolphinemu.dolphinemu.features.settings.ui.SettingsAdapter;
|
||||
|
||||
public final class InputStringSettingViewHolder extends SettingViewHolder
|
||||
{
|
||||
private InputStringSetting mInputString;
|
||||
|
||||
private final ListItemSettingBinding mBinding;
|
||||
|
||||
public InputStringSettingViewHolder(@NonNull ListItemSettingBinding binding,
|
||||
SettingsAdapter adapter)
|
||||
{
|
||||
super(binding.getRoot(), adapter);
|
||||
mBinding = binding;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(SettingsItem item)
|
||||
{
|
||||
mInputString = (InputStringSetting) item;
|
||||
|
||||
String inputString = mInputString.getSelectedValue();
|
||||
|
||||
mBinding.textSettingName.setText(item.getName());
|
||||
|
||||
if (!TextUtils.isEmpty(inputString))
|
||||
{
|
||||
mBinding.textSettingDescription.setText(inputString);
|
||||
}
|
||||
else
|
||||
{
|
||||
mBinding.textSettingDescription.setText(item.getDescription());
|
||||
}
|
||||
|
||||
setStyle(mBinding.textSettingName, mInputString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View clicked)
|
||||
{
|
||||
if (!mInputString.isEditable())
|
||||
{
|
||||
showNotRuntimeEditableError();
|
||||
return;
|
||||
}
|
||||
|
||||
int position = getBindingAdapterPosition();
|
||||
|
||||
getAdapter().onInputStringClick(mInputString, position);
|
||||
|
||||
setStyle(mBinding.textSettingName, mInputString);
|
||||
}
|
||||
|
||||
@Nullable @Override
|
||||
protected SettingsItem getItem()
|
||||
{
|
||||
return mInputString;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package org.dolphinemu.dolphinemu.features.settings.ui.viewholder
|
||||
|
||||
import android.text.TextUtils
|
||||
import android.view.View
|
||||
import org.dolphinemu.dolphinemu.databinding.ListItemSettingBinding
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.view.InputStringSetting
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem
|
||||
import org.dolphinemu.dolphinemu.features.settings.ui.SettingsAdapter
|
||||
|
||||
class InputStringSettingViewHolder(
|
||||
private val binding: ListItemSettingBinding,
|
||||
adapter: SettingsAdapter
|
||||
) : SettingViewHolder(binding.getRoot(), adapter) {
|
||||
private lateinit var setting: InputStringSetting
|
||||
|
||||
override val item: SettingsItem
|
||||
get() = setting
|
||||
|
||||
override fun bind(item: SettingsItem) {
|
||||
setting = item as InputStringSetting
|
||||
|
||||
val inputString = setting.selectedValue
|
||||
|
||||
binding.textSettingName.text = setting.name
|
||||
|
||||
if (!TextUtils.isEmpty(inputString)) {
|
||||
binding.textSettingDescription.text = inputString
|
||||
} else {
|
||||
binding.textSettingDescription.text = setting.description
|
||||
}
|
||||
|
||||
setStyle(binding.textSettingName, setting)
|
||||
}
|
||||
|
||||
override fun onClick(clicked: View) {
|
||||
if (!setting.isEditable) {
|
||||
showNotRuntimeEditableError()
|
||||
return
|
||||
}
|
||||
|
||||
val position = bindingAdapterPosition
|
||||
|
||||
adapter.onInputStringClick(setting, position)
|
||||
|
||||
setStyle(binding.textSettingName, setting)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue