Merge pull request #9095 from JosJuice/android-reset-setting

Android: Long press a setting to reset it
This commit is contained in:
Léo Lam 2020-11-23 02:50:40 +01:00 committed by GitHub
commit 17b11cf4a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 147 additions and 47 deletions

View File

@ -77,4 +77,14 @@ public abstract class SettingsItem
AbstractSetting setting = getSetting();
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();
}
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);
@ -317,21 +325,6 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
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();

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.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)
@ -356,8 +357,6 @@ 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 RunRunnable(R.string.reset_paths, 0, R.string.reset_paths_confirmation, 0,
mView.getAdapter()::resetPaths));
}
private void addGameCubeSettings(ArrayList<SettingsItem> sl)
@ -435,16 +434,19 @@ public final class SettingsFragmentPresenter
{
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,
@ -456,16 +458,19 @@ public final class SettingsFragmentPresenter
{
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,
@ -493,6 +498,7 @@ public final class SettingsFragmentPresenter
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)

View File

@ -4,6 +4,8 @@ import android.view.View;
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;
@ -78,4 +80,10 @@ public final class CheckBoxSettingViewHolder extends SettingViewHolder
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.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;
@ -82,4 +84,10 @@ public final class FilePickerViewHolder extends SettingViewHolder
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.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;
@ -34,4 +36,10 @@ public final class HeaderViewHolder extends SettingViewHolder
{
// 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.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;
@ -61,4 +63,10 @@ public final class InputBindingSettingViewHolder extends SettingViewHolder
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.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;
@ -61,4 +63,10 @@ public class RumbleBindingViewHolder extends SettingViewHolder
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.Toast;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import org.dolphinemu.dolphinemu.R;
@ -56,8 +57,8 @@ public final class RunRunnableViewHolder extends SettingViewHolder
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) ->
@ -75,6 +76,12 @@ public final class RunRunnableViewHolder extends SettingViewHolder
}
}
@Nullable @Override
protected SettingsItem getItem()
{
return mItem;
}
private void runRunnable()
{
mItem.getRunnable().run();

View File

@ -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;
@ -15,7 +17,7 @@ import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem;
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;
@ -26,6 +28,7 @@ public abstract class SettingViewHolder extends RecyclerView.ViewHolder
mAdapter = adapter;
itemView.setOnClickListener(this);
itemView.setOnLongClickListener(this);
findViews(itemView);
}
@ -72,4 +75,40 @@ public abstract class SettingViewHolder extends RecyclerView.ViewHolder
* @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;
}
}

View File

@ -4,6 +4,8 @@ import android.content.res.Resources;
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;
@ -110,4 +112,10 @@ public final class SingleChoiceViewHolder extends SettingViewHolder
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.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;
@ -66,5 +68,11 @@ public final class SliderViewHolder extends SettingViewHolder
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.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;
@ -38,4 +40,10 @@ public final class SubmenuViewHolder extends SettingViewHolder
{
getAdapter().onSubmenuClick(mItem);
}
@Nullable @Override
protected SettingsItem getItem()
{
return mItem;
}
}

View File

@ -215,11 +215,6 @@ public final class SettingsFile
public static void readFile(final String fileName, IniFile ini, SettingsActivityView view)
{
readFile(getSettingsFile(fileName), ini, view);
if (fileName.equals(Settings.FILE_DOLPHIN))
{
addGcPadSettingsIfTheyDontExist(ini);
}
}
/**
@ -328,19 +323,4 @@ public final class SettingsFile
return new File(wiiConfigPath);
}
private static void addGcPadSettingsIfTheyDontExist(IniFile ini)
{
IniFile.Section coreSection = ini.getOrCreateSection(Settings.SECTION_INI_CORE);
for (int i = 0; i < 4; i++)
{
String key = SettingsFile.KEY_GCPAD_TYPE + i;
if (!coreSection.exists(key))
{
// Set GameCube controller 1 to enabled, all others disabled
coreSection.setInt(key, i == 0 ? 6 : 0);
}
}
}
}

View File

@ -183,8 +183,6 @@
<string name="load_path">Load Path</string>
<string name="resource_pack_path">Resource Pack Path</string>
<string name="SD_card_path">SD Card Path</string>
<string name="reset_paths">Reset Paths to Default Settings</string>
<string name="reset_paths_confirmation">Are you sure you want to reset Paths to default settings?</string>
<!-- Graphics Settings -->
<string name="graphics_general">General</string>
@ -418,6 +416,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="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_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="external_storage_not_mounted">The external storage needs to be available in order to use Dolphin</string>