Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #9095 from JosJuice/android-reset-setting
Android: Long press a setting to reset it
  • Loading branch information
leoetlino committed Nov 23, 2020
2 parents b555f0f + 115dede commit 17b11cf
Show file tree
Hide file tree
Showing 15 changed files with 147 additions and 47 deletions.
Expand Up @@ -77,4 +77,14 @@ public boolean isEditable()
AbstractSetting setting = getSetting();
return setting != null && setting.isRuntimeEditable();
}

public boolean hasSetting()
{
return getSetting() != null;
}

public void clear(Settings settings)
{
getSetting().delete(settings);
}
}
Expand Up @@ -160,6 +160,14 @@ public void setSettings(ArrayList<SettingsItem> settings)
notifyDataSetChanged();
}

public void clearSetting(SettingsItem item, int position)
{
item.clear(getSettings());
notifyItemChanged(position);

mView.onSettingChanged();
}

public void onBooleanClick(CheckBoxSetting item, int position, boolean checked)
{
item.setChecked(getSettings(), checked);
Expand Down Expand Up @@ -317,21 +325,6 @@ public void onFilePickerConfirmation(String selectedFile)
mClickedItem = null;
}

public void resetPaths()
{
Settings settings = mView.getSettings();

StringSetting.MAIN_DEFAULT_ISO.delete(settings);
StringSetting.MAIN_FS_PATH.delete(settings);
StringSetting.MAIN_DUMP_PATH.delete(settings);
StringSetting.MAIN_LOAD_PATH.delete(settings);
StringSetting.MAIN_RESOURCEPACK_PATH.delete(settings);
StringSetting.MAIN_SD_PATH.delete(settings);

notifyItemRangeChanged(0, getItemCount());
mView.onSettingChanged();
}

public void setAllLogTypes(boolean value)
{
Settings settings = mView.getSettings();
Expand Down
Expand Up @@ -225,6 +225,7 @@ private void addConfigSettings(ArrayList<SettingsItem> sl)
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.debug_submenu, MenuTag.DEBUG));
sl.add(new HeaderSetting(R.string.setting_clear_info, 0));
}

private void addGeneralSettings(ArrayList<SettingsItem> sl)
Expand Down Expand Up @@ -356,8 +357,6 @@ 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 RunRunnable(R.string.reset_paths, 0, R.string.reset_paths_confirmation, 0,
mView.getAdapter()::resetPaths));
}

private void addGameCubeSettings(ArrayList<SettingsItem> sl)
Expand Down Expand Up @@ -435,16 +434,19 @@ private void addGcPadSettings(ArrayList<SettingsItem> sl)
{
for (int i = 0; i < 4; i++)
{
// GameCube controller 1 is set to Emulated by default, all others disabled
int defaultValue = i == 0 ? 6 : 0;

LegacyIntSetting gcPadSetting;
if (mGameID.equals(""))
{
gcPadSetting = new LegacyIntSetting(Settings.FILE_DOLPHIN, Settings.SECTION_INI_CORE,
SettingsFile.KEY_GCPAD_TYPE + i, 0);
SettingsFile.KEY_GCPAD_TYPE + i, defaultValue);
}
else
{
gcPadSetting = new LegacyIntSetting(Settings.GAME_SETTINGS_PLACEHOLDER_FILE_NAME,
Settings.SECTION_CONTROLS, SettingsFile.KEY_GCPAD_G_TYPE + i, 0);
Settings.SECTION_CONTROLS, SettingsFile.KEY_GCPAD_G_TYPE + i, defaultValue);
}
// TODO: This controller_0 + i business is quite the hack. It should work, but only if the definitions are kept together and in order.
sl.add(new SingleChoiceSetting(gcPadSetting, R.string.controller_0 + i, 0,
Expand All @@ -456,16 +458,19 @@ private void addWiimoteSettings(ArrayList<SettingsItem> sl)
{
for (int i = 0; i < 4; i++)
{
// Wii Remote 1 is set to Emulated by default, all others disabled
int defaultValue = i == 0 ? 1 : 0;

LegacyIntSetting wiimoteSetting;
if (mGameID.equals(""))
{
wiimoteSetting = new LegacyIntSetting(Settings.FILE_WIIMOTE,
Settings.SECTION_WIIMOTE + (i + 1), SettingsFile.KEY_WIIMOTE_TYPE, 0);
Settings.SECTION_WIIMOTE + (i + 1), SettingsFile.KEY_WIIMOTE_TYPE, defaultValue);
}
else
{
wiimoteSetting = new LegacyIntSetting(Settings.GAME_SETTINGS_PLACEHOLDER_FILE_NAME,
Settings.SECTION_CONTROLS, SettingsFile.KEY_WIIMOTE_G_TYPE + i, 0);
Settings.SECTION_CONTROLS, SettingsFile.KEY_WIIMOTE_G_TYPE + i, defaultValue);
}
// TODO: This wiimote_0 + i business is quite the hack. It should work, but only if the definitions are kept together and in order.
sl.add(new SingleChoiceSetting(wiimoteSetting, R.string.wiimote_4 + i, 0,
Expand Down Expand Up @@ -493,6 +498,7 @@ private void addGraphicsSettings(ArrayList<SettingsItem> sl)
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.hacks_submenu, MenuTag.HACKS));
sl.add(new HeaderSetting(R.string.setting_clear_info, 0));
}

private void addEnhanceSettings(ArrayList<SettingsItem> sl)
Expand Down
Expand Up @@ -4,6 +4,8 @@
import android.widget.CheckBox;
import android.widget.TextView;

import androidx.annotation.Nullable;

import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.features.settings.model.view.CheckBoxSetting;
import org.dolphinemu.dolphinemu.features.settings.model.view.LogCheckBoxSetting;
Expand Down Expand Up @@ -78,4 +80,10 @@ public void onClick(View clicked)

setStyle(mTextSettingName, mItem);
}

@Nullable @Override
protected SettingsItem getItem()
{
return mItem;
}
}
Expand Up @@ -4,6 +4,8 @@
import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;

import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.features.settings.model.view.FilePicker;
import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem;
Expand Down Expand Up @@ -82,4 +84,10 @@ public void onClick(View clicked)

setStyle(mTextSettingName, mItem);
}

@Nullable @Override
protected SettingsItem getItem()
{
return mItem;
}
}
Expand Up @@ -3,6 +3,8 @@
import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;

import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem;
import org.dolphinemu.dolphinemu.features.settings.ui.SettingsAdapter;
Expand Down Expand Up @@ -34,4 +36,10 @@ public void onClick(View clicked)
{
// no-op
}

@Nullable @Override
protected SettingsItem getItem()
{
return null;
}
}
Expand Up @@ -6,6 +6,8 @@
import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;

import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.features.settings.model.view.InputBindingSetting;
import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem;
Expand Down Expand Up @@ -61,4 +63,10 @@ public void onClick(View clicked)

setStyle(mTextSettingName, mItem);
}

@Nullable @Override
protected SettingsItem getItem()
{
return mItem;
}
}
Expand Up @@ -6,6 +6,8 @@
import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;

import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.features.settings.model.view.RumbleBindingSetting;
import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem;
Expand Down Expand Up @@ -61,4 +63,10 @@ public void onClick(View clicked)

setStyle(mTextSettingName, mItem);
}

@Nullable @Override
protected SettingsItem getItem()
{
return mItem;
}
}
Expand Up @@ -5,6 +5,7 @@
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;

import org.dolphinemu.dolphinemu.R;
Expand Down Expand Up @@ -56,8 +57,8 @@ public void onClick(View clicked)
if (alertTextID > 0)
{
AlertDialog.Builder builder = new AlertDialog.Builder(mContext, R.style.DolphinDialogBase)
.setTitle(mContext.getString(mItem.getNameId()))
.setMessage(mContext.getString(alertTextID));
.setTitle(mItem.getNameId())
.setMessage(alertTextID);

builder
.setPositiveButton(R.string.ok, (dialog, whichButton) ->
Expand All @@ -75,6 +76,12 @@ public void onClick(View clicked)
}
}

@Nullable @Override
protected SettingsItem getItem()
{
return mItem;
}

private void runRunnable()
{
mItem.getRunnable().run();
Expand Down
@@ -1,12 +1,14 @@
package org.dolphinemu.dolphinemu.features.settings.ui.viewholder;


import android.content.Context;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.recyclerview.widget.RecyclerView;

import org.dolphinemu.dolphinemu.DolphinApplication;
Expand All @@ -15,7 +17,7 @@
import org.dolphinemu.dolphinemu.features.settings.ui.SettingsAdapter;

public abstract class SettingViewHolder extends RecyclerView.ViewHolder
implements View.OnClickListener
implements View.OnClickListener, View.OnLongClickListener
{
private SettingsAdapter mAdapter;

Expand All @@ -26,6 +28,7 @@ public SettingViewHolder(View itemView, SettingsAdapter adapter)
mAdapter = adapter;

itemView.setOnClickListener(this);
itemView.setOnLongClickListener(this);

findViews(itemView);
}
Expand Down Expand Up @@ -72,4 +75,40 @@ protected static void showNotRuntimeEditableError()
* @param clicked The view that was clicked on.
*/
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;
}
}
Expand Up @@ -4,6 +4,8 @@
import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;

import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem;
import org.dolphinemu.dolphinemu.features.settings.model.view.SingleChoiceSetting;
Expand Down Expand Up @@ -110,4 +112,10 @@ else if (mItem instanceof SingleChoiceSettingDynamicDescriptions)

setStyle(mTextSettingName, mItem);
}

@Nullable @Override
protected SettingsItem getItem()
{
return mItem;
}
}
Expand Up @@ -4,6 +4,8 @@
import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;

import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem;
import org.dolphinemu.dolphinemu.features.settings.model.view.SliderSetting;
Expand Down Expand Up @@ -66,5 +68,11 @@ public void onClick(View clicked)

setStyle(mTextSettingName, mItem);
}

@Nullable @Override
protected SettingsItem getItem()
{
return mItem;
}
}

Expand Up @@ -3,6 +3,8 @@
import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;

import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem;
import org.dolphinemu.dolphinemu.features.settings.model.view.SubmenuSetting;
Expand Down Expand Up @@ -38,4 +40,10 @@ public void onClick(View clicked)
{
getAdapter().onSubmenuClick(mItem);
}

@Nullable @Override
protected SettingsItem getItem()
{
return mItem;
}
}

0 comments on commit 17b11cf

Please sign in to comment.