Android: Long press a setting to reset it

This is particularly important for game INIs, where a setting being
unset is not the same as it being set to the default value.
This commit is contained in:
JosJuice 2020-09-18 18:53:01 +02:00
parent 33f15f22e2
commit 064cde9774
14 changed files with 137 additions and 4 deletions

View File

@ -77,4 +77,14 @@ public abstract class SettingsItem
AbstractSetting setting = getSetting(); AbstractSetting setting = getSetting();
return setting != null && setting.isRuntimeEditable(); return setting != null && setting.isRuntimeEditable();
} }
public boolean hasSetting()
{
return getSetting() != null;
}
public void clear(Settings settings)
{
getSetting().delete(settings);
}
} }

View File

@ -160,6 +160,14 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
notifyDataSetChanged(); notifyDataSetChanged();
} }
public void clearSetting(SettingsItem item, int position)
{
item.clear(getSettings());
notifyItemChanged(position);
mView.onSettingChanged();
}
public void onBooleanClick(CheckBoxSetting item, int position, boolean checked) public void onBooleanClick(CheckBoxSetting item, int position, boolean checked)
{ {
item.setChecked(getSettings(), checked); item.setChecked(getSettings(), checked);

View File

@ -225,6 +225,7 @@ public final class SettingsFragmentPresenter
sl.add(new SubmenuSetting(R.string.advanced_submenu, MenuTag.CONFIG_ADVANCED)); sl.add(new SubmenuSetting(R.string.advanced_submenu, MenuTag.CONFIG_ADVANCED));
sl.add(new SubmenuSetting(R.string.log_submenu, MenuTag.CONFIG_LOG)); sl.add(new SubmenuSetting(R.string.log_submenu, MenuTag.CONFIG_LOG));
sl.add(new SubmenuSetting(R.string.debug_submenu, MenuTag.DEBUG)); sl.add(new SubmenuSetting(R.string.debug_submenu, MenuTag.DEBUG));
sl.add(new HeaderSetting(R.string.setting_clear_info, 0));
} }
private void addGeneralSettings(ArrayList<SettingsItem> sl) private void addGeneralSettings(ArrayList<SettingsItem> sl)
@ -493,6 +494,7 @@ public final class SettingsFragmentPresenter
sl.add(new HeaderSetting(R.string.graphics_enhancements_and_hacks, 0)); sl.add(new HeaderSetting(R.string.graphics_enhancements_and_hacks, 0));
sl.add(new SubmenuSetting(R.string.enhancements_submenu, MenuTag.ENHANCEMENTS)); sl.add(new SubmenuSetting(R.string.enhancements_submenu, MenuTag.ENHANCEMENTS));
sl.add(new SubmenuSetting(R.string.hacks_submenu, MenuTag.HACKS)); sl.add(new SubmenuSetting(R.string.hacks_submenu, MenuTag.HACKS));
sl.add(new HeaderSetting(R.string.setting_clear_info, 0));
} }
private void addEnhanceSettings(ArrayList<SettingsItem> sl) private void addEnhanceSettings(ArrayList<SettingsItem> sl)

View File

@ -4,6 +4,8 @@ import android.view.View;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.Nullable;
import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.features.settings.model.view.CheckBoxSetting; import org.dolphinemu.dolphinemu.features.settings.model.view.CheckBoxSetting;
import org.dolphinemu.dolphinemu.features.settings.model.view.LogCheckBoxSetting; import org.dolphinemu.dolphinemu.features.settings.model.view.LogCheckBoxSetting;
@ -78,4 +80,10 @@ public final class CheckBoxSettingViewHolder extends SettingViewHolder
setStyle(mTextSettingName, mItem); setStyle(mTextSettingName, mItem);
} }
@Nullable @Override
protected SettingsItem getItem()
{
return mItem;
}
} }

View File

@ -4,6 +4,8 @@ import android.text.TextUtils;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.Nullable;
import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.features.settings.model.view.FilePicker; import org.dolphinemu.dolphinemu.features.settings.model.view.FilePicker;
import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem; import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem;
@ -82,4 +84,10 @@ public final class FilePickerViewHolder extends SettingViewHolder
setStyle(mTextSettingName, mItem); setStyle(mTextSettingName, mItem);
} }
@Nullable @Override
protected SettingsItem getItem()
{
return mItem;
}
} }

View File

@ -3,6 +3,8 @@ package org.dolphinemu.dolphinemu.features.settings.ui.viewholder;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.Nullable;
import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem; import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem;
import org.dolphinemu.dolphinemu.features.settings.ui.SettingsAdapter; import org.dolphinemu.dolphinemu.features.settings.ui.SettingsAdapter;
@ -34,4 +36,10 @@ public final class HeaderViewHolder extends SettingViewHolder
{ {
// no-op // no-op
} }
@Nullable @Override
protected SettingsItem getItem()
{
return null;
}
} }

View File

@ -6,6 +6,8 @@ import android.preference.PreferenceManager;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.Nullable;
import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.features.settings.model.view.InputBindingSetting; import org.dolphinemu.dolphinemu.features.settings.model.view.InputBindingSetting;
import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem; import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem;
@ -61,4 +63,10 @@ public final class InputBindingSettingViewHolder extends SettingViewHolder
setStyle(mTextSettingName, mItem); setStyle(mTextSettingName, mItem);
} }
@Nullable @Override
protected SettingsItem getItem()
{
return mItem;
}
} }

View File

@ -6,6 +6,8 @@ import android.preference.PreferenceManager;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.Nullable;
import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.features.settings.model.view.RumbleBindingSetting; import org.dolphinemu.dolphinemu.features.settings.model.view.RumbleBindingSetting;
import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem; import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem;
@ -61,4 +63,10 @@ public class RumbleBindingViewHolder extends SettingViewHolder
setStyle(mTextSettingName, mItem); setStyle(mTextSettingName, mItem);
} }
@Nullable @Override
protected SettingsItem getItem()
{
return mItem;
}
} }

View File

@ -5,6 +5,7 @@ import android.view.View;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.R;
@ -56,8 +57,8 @@ public final class RunRunnableViewHolder extends SettingViewHolder
if (alertTextID > 0) if (alertTextID > 0)
{ {
AlertDialog.Builder builder = new AlertDialog.Builder(mContext, R.style.DolphinDialogBase) AlertDialog.Builder builder = new AlertDialog.Builder(mContext, R.style.DolphinDialogBase)
.setTitle(mContext.getString(mItem.getNameId())) .setTitle(mItem.getNameId())
.setMessage(mContext.getString(alertTextID)); .setMessage(alertTextID);
builder builder
.setPositiveButton(R.string.ok, (dialog, whichButton) -> .setPositiveButton(R.string.ok, (dialog, whichButton) ->
@ -75,6 +76,12 @@ public final class RunRunnableViewHolder extends SettingViewHolder
} }
} }
@Nullable @Override
protected SettingsItem getItem()
{
return mItem;
}
private void runRunnable() private void runRunnable()
{ {
mItem.getRunnable().run(); mItem.getRunnable().run();

View File

@ -1,12 +1,14 @@
package org.dolphinemu.dolphinemu.features.settings.ui.viewholder; package org.dolphinemu.dolphinemu.features.settings.ui.viewholder;
import android.content.Context;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import org.dolphinemu.dolphinemu.DolphinApplication; import org.dolphinemu.dolphinemu.DolphinApplication;
@ -15,7 +17,7 @@ import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem;
import org.dolphinemu.dolphinemu.features.settings.ui.SettingsAdapter; import org.dolphinemu.dolphinemu.features.settings.ui.SettingsAdapter;
public abstract class SettingViewHolder extends RecyclerView.ViewHolder public abstract class SettingViewHolder extends RecyclerView.ViewHolder
implements View.OnClickListener implements View.OnClickListener, View.OnLongClickListener
{ {
private SettingsAdapter mAdapter; private SettingsAdapter mAdapter;
@ -26,6 +28,7 @@ public abstract class SettingViewHolder extends RecyclerView.ViewHolder
mAdapter = adapter; mAdapter = adapter;
itemView.setOnClickListener(this); itemView.setOnClickListener(this);
itemView.setOnLongClickListener(this);
findViews(itemView); findViews(itemView);
} }
@ -72,4 +75,40 @@ public abstract class SettingViewHolder extends RecyclerView.ViewHolder
* @param clicked The view that was clicked on. * @param clicked The view that was clicked on.
*/ */
public abstract void onClick(View clicked); public abstract void onClick(View clicked);
@Nullable
protected abstract SettingsItem getItem();
public boolean onLongClick(View clicked)
{
SettingsItem item = getItem();
if (item == null || !item.hasSetting())
return false;
if (!item.isEditable())
{
showNotRuntimeEditableError();
return true;
}
Context context = clicked.getContext();
AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.DolphinDialogBase)
.setMessage(R.string.setting_clear_confirm);
builder
.setPositiveButton(R.string.ok, (dialog, whichButton) ->
{
getAdapter().clearSetting(item, getAdapterPosition());
bind(item);
Toast.makeText(context, R.string.setting_cleared, Toast.LENGTH_SHORT).show();
dialog.dismiss();
})
.setNegativeButton(R.string.cancel, (dialog, whichButton) -> dialog.dismiss());
builder.show();
return true;
}
} }

View File

@ -4,6 +4,8 @@ import android.content.res.Resources;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.Nullable;
import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem; import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem;
import org.dolphinemu.dolphinemu.features.settings.model.view.SingleChoiceSetting; import org.dolphinemu.dolphinemu.features.settings.model.view.SingleChoiceSetting;
@ -110,4 +112,10 @@ public final class SingleChoiceViewHolder extends SettingViewHolder
setStyle(mTextSettingName, mItem); setStyle(mTextSettingName, mItem);
} }
@Nullable @Override
protected SettingsItem getItem()
{
return mItem;
}
} }

View File

@ -4,6 +4,8 @@ import android.content.Context;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.Nullable;
import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem; import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem;
import org.dolphinemu.dolphinemu.features.settings.model.view.SliderSetting; import org.dolphinemu.dolphinemu.features.settings.model.view.SliderSetting;
@ -66,5 +68,11 @@ public final class SliderViewHolder extends SettingViewHolder
setStyle(mTextSettingName, mItem); setStyle(mTextSettingName, mItem);
} }
@Nullable @Override
protected SettingsItem getItem()
{
return mItem;
}
} }

View File

@ -3,6 +3,8 @@ package org.dolphinemu.dolphinemu.features.settings.ui.viewholder;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.Nullable;
import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem; import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem;
import org.dolphinemu.dolphinemu.features.settings.model.view.SubmenuSetting; import org.dolphinemu.dolphinemu.features.settings.model.view.SubmenuSetting;
@ -38,4 +40,10 @@ public final class SubmenuViewHolder extends SettingViewHolder
{ {
getAdapter().onSubmenuClick(mItem); getAdapter().onSubmenuClick(mItem);
} }
@Nullable @Override
protected SettingsItem getItem()
{
return mItem;
}
} }

View File

@ -418,6 +418,9 @@ It can efficiently compress both junk data and encrypted Wii data.
<string name="write_permission_needed">You need to allow write access to external storage for the emulator to work</string> <string name="write_permission_needed">You need to allow write access to external storage for the emulator to work</string>
<string name="load_settings">Loading Settings...</string> <string name="load_settings">Loading Settings...</string>
<string name="setting_not_runtime_editable">This setting can\'t be changed while a game is running.</string> <string name="setting_not_runtime_editable">This setting can\'t be changed while a game is running.</string>
<string name="setting_clear_info">Long press a setting to clear it.</string>
<string name="setting_clear_confirm">Do you want to restore this setting to its default value?</string>
<string name="setting_cleared">Setting cleared</string>
<string name="emulation_change_disc">Change Disc</string> <string name="emulation_change_disc">Change Disc</string>
<string name="external_storage_not_mounted">The external storage needs to be available in order to use Dolphin</string> <string name="external_storage_not_mounted">The external storage needs to be available in order to use Dolphin</string>