From a8da5902bb6341853e008614c2e9bb6574d8de1b Mon Sep 17 00:00:00 2001 From: Charles Lombardo Date: Wed, 1 Mar 2023 13:40:28 -0500 Subject: [PATCH] Android: Convert CheatViewHolder to Kotlin --- .../features/cheats/ui/CheatViewHolder.java | 55 ------------------- .../features/cheats/ui/CheatViewHolder.kt | 39 +++++++++++++ 2 files changed, 39 insertions(+), 55 deletions(-) delete mode 100644 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/CheatViewHolder.java create mode 100644 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/CheatViewHolder.kt diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/CheatViewHolder.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/CheatViewHolder.java deleted file mode 100644 index 0623aeabeb..0000000000 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/CheatViewHolder.java +++ /dev/null @@ -1,55 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later - -package org.dolphinemu.dolphinemu.features.cheats.ui; - -import android.view.View; -import android.widget.CompoundButton; - -import androidx.annotation.NonNull; -import androidx.lifecycle.ViewModelProvider; - -import org.dolphinemu.dolphinemu.databinding.ListItemCheatBinding; -import org.dolphinemu.dolphinemu.features.cheats.model.Cheat; -import org.dolphinemu.dolphinemu.features.cheats.model.CheatsViewModel; - -public class CheatViewHolder extends CheatItemViewHolder - implements View.OnClickListener, CompoundButton.OnCheckedChangeListener -{ - private final ListItemCheatBinding mBinding; - - private CheatsViewModel mViewModel; - private Cheat mCheat; - private int mPosition; - - public CheatViewHolder(@NonNull ListItemCheatBinding binding) - { - super(binding.getRoot()); - mBinding = binding; - } - - public void bind(CheatsActivity activity, CheatItem item, int position) - { - mBinding.cheatSwitch.setOnCheckedChangeListener(null); - - mViewModel = new ViewModelProvider(activity).get(CheatsViewModel.class); - mCheat = item.getCheat(); - mPosition = position; - - mBinding.textName.setText(mCheat.getName()); - mBinding.cheatSwitch.setChecked(mCheat.getEnabled()); - - mBinding.root.setOnClickListener(this); - mBinding.cheatSwitch.setOnCheckedChangeListener(this); - } - - public void onClick(View root) - { - mViewModel.setSelectedCheat(mCheat, mPosition); - mViewModel.openDetailsView(); - } - - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) - { - mCheat.setEnabled(isChecked); - } -} diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/CheatViewHolder.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/CheatViewHolder.kt new file mode 100644 index 0000000000..15b51e7299 --- /dev/null +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/CheatViewHolder.kt @@ -0,0 +1,39 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +package org.dolphinemu.dolphinemu.features.cheats.ui + +import android.view.View +import android.widget.CompoundButton +import androidx.lifecycle.ViewModelProvider +import org.dolphinemu.dolphinemu.databinding.ListItemCheatBinding +import org.dolphinemu.dolphinemu.features.cheats.model.Cheat +import org.dolphinemu.dolphinemu.features.cheats.model.CheatsViewModel + +class CheatViewHolder(private val binding: ListItemCheatBinding) : + CheatItemViewHolder(binding.getRoot()), + View.OnClickListener, + CompoundButton.OnCheckedChangeListener { + private lateinit var viewModel: CheatsViewModel + private lateinit var cheat: Cheat + private var position = 0 + + override fun bind(activity: CheatsActivity, item: CheatItem, position: Int) { + binding.cheatSwitch.setOnCheckedChangeListener(null) + viewModel = ViewModelProvider(activity)[CheatsViewModel::class.java] + cheat = item.cheat!! + this.position = position + binding.textName.text = cheat.getName() + binding.cheatSwitch.isChecked = cheat.getEnabled() + binding.root.setOnClickListener(this) + binding.cheatSwitch.setOnCheckedChangeListener(this) + } + + override fun onClick(root: View) { + viewModel.setSelectedCheat(cheat, position) + viewModel.openDetailsView() + } + + override fun onCheckedChanged(buttonView: CompoundButton, isChecked: Boolean) { + cheat.setEnabled(isChecked) + } +}