Android: Convert SliderViewHolder to Kotlin

This commit is contained in:
Charles Lombardo 2023-03-15 03:32:44 -04:00
parent 9b79f5fa5d
commit 760417b08f
2 changed files with 51 additions and 74 deletions

View File

@ -1,74 +0,0 @@
// SPDX-License-Identifier: GPL-2.0-or-later
package org.dolphinemu.dolphinemu.features.settings.ui.viewholder;
import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.databinding.ListItemSettingBinding;
import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem;
import org.dolphinemu.dolphinemu.features.settings.model.view.SliderSetting;
import org.dolphinemu.dolphinemu.features.settings.ui.SettingsAdapter;
public final class SliderViewHolder extends SettingViewHolder
{
private final Context mContext;
private SliderSetting mItem;
private final ListItemSettingBinding mBinding;
public SliderViewHolder(@NonNull ListItemSettingBinding binding, SettingsAdapter adapter,
Context context)
{
super(binding.getRoot(), adapter);
mBinding = binding;
mContext = context;
}
@Override
public void bind(SettingsItem item)
{
mItem = (SliderSetting) item;
mBinding.textSettingName.setText(item.getName());
if (!TextUtils.isEmpty(item.getDescription()))
{
mBinding.textSettingDescription.setText(item.getDescription());
}
else
{
mBinding.textSettingDescription.setText(mContext.getString(R.string.slider_setting_value,
mItem.getSelectedValue(), mItem.getUnits()));
}
setStyle(mBinding.textSettingName, mItem);
}
@Override
public void onClick(View clicked)
{
if (!mItem.isEditable())
{
showNotRuntimeEditableError();
return;
}
getAdapter().onSliderClick(mItem, getBindingAdapterPosition());
setStyle(mBinding.textSettingName, mItem);
}
@Nullable @Override
protected SettingsItem getItem()
{
return mItem;
}
}

View File

@ -0,0 +1,51 @@
// SPDX-License-Identifier: GPL-2.0-or-later
package org.dolphinemu.dolphinemu.features.settings.ui.viewholder
import android.content.Context
import android.text.TextUtils
import android.view.View
import org.dolphinemu.dolphinemu.R
import org.dolphinemu.dolphinemu.databinding.ListItemSettingBinding
import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem
import org.dolphinemu.dolphinemu.features.settings.model.view.SliderSetting
import org.dolphinemu.dolphinemu.features.settings.ui.SettingsAdapter
class SliderViewHolder(
private val binding: ListItemSettingBinding, adapter: SettingsAdapter?,
private val context: Context
) : SettingViewHolder(binding.getRoot(), adapter!!) {
private lateinit var setting: SliderSetting
override val item: SettingsItem
get() = setting
override fun bind(item: SettingsItem) {
setting = item as SliderSetting
binding.textSettingName.text = item.name
if (!TextUtils.isEmpty(item.description)) {
binding.textSettingDescription.text = item.description
} else {
binding.textSettingDescription.text = context.getString(
R.string.slider_setting_value,
setting.selectedValue,
setting.units
)
}
setStyle(binding.textSettingName, setting)
}
override fun onClick(clicked: View) {
if (!setting.isEditable) {
showNotRuntimeEditableError()
return
}
adapter.onSliderClick(setting, bindingAdapterPosition)
setStyle(binding.textSettingName, setting)
}
}