Android: Convert CheatViewHolder to Kotlin
This commit is contained in:
parent
25fb3218d9
commit
a8da5902bb
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue