diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/ConfirmRunnable.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/RunRunnable.java similarity index 57% rename from Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/ConfirmRunnable.java rename to Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/RunRunnable.java index f0a1dee5eb..7c03cfc5e5 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/ConfirmRunnable.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/RunRunnable.java @@ -2,18 +2,18 @@ package org.dolphinemu.dolphinemu.features.settings.model.view; import org.dolphinemu.dolphinemu.features.settings.model.AbstractSetting; -public final class ConfirmRunnable extends SettingsItem +public final class RunRunnable extends SettingsItem { - private int mAlertText; - private int mConfirmationText; - private Runnable mRunnable; + private final int mAlertText; + private final int mToastTextAfterRun; + private final Runnable mRunnable; - public ConfirmRunnable(int titleId, int descriptionId, int alertText, int confirmationText, + public RunRunnable(int titleId, int descriptionId, int alertText, int toastTextAfterRun, Runnable runnable) { super(titleId, descriptionId); mAlertText = alertText; - mConfirmationText = confirmationText; + mToastTextAfterRun = toastTextAfterRun; mRunnable = runnable; } @@ -22,9 +22,9 @@ public final class ConfirmRunnable extends SettingsItem return mAlertText; } - public int getConfirmationText() + public int getToastTextAfterRun() { - return mConfirmationText; + return mToastTextAfterRun; } public Runnable getRunnable() @@ -35,7 +35,7 @@ public final class ConfirmRunnable extends SettingsItem @Override public int getType() { - return TYPE_CONFIRM_RUNNABLE; + return TYPE_RUN_RUNNABLE; } @Override diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/SettingsItem.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/SettingsItem.java index 2e154d69d3..ebc68f6948 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/SettingsItem.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/SettingsItem.java @@ -22,10 +22,10 @@ public abstract class SettingsItem public static final int TYPE_RUMBLE_BINDING = 7; public static final int TYPE_SINGLE_CHOICE_DYNAMIC_DESCRIPTIONS = 8; public static final int TYPE_FILE_PICKER = 9; - public static final int TYPE_CONFIRM_RUNNABLE = 10; + public static final int TYPE_RUN_RUNNABLE = 10; - private int mNameId; - private int mDescriptionId; + private final int mNameId; + private final int mDescriptionId; /** * Base constructor. diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsAdapter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsAdapter.java index 1c097ea06c..01fc41536b 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsAdapter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsAdapter.java @@ -29,7 +29,7 @@ import org.dolphinemu.dolphinemu.features.settings.model.view.SliderSetting; import org.dolphinemu.dolphinemu.features.settings.model.view.StringSingleChoiceSetting; import org.dolphinemu.dolphinemu.features.settings.model.view.SubmenuSetting; import org.dolphinemu.dolphinemu.features.settings.ui.viewholder.CheckBoxSettingViewHolder; -import org.dolphinemu.dolphinemu.features.settings.ui.viewholder.ConfirmRunnableViewHolder; +import org.dolphinemu.dolphinemu.features.settings.ui.viewholder.RunRunnableViewHolder; import org.dolphinemu.dolphinemu.features.settings.ui.viewholder.FilePickerViewHolder; import org.dolphinemu.dolphinemu.features.settings.ui.viewholder.HeaderViewHolder; import org.dolphinemu.dolphinemu.features.settings.ui.viewholder.InputBindingSettingViewHolder; @@ -49,8 +49,8 @@ import java.util.Map; public final class SettingsAdapter extends RecyclerView.Adapter implements DialogInterface.OnClickListener, SeekBar.OnSeekBarChangeListener { - private SettingsFragmentView mView; - private Context mContext; + private final SettingsFragmentView mView; + private final Context mContext; private ArrayList mSettings; private SettingsItem mClickedItem; @@ -110,9 +110,9 @@ public final class SettingsAdapter extends RecyclerView.Adapter mView.getAdapter().setAllLogTypes(true))); - sl.add(new ConfirmRunnable(R.string.log_disable_all, 0, R.string.log_disable_all_confirmation, - 0, () -> mView.getAdapter().setAllLogTypes(false))); + sl.add(new RunRunnable(R.string.log_disable_all, 0, R.string.log_disable_all_confirmation, 0, + () -> mView.getAdapter().setAllLogTypes(false))); sl.add(new HeaderSetting(R.string.log_types, 0)); for (Map.Entry entry : LOG_TYPE_NAMES.entrySet()) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/ConfirmRunnableViewHolder.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/ConfirmRunnableViewHolder.java deleted file mode 100644 index 2c73dd694a..0000000000 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/ConfirmRunnableViewHolder.java +++ /dev/null @@ -1,82 +0,0 @@ -package org.dolphinemu.dolphinemu.features.settings.ui.viewholder; - -import android.content.Context; -import android.view.View; -import android.widget.TextView; -import android.widget.Toast; - -import androidx.appcompat.app.AlertDialog; - -import org.dolphinemu.dolphinemu.R; -import org.dolphinemu.dolphinemu.features.settings.model.view.ConfirmRunnable; -import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem; -import org.dolphinemu.dolphinemu.features.settings.ui.SettingsAdapter; -import org.dolphinemu.dolphinemu.features.settings.ui.SettingsFragmentView; - -public final class ConfirmRunnableViewHolder extends SettingViewHolder -{ - private ConfirmRunnable mItem; - private SettingsFragmentView mView; - - private Context mContext; - - private TextView mTextSettingName; - private TextView mTextSettingDescription; - - public ConfirmRunnableViewHolder(View itemView, SettingsAdapter adapter, Context context, - SettingsFragmentView view) - { - super(itemView, adapter); - - mContext = context; - mView = view; - } - - @Override - protected void findViews(View root) - { - mTextSettingName = root.findViewById(R.id.text_setting_name); - mTextSettingDescription = root.findViewById(R.id.text_setting_description); - } - - @Override - public void bind(SettingsItem item) - { - mItem = (ConfirmRunnable) item; - - mTextSettingName.setText(item.getNameId()); - - if (item.getDescriptionId() > 0) - { - mTextSettingDescription.setText(item.getDescriptionId()); - } - } - - @Override - public void onClick(View clicked) - { - String alertTitle = mContext.getString(mItem.getNameId()); - String alertText = mContext.getString(mItem.getAlertText()); - - AlertDialog.Builder builder = new AlertDialog.Builder(mContext, R.style.DolphinDialogBase) - .setTitle(alertTitle) - .setMessage(alertText); - - builder - .setPositiveButton("Yes", (dialog, whichButton) -> - { - mItem.getRunnable().run(); - - if (mItem.getConfirmationText() > 0) - { - String confirmationText = mContext.getString(mItem.getConfirmationText()); - Toast.makeText(mContext, confirmationText, Toast.LENGTH_SHORT).show(); - } - dialog.dismiss(); - }) - .setNegativeButton("No", (dialog, whichButton) -> - dialog.dismiss()); - - builder.show(); - } -} 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 new file mode 100644 index 0000000000..1fd87824df --- /dev/null +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/RunRunnableViewHolder.java @@ -0,0 +1,88 @@ +package org.dolphinemu.dolphinemu.features.settings.ui.viewholder; + +import android.content.Context; +import android.view.View; +import android.widget.TextView; +import android.widget.Toast; + +import androidx.appcompat.app.AlertDialog; + +import org.dolphinemu.dolphinemu.R; +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 TextView mTextSettingName; + private TextView mTextSettingDescription; + + public RunRunnableViewHolder(View itemView, SettingsAdapter adapter, Context context) + { + super(itemView, adapter); + + mContext = context; + } + + @Override + protected void findViews(View root) + { + mTextSettingName = root.findViewById(R.id.text_setting_name); + mTextSettingDescription = root.findViewById(R.id.text_setting_description); + } + + @Override + public void bind(SettingsItem item) + { + mItem = (RunRunnable) item; + + mTextSettingName.setText(item.getNameId()); + + if (item.getDescriptionId() > 0) + { + mTextSettingDescription.setText(item.getDescriptionId()); + } + } + + @Override + public void onClick(View clicked) + { + int alertTextID = mItem.getAlertText(); + + if (alertTextID > 0) + { + AlertDialog.Builder builder = new AlertDialog.Builder(mContext, R.style.DolphinDialogBase) + .setTitle(mContext.getString(mItem.getNameId())) + .setMessage(mContext.getString(alertTextID)); + + builder + .setPositiveButton(R.string.ok, (dialog, whichButton) -> + { + runRunnable(); + dialog.dismiss(); + }) + .setNegativeButton(R.string.cancel, (dialog, whichButton) -> dialog.dismiss()); + + builder.show(); + } + else + { + runRunnable(); + } + } + + private void runRunnable() + { + mItem.getRunnable().run(); + + if (mItem.getToastTextAfterRun() > 0) + { + Toast.makeText(mContext, mContext.getString(mItem.getToastTextAfterRun()), Toast.LENGTH_SHORT) + .show(); + } + } +}