Android: ConfirmRunnable to RunRunnable with optional confirmation
This commit is contained in:
parent
653f89701d
commit
d8c5f4323b
|
@ -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
|
|
@ -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.
|
||||
|
|
|
@ -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<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;
|
||||
|
@ -110,9 +110,9 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
|
|||
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);
|
||||
|
|
|
@ -15,7 +15,7 @@ import org.dolphinemu.dolphinemu.features.settings.model.LegacyStringSetting;
|
|||
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;
|
||||
|
@ -354,7 +354,7 @@ public final class SettingsFragmentPresenter
|
|||
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));
|
||||
}
|
||||
|
||||
|
@ -626,10 +626,10 @@ public final class SettingsFragmentPresenter
|
|||
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())
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue