diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/RunRunnableViewHolder.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/RunRunnableViewHolder.java deleted file mode 100644 index 6104a2aa2e..0000000000 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/RunRunnableViewHolder.java +++ /dev/null @@ -1,93 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later - -package org.dolphinemu.dolphinemu.features.settings.ui.viewholder; - -import android.content.Context; -import android.view.View; -import android.widget.Toast; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -import com.google.android.material.dialog.MaterialAlertDialogBuilder; - -import org.dolphinemu.dolphinemu.R; -import org.dolphinemu.dolphinemu.databinding.ListItemSettingBinding; -import org.dolphinemu.dolphinemu.features.settings.model.view.RunRunnable; -import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem; -import org.dolphinemu.dolphinemu.features.settings.ui.SettingsAdapter; - -public final class RunRunnableViewHolder extends SettingViewHolder -{ - private RunRunnable mItem; - - private final Context mContext; - - private final ListItemSettingBinding mBinding; - - public RunRunnableViewHolder(@NonNull ListItemSettingBinding binding, SettingsAdapter adapter, - Context context) - { - super(binding.getRoot(), adapter); - mBinding = binding; - mContext = context; - } - - @Override - public void bind(SettingsItem item) - { - mItem = (RunRunnable) item; - - mBinding.textSettingName.setText(item.getName()); - mBinding.textSettingDescription.setText(item.getDescription()); - - setStyle(mBinding.textSettingName, mItem); - } - - @Override - public void onClick(View clicked) - { - if (!mItem.isEditable()) - { - showNotRuntimeEditableError(); - return; - } - - int alertTextID = mItem.getAlertText(); - - if (alertTextID > 0) - { - new MaterialAlertDialogBuilder(mContext) - .setTitle(mItem.getName()) - .setMessage(alertTextID) - .setPositiveButton(R.string.ok, (dialog, whichButton) -> - { - runRunnable(); - dialog.dismiss(); - }) - .setNegativeButton(R.string.cancel, (dialog, whichButton) -> dialog.dismiss()) - .show(); - } - else - { - runRunnable(); - } - } - - @Nullable @Override - protected SettingsItem getItem() - { - return mItem; - } - - private void runRunnable() - { - mItem.getRunnable().run(); - - if (mItem.getToastTextAfterRun() > 0) - { - Toast.makeText(mContext, mContext.getString(mItem.getToastTextAfterRun()), Toast.LENGTH_SHORT) - .show(); - } - } -} diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/RunRunnableViewHolder.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/RunRunnableViewHolder.kt new file mode 100644 index 0000000000..2ff39d51d5 --- /dev/null +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/RunRunnableViewHolder.kt @@ -0,0 +1,68 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +package org.dolphinemu.dolphinemu.features.settings.ui.viewholder + +import android.content.Context +import android.content.DialogInterface +import android.view.View +import android.widget.Toast +import com.google.android.material.dialog.MaterialAlertDialogBuilder +import org.dolphinemu.dolphinemu.R +import org.dolphinemu.dolphinemu.databinding.ListItemSettingBinding +import org.dolphinemu.dolphinemu.features.settings.model.view.RunRunnable +import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem +import org.dolphinemu.dolphinemu.features.settings.ui.SettingsAdapter + +class RunRunnableViewHolder( + private val mBinding: ListItemSettingBinding, adapter: SettingsAdapter?, + private val mContext: Context +) : SettingViewHolder(mBinding.getRoot(), adapter!!) { + private lateinit var setting: RunRunnable + + override val item: SettingsItem + get() = setting + + override fun bind(item: SettingsItem) { + setting = item as RunRunnable + + mBinding.textSettingName.text = setting.name + mBinding.textSettingDescription.text = setting.description + + setStyle(mBinding.textSettingName, setting) + } + + override fun onClick(clicked: View) { + if (!setting.isEditable) { + showNotRuntimeEditableError() + return + } + + val alertTextID = setting.alertText + + if (alertTextID > 0) { + MaterialAlertDialogBuilder(mContext) + .setTitle(setting.name) + .setMessage(alertTextID) + .setPositiveButton(R.string.ok) { dialog: DialogInterface, _: Int -> + runRunnable() + dialog.dismiss() + } + .setNegativeButton(R.string.cancel) { dialog: DialogInterface, _: Int -> dialog.dismiss() } + .show() + } else { + runRunnable() + } + } + + private fun runRunnable() { + setting.runnable.run() + + if (setting.toastTextAfterRun > 0) { + Toast.makeText( + mContext, + mContext.getString(setting.toastTextAfterRun), + Toast.LENGTH_SHORT + ).show() + } + } +}