From 6caa4307ac11f57ea4dcf41ea7d16d7029fa3800 Mon Sep 17 00:00:00 2001 From: Charles Lombardo Date: Sat, 10 Jun 2023 05:18:37 -0400 Subject: [PATCH] Android: Convert ProfileViewHolder to Kotlin --- .../features/input/ui/ProfileViewHolder.java | 76 ------------------- .../features/input/ui/ProfileViewHolder.kt | 56 ++++++++++++++ 2 files changed, 56 insertions(+), 76 deletions(-) delete mode 100644 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/ui/ProfileViewHolder.java create mode 100644 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/ui/ProfileViewHolder.kt diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/ui/ProfileViewHolder.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/ui/ProfileViewHolder.java deleted file mode 100644 index d4d40c0c65..0000000000 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/ui/ProfileViewHolder.java +++ /dev/null @@ -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); - } -} diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/ui/ProfileViewHolder.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/ui/ProfileViewHolder.kt new file mode 100644 index 0000000000..671461c9aa --- /dev/null +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/ui/ProfileViewHolder.kt @@ -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!!) +}