Android: Convert ProfileViewHolder to Kotlin

This commit is contained in:
Charles Lombardo 2023-06-10 05:18:37 -04:00
parent 29e5c78541
commit 6caa4307ac
2 changed files with 56 additions and 76 deletions

View File

@ -1,76 +0,0 @@
// SPDX-License-Identifier: GPL-2.0-or-later
package org.dolphinemu.dolphinemu.features.input.ui;
import android.content.Context;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.databinding.ListItemProfileBinding;
public class ProfileViewHolder extends RecyclerView.ViewHolder
{
private final ProfileDialogPresenter mPresenter;
private final ListItemProfileBinding mBinding;
private String mProfileName;
private boolean mStock;
public ProfileViewHolder(@NonNull ProfileDialogPresenter presenter,
@NonNull ListItemProfileBinding binding)
{
super(binding.getRoot());
mPresenter = presenter;
mBinding = binding;
binding.buttonLoad.setOnClickListener(view -> loadProfile());
binding.buttonSave.setOnClickListener(view -> saveProfile());
binding.buttonDelete.setOnClickListener(view -> deleteProfile());
}
public void bind(String profileName, boolean stock)
{
mProfileName = profileName;
mStock = stock;
mBinding.textName.setText(profileName);
mBinding.buttonLoad.setVisibility(View.VISIBLE);
mBinding.buttonSave.setVisibility(stock ? View.GONE : View.VISIBLE);
mBinding.buttonDelete.setVisibility(stock ? View.GONE : View.VISIBLE);
}
public void bindAsEmpty(Context context)
{
mProfileName = null;
mStock = false;
mBinding.textName.setText(context.getText(R.string.input_profile_new));
mBinding.buttonLoad.setVisibility(View.GONE);
mBinding.buttonSave.setVisibility(View.VISIBLE);
mBinding.buttonDelete.setVisibility(View.GONE);
}
private void loadProfile()
{
mPresenter.loadProfile(mProfileName, mStock);
}
private void saveProfile()
{
if (mProfileName == null)
mPresenter.saveProfileAndPromptForName();
else
mPresenter.saveProfile(mProfileName);
}
private void deleteProfile()
{
mPresenter.deleteProfile(mProfileName);
}
}

View File

@ -0,0 +1,56 @@
// SPDX-License-Identifier: GPL-2.0-or-later
package org.dolphinemu.dolphinemu.features.input.ui
import android.content.Context
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import org.dolphinemu.dolphinemu.R
import org.dolphinemu.dolphinemu.databinding.ListItemProfileBinding
class ProfileViewHolder(
private val presenter: ProfileDialogPresenter,
private val binding: ListItemProfileBinding
) : RecyclerView.ViewHolder(binding.getRoot()) {
private var profileName: String? = null
private var stock = false
init {
binding.buttonLoad.setOnClickListener { loadProfile() }
binding.buttonSave.setOnClickListener { saveProfile() }
binding.buttonDelete.setOnClickListener { deleteProfile() }
}
fun bind(profileName: String, stock: Boolean) {
this.profileName = profileName
this.stock = stock
binding.textName.text = profileName
binding.buttonLoad.visibility = View.VISIBLE
binding.buttonSave.visibility = if (stock) View.GONE else View.VISIBLE
binding.buttonDelete.visibility = if (stock) View.GONE else View.VISIBLE
}
fun bindAsEmpty(context: Context) {
profileName = null
stock = false
binding.textName.text = context.getText(R.string.input_profile_new)
binding.buttonLoad.visibility = View.GONE
binding.buttonSave.visibility = View.VISIBLE
binding.buttonDelete.visibility = View.GONE
}
private fun loadProfile() = presenter.loadProfile(profileName!!, stock)
private fun saveProfile() {
if (profileName == null)
presenter.saveProfileAndPromptForName()
else
presenter.saveProfile(profileName!!)
}
private fun deleteProfile() = presenter.deleteProfile(profileName!!)
}