From 760417b08f0eb74c5368dba9d38d5a37acdb9f48 Mon Sep 17 00:00:00 2001 From: Charles Lombardo Date: Wed, 15 Mar 2023 03:32:44 -0400 Subject: [PATCH] Android: Convert SliderViewHolder to Kotlin --- .../ui/viewholder/SliderViewHolder.java | 74 ------------------- .../ui/viewholder/SliderViewHolder.kt | 51 +++++++++++++ 2 files changed, 51 insertions(+), 74 deletions(-) delete mode 100644 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/SliderViewHolder.java create mode 100644 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/SliderViewHolder.kt diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/SliderViewHolder.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/SliderViewHolder.java deleted file mode 100644 index 8d53bb1365..0000000000 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/SliderViewHolder.java +++ /dev/null @@ -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; - } -} - diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/SliderViewHolder.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/SliderViewHolder.kt new file mode 100644 index 0000000000..9009be4e7d --- /dev/null +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/SliderViewHolder.kt @@ -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) + } +}