Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #9010 from JosJuice/android-settingsadapter-redund…
…ant-static

Android: Remove some static variables from SettingsAdapter
  • Loading branch information
lioncash committed Aug 6, 2020
2 parents 7b3056f + e391173 commit d8c0344
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 37 deletions.
Expand Up @@ -182,7 +182,8 @@ protected void onActivityResult(int requestCode, int resultCode, Intent result)
// If the user picked a file, as opposed to just backing out.
if (resultCode == MainActivity.RESULT_OK)
{
mPresenter.onFileConfirmed(FileBrowserHelper.getSelectedPath(result));
String path = FileBrowserHelper.getSelectedPath(result);
getFragment().getAdapter().onFilePickerConfirmation(path);

// Prevent duplicate Toasts.
if (!mPresenter.shouldSave())
Expand Down
Expand Up @@ -231,9 +231,4 @@ public void onExtensionSettingChanged(MenuTag menuTag, int value)
mView.showSettingsFragment(menuTag, bundle, true, gameId);
}
}

public void onFileConfirmed(String file)
{
SettingsAdapter.onFilePickerConfirmation(file);
}
}
Expand Up @@ -56,7 +56,6 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
implements DialogInterface.OnClickListener, SeekBar.OnSeekBarChangeListener
{
private SettingsFragmentView mView;
private static SettingsFragmentView sView;
private Context mContext;
private ArrayList<SettingsItem> mSettings;

Expand All @@ -67,14 +66,9 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
private AlertDialog mDialog;
private TextView mTextSliderValue;

// TODO: Properly restore these two on activity recreation
private static FilePicker sFilePicker;
private static SettingsItem sItem;

public SettingsAdapter(SettingsFragmentView view, Context context)
{
mView = view;
sView = view;
mContext = context;
mClickedPosition = -1;
}
Expand Down Expand Up @@ -303,19 +297,18 @@ public void onInputBindingClick(final InputBindingSetting item, final int positi

public void onFilePickerDirectoryClick(SettingsItem item)
{
sFilePicker = (FilePicker) item;
sItem = item;
mClickedItem = item;

FileBrowserHelper.openDirectoryPicker(mView.getActivity(), FileBrowserHelper.GAME_EXTENSIONS);
}

public void onFilePickerFileClick(SettingsItem item)
{
sFilePicker = (FilePicker) item;
sItem = item;
mClickedItem = item;
FilePicker filePicker = (FilePicker) item;

HashSet<String> extensions;
switch (sFilePicker.getRequestType())
switch (filePicker.getRequestType())
{
case MainPresenter.REQUEST_SD_FILE:
extensions = FileBrowserHelper.RAW_EXTENSION;
Expand All @@ -330,17 +323,22 @@ public void onFilePickerFileClick(SettingsItem item)
throw new InvalidParameterException("Unhandled request code");
}

FileBrowserHelper.openFilePicker(mView.getActivity(), sFilePicker.getRequestType(), false,
FileBrowserHelper.openFilePicker(mView.getActivity(), filePicker.getRequestType(), false,
extensions);
}

public static void onFilePickerConfirmation(String file)
public void onFilePickerConfirmation(String file)
{
NativeLibrary.SetConfig(sFilePicker.getFile(), sItem.getSection(), sItem.getKey(), file);
FilePicker filePicker = (FilePicker) mClickedItem;

NativeLibrary.SetConfig(filePicker.getFile(), filePicker.getSection(), filePicker.getKey(),
file);
NativeLibrary.ReloadConfig();

mClickedItem = null;
}

public static void resetPaths()
public void resetPaths()
{
StringSetting defaultISO =
new StringSetting(SettingsFile.KEY_DEFAULT_ISO, Settings.SECTION_INI_CORE, "");
Expand All @@ -360,23 +358,23 @@ public static void resetPaths()
new StringSetting(SettingsFile.KEY_WII_SD_CARD_PATH, Settings.SECTION_INI_GENERAL,
SettingsFragmentPresenter.getDefaultSDPath());

sView.putSetting(defaultISO);
sView.putSetting(NANDRootPath);
sView.putSetting(dumpPath);
sView.putSetting(loadPath);
sView.putSetting(resourcePackPath);
sView.putSetting(sdPath);
mView.putSetting(defaultISO);
mView.putSetting(NANDRootPath);
mView.putSetting(dumpPath);
mView.putSetting(loadPath);
mView.putSetting(resourcePackPath);
mView.putSetting(sdPath);

sView.onSettingChanged(null);
mView.onSettingChanged(null);
}

public static void setAllLogTypes(String value)
public void setAllLogTypes(String value)
{
for (Map.Entry<String, String> entry : SettingsFragmentPresenter.LOG_TYPE_NAMES.entrySet())
{
sView.putSetting(new StringSetting(entry.getKey(), Settings.SECTION_LOGGER_LOGS, value));
mView.putSetting(new StringSetting(entry.getKey(), Settings.SECTION_LOGGER_LOGS, value));
}
sView.onSettingChanged(null);
mView.onSettingChanged(null);
}

private void handleMenuTag(MenuTag menuTag, int value)
Expand Down
Expand Up @@ -168,6 +168,12 @@ public void loadDefaultSettings()
mPresenter.loadDefaultSettings();
}

@Override
public SettingsAdapter getAdapter()
{
return mAdapter;
}

@Override
public void loadSubMenu(MenuTag menuKey)
{
Expand Down
Expand Up @@ -355,7 +355,7 @@ private void addPathsSettings(ArrayList<SettingsItem> sl)
Settings.SECTION_INI_GENERAL, R.string.SD_card_path, 0, getDefaultSDPath(),
MainPresenter.REQUEST_SD_FILE, wiiSDCardPath));
sl.add(new ConfirmRunnable(R.string.reset_paths, 0, R.string.reset_paths_confirmation, 0,
SettingsAdapter::resetPaths));
mView.getAdapter()::resetPaths));
}

private void addGameCubeSettings(ArrayList<SettingsItem> sl)
Expand Down Expand Up @@ -739,11 +739,9 @@ private void addLogConfigurationSettings(ArrayList<SettingsItem> sl)
R.string.log_verbosity, 0, getLogVerbosityEntries(), getLogVerbosityValues(), 1,
logVerbosity));
sl.add(new ConfirmRunnable(R.string.log_enable_all, 0, R.string.log_enable_all_confirmation, 0,
() -> SettingsAdapter.setAllLogTypes("True")));
sl.add(
new ConfirmRunnable(R.string.log_disable_all, 0, R.string.log_disable_all_confirmation,
0,
() -> SettingsAdapter.setAllLogTypes("False")));
() -> 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 HeaderSetting(null, null, R.string.log_types, 0));
for (Map.Entry<String, String> entry : LOG_TYPE_NAMES.entrySet())
Expand Down
Expand Up @@ -40,6 +40,11 @@
*/
FragmentActivity getActivity();

/**
* @return The Fragment's SettingsAdapter.
*/
SettingsAdapter getAdapter();

/**
* Tell the Fragment to tell the containing Activity to show a new
* Fragment containing a submenu of settings.
Expand Down

0 comments on commit d8c0344

Please sign in to comment.