Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #9154 from Ebola16/RR
Android: ConfirmRunnable to RunRunnable with optional confirmation
  • Loading branch information
leoetlino committed Oct 19, 2020
2 parents 213072b + d8c5f43 commit d448bd5
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 104 deletions.
Expand Up @@ -2,18 +2,18 @@

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;
}

Expand All @@ -22,9 +22,9 @@ public int getAlertText()
return mAlertText;
}

public int getConfirmationText()
public int getToastTextAfterRun()
{
return mConfirmationText;
return mToastTextAfterRun;
}

public Runnable getRunnable()
Expand All @@ -35,7 +35,7 @@ public Runnable getRunnable()
@Override
public int getType()
{
return TYPE_CONFIRM_RUNNABLE;
return TYPE_RUN_RUNNABLE;
}

@Override
Expand Down
Expand Up @@ -22,10 +22,10 @@
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.
Expand Down
Expand Up @@ -29,7 +29,7 @@
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;
Expand All @@ -49,8 +49,8 @@
public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolder>
implements DialogInterface.OnClickListener, SeekBar.OnSeekBarChangeListener
{
private SettingsFragmentView mView;
private Context mContext;
private final SettingsFragmentView mView;
private final Context mContext;
private ArrayList<SettingsItem> mSettings;

private SettingsItem mClickedItem;
Expand Down Expand Up @@ -110,9 +110,9 @@ public SettingViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
view = inflater.inflate(R.layout.list_item_setting, parent, false);
return new FilePickerViewHolder(view, this);

case SettingsItem.TYPE_CONFIRM_RUNNABLE:
case SettingsItem.TYPE_RUN_RUNNABLE:
view = inflater.inflate(R.layout.list_item_setting, parent, false);
return new ConfirmRunnableViewHolder(view, this, mContext, mView);
return new RunRunnableViewHolder(view, this, mContext);

default:
throw new IllegalArgumentException("Invalid view type: " + viewType);
Expand Down
Expand Up @@ -15,7 +15,7 @@
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
import org.dolphinemu.dolphinemu.features.settings.model.StringSetting;
import org.dolphinemu.dolphinemu.features.settings.model.view.CheckBoxSetting;
import org.dolphinemu.dolphinemu.features.settings.model.view.ConfirmRunnable;
import org.dolphinemu.dolphinemu.features.settings.model.view.RunRunnable;
import org.dolphinemu.dolphinemu.features.settings.model.view.FilePicker;
import org.dolphinemu.dolphinemu.features.settings.model.view.HeaderSetting;
import org.dolphinemu.dolphinemu.features.settings.model.view.InputBindingSetting;
Expand Down Expand Up @@ -354,7 +354,7 @@ private void addPathsSettings(ArrayList<SettingsItem> sl)
MainPresenter.REQUEST_DIRECTORY, "/ResourcePacks"));
sl.add(new FilePicker(StringSetting.MAIN_SD_PATH, R.string.SD_card_path, 0,
MainPresenter.REQUEST_SD_FILE, "/Wii/sd.raw"));
sl.add(new ConfirmRunnable(R.string.reset_paths, 0, R.string.reset_paths_confirmation, 0,
sl.add(new RunRunnable(R.string.reset_paths, 0, R.string.reset_paths_confirmation, 0,
mView.getAdapter()::resetPaths));
}

Expand Down Expand Up @@ -626,10 +626,10 @@ private void addLogConfigurationSettings(ArrayList<SettingsItem> sl)
R.string.enable_logging_description));
sl.add(new SingleChoiceSetting(IntSetting.LOGGER_VERBOSITY, R.string.log_verbosity, 0,
getLogVerbosityEntries(), getLogVerbosityValues()));
sl.add(new ConfirmRunnable(R.string.log_enable_all, 0, R.string.log_enable_all_confirmation, 0,
sl.add(new RunRunnable(R.string.log_enable_all, 0, R.string.log_enable_all_confirmation, 0,
() -> 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<String, String> entry : LOG_TYPE_NAMES.entrySet())
Expand Down

This file was deleted.

@@ -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();
}
}
}

0 comments on commit d448bd5

Please sign in to comment.