Android: Remove some static variables from SettingsAdapter
All of these have non-static equivalents (mView and mClickedItem).
This commit is contained in:
parent
25ebc3c07c
commit
e3911736c2
|
@ -179,7 +179,8 @@ public final class SettingsActivity extends AppCompatActivity implements Setting
|
||||||
// If the user picked a file, as opposed to just backing out.
|
// If the user picked a file, as opposed to just backing out.
|
||||||
if (resultCode == MainActivity.RESULT_OK)
|
if (resultCode == MainActivity.RESULT_OK)
|
||||||
{
|
{
|
||||||
mPresenter.onFileConfirmed(FileBrowserHelper.getSelectedPath(result));
|
String path = FileBrowserHelper.getSelectedPath(result);
|
||||||
|
getFragment().getAdapter().onFilePickerConfirmation(path);
|
||||||
|
|
||||||
// Prevent duplicate Toasts.
|
// Prevent duplicate Toasts.
|
||||||
if (!mPresenter.shouldSave())
|
if (!mPresenter.shouldSave())
|
||||||
|
|
|
@ -235,9 +235,4 @@ public final class SettingsActivityPresenter
|
||||||
mView.showSettingsFragment(menuTag, bundle, true, gameId);
|
mView.showSettingsFragment(menuTag, bundle, true, gameId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onFileConfirmed(String file)
|
|
||||||
{
|
|
||||||
SettingsAdapter.onFilePickerConfirmation(file);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,6 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
|
||||||
implements DialogInterface.OnClickListener, SeekBar.OnSeekBarChangeListener
|
implements DialogInterface.OnClickListener, SeekBar.OnSeekBarChangeListener
|
||||||
{
|
{
|
||||||
private SettingsFragmentView mView;
|
private SettingsFragmentView mView;
|
||||||
private static SettingsFragmentView sView;
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private ArrayList<SettingsItem> mSettings;
|
private ArrayList<SettingsItem> mSettings;
|
||||||
|
|
||||||
|
@ -67,14 +66,9 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
|
||||||
private AlertDialog mDialog;
|
private AlertDialog mDialog;
|
||||||
private TextView mTextSliderValue;
|
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)
|
public SettingsAdapter(SettingsFragmentView view, Context context)
|
||||||
{
|
{
|
||||||
mView = view;
|
mView = view;
|
||||||
sView = view;
|
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mClickedPosition = -1;
|
mClickedPosition = -1;
|
||||||
}
|
}
|
||||||
|
@ -303,19 +297,18 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
|
||||||
|
|
||||||
public void onFilePickerDirectoryClick(SettingsItem item)
|
public void onFilePickerDirectoryClick(SettingsItem item)
|
||||||
{
|
{
|
||||||
sFilePicker = (FilePicker) item;
|
mClickedItem = item;
|
||||||
sItem = item;
|
|
||||||
|
|
||||||
FileBrowserHelper.openDirectoryPicker(mView.getActivity(), FileBrowserHelper.GAME_EXTENSIONS);
|
FileBrowserHelper.openDirectoryPicker(mView.getActivity(), FileBrowserHelper.GAME_EXTENSIONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onFilePickerFileClick(SettingsItem item)
|
public void onFilePickerFileClick(SettingsItem item)
|
||||||
{
|
{
|
||||||
sFilePicker = (FilePicker) item;
|
mClickedItem = item;
|
||||||
sItem = item;
|
FilePicker filePicker = (FilePicker) item;
|
||||||
|
|
||||||
HashSet<String> extensions;
|
HashSet<String> extensions;
|
||||||
switch (sFilePicker.getRequestType())
|
switch (filePicker.getRequestType())
|
||||||
{
|
{
|
||||||
case MainPresenter.REQUEST_SD_FILE:
|
case MainPresenter.REQUEST_SD_FILE:
|
||||||
extensions = FileBrowserHelper.RAW_EXTENSION;
|
extensions = FileBrowserHelper.RAW_EXTENSION;
|
||||||
|
@ -330,17 +323,22 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
|
||||||
throw new InvalidParameterException("Unhandled request code");
|
throw new InvalidParameterException("Unhandled request code");
|
||||||
}
|
}
|
||||||
|
|
||||||
FileBrowserHelper.openFilePicker(mView.getActivity(), sFilePicker.getRequestType(), false,
|
FileBrowserHelper.openFilePicker(mView.getActivity(), filePicker.getRequestType(), false,
|
||||||
extensions);
|
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();
|
NativeLibrary.ReloadConfig();
|
||||||
|
|
||||||
|
mClickedItem = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void resetPaths()
|
public void resetPaths()
|
||||||
{
|
{
|
||||||
StringSetting defaultISO =
|
StringSetting defaultISO =
|
||||||
new StringSetting(SettingsFile.KEY_DEFAULT_ISO, Settings.SECTION_INI_CORE, "");
|
new StringSetting(SettingsFile.KEY_DEFAULT_ISO, Settings.SECTION_INI_CORE, "");
|
||||||
|
@ -360,23 +358,23 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
|
||||||
new StringSetting(SettingsFile.KEY_WII_SD_CARD_PATH, Settings.SECTION_INI_GENERAL,
|
new StringSetting(SettingsFile.KEY_WII_SD_CARD_PATH, Settings.SECTION_INI_GENERAL,
|
||||||
SettingsFragmentPresenter.getDefaultSDPath());
|
SettingsFragmentPresenter.getDefaultSDPath());
|
||||||
|
|
||||||
sView.putSetting(defaultISO);
|
mView.putSetting(defaultISO);
|
||||||
sView.putSetting(NANDRootPath);
|
mView.putSetting(NANDRootPath);
|
||||||
sView.putSetting(dumpPath);
|
mView.putSetting(dumpPath);
|
||||||
sView.putSetting(loadPath);
|
mView.putSetting(loadPath);
|
||||||
sView.putSetting(resourcePackPath);
|
mView.putSetting(resourcePackPath);
|
||||||
sView.putSetting(sdPath);
|
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())
|
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)
|
private void handleMenuTag(MenuTag menuTag, int value)
|
||||||
|
|
|
@ -179,6 +179,12 @@ public final class SettingsFragment extends Fragment implements SettingsFragment
|
||||||
mPresenter.loadDefaultSettings();
|
mPresenter.loadDefaultSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SettingsAdapter getAdapter()
|
||||||
|
{
|
||||||
|
return mAdapter;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadSubMenu(MenuTag menuKey)
|
public void loadSubMenu(MenuTag menuKey)
|
||||||
{
|
{
|
||||||
|
|
|
@ -368,7 +368,7 @@ public final class SettingsFragmentPresenter
|
||||||
Settings.SECTION_INI_GENERAL, R.string.SD_card_path, 0, getDefaultSDPath(),
|
Settings.SECTION_INI_GENERAL, R.string.SD_card_path, 0, getDefaultSDPath(),
|
||||||
MainPresenter.REQUEST_SD_FILE, wiiSDCardPath));
|
MainPresenter.REQUEST_SD_FILE, wiiSDCardPath));
|
||||||
sl.add(new ConfirmRunnable(R.string.reset_paths, 0, R.string.reset_paths_confirmation, 0,
|
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)
|
private void addGameCubeSettings(ArrayList<SettingsItem> sl)
|
||||||
|
@ -752,11 +752,9 @@ public final class SettingsFragmentPresenter
|
||||||
R.string.log_verbosity, 0, getLogVerbosityEntries(), getLogVerbosityValues(), 1,
|
R.string.log_verbosity, 0, getLogVerbosityEntries(), getLogVerbosityValues(), 1,
|
||||||
logVerbosity));
|
logVerbosity));
|
||||||
sl.add(new ConfirmRunnable(R.string.log_enable_all, 0, R.string.log_enable_all_confirmation, 0,
|
sl.add(new ConfirmRunnable(R.string.log_enable_all, 0, R.string.log_enable_all_confirmation, 0,
|
||||||
() -> SettingsAdapter.setAllLogTypes("True")));
|
() -> mView.getAdapter().setAllLogTypes("True")));
|
||||||
sl.add(
|
sl.add(new ConfirmRunnable(R.string.log_disable_all, 0, R.string.log_disable_all_confirmation,
|
||||||
new ConfirmRunnable(R.string.log_disable_all, 0, R.string.log_disable_all_confirmation,
|
0, () -> mView.getAdapter().setAllLogTypes("False")));
|
||||||
0,
|
|
||||||
() -> SettingsAdapter.setAllLogTypes("False")));
|
|
||||||
|
|
||||||
sl.add(new HeaderSetting(null, null, R.string.log_types, 0));
|
sl.add(new HeaderSetting(null, null, R.string.log_types, 0));
|
||||||
for (Map.Entry<String, String> entry : LOG_TYPE_NAMES.entrySet())
|
for (Map.Entry<String, String> entry : LOG_TYPE_NAMES.entrySet())
|
||||||
|
|
|
@ -49,6 +49,11 @@ public interface SettingsFragmentView
|
||||||
*/
|
*/
|
||||||
FragmentActivity getActivity();
|
FragmentActivity getActivity();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The Fragment's SettingsAdapter.
|
||||||
|
*/
|
||||||
|
SettingsAdapter getAdapter();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tell the Fragment to tell the containing Activity to show a new
|
* Tell the Fragment to tell the containing Activity to show a new
|
||||||
* Fragment containing a submenu of settings.
|
* Fragment containing a submenu of settings.
|
||||||
|
|
Loading…
Reference in New Issue