Android: Don't let onSettingChanged clobber ConfirmRunnable changes

This commit is contained in:
Ryan Meredith 2020-03-24 17:08:35 -04:00
parent de5430b222
commit d15d6e70d7
10 changed files with 45 additions and 54 deletions

View File

@ -27,8 +27,7 @@ public enum MenuTag
WIIMOTE_EXTENSION_1("wiimote_extension", 4), WIIMOTE_EXTENSION_1("wiimote_extension", 4),
WIIMOTE_EXTENSION_2("wiimote_extension", 5), WIIMOTE_EXTENSION_2("wiimote_extension", 5),
WIIMOTE_EXTENSION_3("wiimote_extension", 6), WIIMOTE_EXTENSION_3("wiimote_extension", 6),
WIIMOTE_EXTENSION_4("wiimote_extension", 7), WIIMOTE_EXTENSION_4("wiimote_extension", 7);
BLANK("Blank");
private String tag; private String tag;
private int subType = -1; private int subType = -1;

View File

@ -105,13 +105,13 @@ public final class SettingsActivity extends AppCompatActivity implements Setting
@Override @Override
public void showSettingsFragment(MenuTag menuTag, Bundle extras, boolean addToStack, public void showSettingsFragment(MenuTag menuTag, Bundle extras, boolean addToStack,
boolean customAnimations, String gameID) String gameID)
{ {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
if (addToStack) if (addToStack)
{ {
if (areSystemAnimationsEnabled() && customAnimations) if (areSystemAnimationsEnabled())
{ {
transaction.setCustomAnimations( transaction.setCustomAnimations(
R.animator.settings_enter, R.animator.settings_enter,

View File

@ -70,7 +70,7 @@ public final class SettingsActivityPresenter
} }
} }
mView.showSettingsFragment(menuTag, null, false, true, gameId); mView.showSettingsFragment(menuTag, null, false, gameId);
mView.onSettingsFileLoaded(mSettings); mView.onSettingsFileLoaded(mSettings);
} }
@ -195,7 +195,7 @@ public final class SettingsActivityPresenter
{ {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putInt(SettingsFragmentPresenter.ARG_CONTROLLER_TYPE, value / 6); bundle.putInt(SettingsFragmentPresenter.ARG_CONTROLLER_TYPE, value / 6);
mView.showSettingsFragment(key, bundle, true, true, gameId); mView.showSettingsFragment(key, bundle, true, gameId);
} }
} }
@ -204,7 +204,7 @@ public final class SettingsActivityPresenter
switch (value) switch (value)
{ {
case 1: case 1:
mView.showSettingsFragment(menuTag, null, true, true, gameId); mView.showSettingsFragment(menuTag, null, true, gameId);
break; break;
case 2: case 2:
@ -219,7 +219,7 @@ public final class SettingsActivityPresenter
{ {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putInt(SettingsFragmentPresenter.ARG_CONTROLLER_TYPE, value); bundle.putInt(SettingsFragmentPresenter.ARG_CONTROLLER_TYPE, value);
mView.showSettingsFragment(menuTag, bundle, true, true, gameId); mView.showSettingsFragment(menuTag, bundle, true, gameId);
} }
} }

View File

@ -14,12 +14,10 @@ public interface SettingsActivityView
/** /**
* Show a new SettingsFragment. * Show a new SettingsFragment.
* *
* @param menuTag Identifier for the settings group that should be displayed. * @param menuTag Identifier for the settings group that should be displayed.
* @param addToStack Whether or not this fragment should replace a previous one. * @param addToStack Whether or not this fragment should replace a previous one.
* @param customAnimations Custom animations are used if true while system animations are enabled.
*/ */
void showSettingsFragment(MenuTag menuTag, Bundle extras, boolean addToStack, void showSettingsFragment(MenuTag menuTag, Bundle extras, boolean addToStack, String gameId);
boolean customAnimations, String gameId);
/** /**
* Called by a contained Fragment to get access to the Setting HashMap * Called by a contained Fragment to get access to the Setting HashMap

View File

@ -55,6 +55,7 @@ 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;
@ -72,6 +73,7 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
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;
} }
@ -332,20 +334,32 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
public static void resetPaths() public static void resetPaths()
{ {
NativeLibrary.SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_CORE, StringSetting defaultISO =
SettingsFile.KEY_DEFAULT_ISO, ""); new StringSetting(SettingsFile.KEY_DEFAULT_ISO, Settings.SECTION_INI_CORE, "");
NativeLibrary.SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_GENERAL, StringSetting NANDRootPath =
SettingsFile.KEY_NAND_ROOT_PATH, SettingsFragmentPresenter.getDefaultNANDRootPath()); new StringSetting(SettingsFile.KEY_NAND_ROOT_PATH, Settings.SECTION_INI_GENERAL,
NativeLibrary.SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_GENERAL, SettingsFragmentPresenter.getDefaultNANDRootPath());
SettingsFile.KEY_DUMP_PATH, SettingsFragmentPresenter.getDefaultDumpPath()); StringSetting dumpPath =
NativeLibrary.SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_GENERAL, new StringSetting(SettingsFile.KEY_DUMP_PATH, Settings.SECTION_INI_GENERAL,
SettingsFile.KEY_LOAD_PATH, SettingsFragmentPresenter.getDefaultLoadPath()); SettingsFragmentPresenter.getDefaultDumpPath());
NativeLibrary.SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_GENERAL, StringSetting loadPath =
SettingsFile.KEY_RESOURCE_PACK_PATH, new StringSetting(SettingsFile.KEY_LOAD_PATH, Settings.SECTION_INI_GENERAL,
SettingsFragmentPresenter.getDefaultResourcePackPath()); SettingsFragmentPresenter.getDefaultLoadPath());
NativeLibrary.SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_GENERAL, StringSetting resourcePackPath =
SettingsFile.KEY_WII_SD_CARD_PATH, SettingsFragmentPresenter.getDefaultSDPath()); new StringSetting(SettingsFile.KEY_RESOURCE_PACK_PATH, Settings.SECTION_INI_GENERAL,
NativeLibrary.ReloadConfig(); SettingsFragmentPresenter.getDefaultResourcePackPath());
StringSetting sdPath =
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);
sView.onSettingChanged();
} }
@Override @Override

View File

@ -20,7 +20,6 @@ import org.dolphinemu.dolphinemu.ui.DividerItemDecoration;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Objects;
public final class SettingsFragment extends Fragment implements SettingsFragmentView public final class SettingsFragment extends Fragment implements SettingsFragmentView
{ {
@ -180,18 +179,7 @@ public final class SettingsFragment extends Fragment implements SettingsFragment
@Override @Override
public void loadSubMenu(MenuTag menuKey) public void loadSubMenu(MenuTag menuKey)
{ {
mActivity mActivity.showSettingsFragment(menuKey, null, true, getArguments().getString(ARGUMENT_GAME_ID));
.showSettingsFragment(menuKey, null, true, true,
getArguments().getString(ARGUMENT_GAME_ID));
}
@Override
public void reloadSubMenu()
{
mActivity
.showSettingsFragment(MenuTag.BLANK, null, true, false,
getArguments().getString(ARGUMENT_GAME_ID));
Objects.requireNonNull(getActivity()).onBackPressed();
} }
@Override @Override

View File

@ -197,9 +197,6 @@ public final class SettingsFragmentPresenter
addStereoSettings(sl); addStereoSettings(sl);
break; break;
case BLANK:
break;
default: default:
mView.showToastMessage("Unimplemented menu"); mView.showToastMessage("Unimplemented menu");
return; return;
@ -353,8 +350,8 @@ public final class SettingsFragmentPresenter
sl.add(new FilePicker(SettingsFile.FILE_NAME_DOLPHIN, SettingsFile.KEY_WII_SD_CARD_PATH, sl.add(new FilePicker(SettingsFile.FILE_NAME_DOLPHIN, SettingsFile.KEY_WII_SD_CARD_PATH,
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, sl.add(new ConfirmRunnable(R.string.reset_paths, 0, R.string.reset_paths_confirmation, 0,
R.string.reset_paths_complete, () -> SettingsAdapter.resetPaths())); SettingsAdapter::resetPaths));
} }
private void addGameCubeSettings(ArrayList<SettingsItem> sl) private void addGameCubeSettings(ArrayList<SettingsItem> sl)

View File

@ -57,12 +57,6 @@ public interface SettingsFragmentView
*/ */
void loadSubMenu(MenuTag menuKey); void loadSubMenu(MenuTag menuKey);
/**
* Show a new blank submenu and then immediately back out of it.
* Useful for updating dynamic setting descriptions.
*/
void reloadSubMenu();
/** /**
* Tell the Fragment to tell the containing activity to display a toast message. * Tell the Fragment to tell the containing activity to display a toast message.
* *

View File

@ -57,7 +57,6 @@ public final class ConfirmRunnableViewHolder extends SettingViewHolder
{ {
String alertTitle = mContext.getString(mItem.getNameId()); String alertTitle = mContext.getString(mItem.getNameId());
String alertText = mContext.getString(mItem.getAlertText()); String alertText = mContext.getString(mItem.getAlertText());
String confirmationText = mContext.getString(mItem.getConfirmationText());
AlertDialog.Builder builder = new AlertDialog.Builder(mContext) AlertDialog.Builder builder = new AlertDialog.Builder(mContext)
.setTitle(alertTitle) .setTitle(alertTitle)
@ -70,10 +69,13 @@ public final class ConfirmRunnableViewHolder extends SettingViewHolder
if (mItem.getConfirmationText() > 0) if (mItem.getConfirmationText() > 0)
{ {
String confirmationText = mContext.getString(mItem.getConfirmationText());
Toast.makeText(mContext, confirmationText, Toast.LENGTH_SHORT).show(); Toast.makeText(mContext, confirmationText, Toast.LENGTH_SHORT).show();
} }
dialog.dismiss(); dialog.dismiss();
mView.reloadSubMenu();
// TODO: Remove finish and properly update dynamic settings descriptions.
mView.getActivity().finish();
}) })
.setNegativeButton("No", (dialog, whichButton) -> .setNegativeButton("No", (dialog, whichButton) ->
{ {

View File

@ -172,7 +172,6 @@
<string name="SD_card_path">SD Card 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">Reset Paths to Default Settings</string>
<string name="reset_paths_confirmation">Are you sure you want to reset Paths to default settings?</string> <string name="reset_paths_confirmation">Are you sure you want to reset Paths to default settings?</string>
<string name="reset_paths_complete">Paths reset</string>
<!-- Graphics Settings --> <!-- Graphics Settings -->
<string name="graphics_general">General</string> <string name="graphics_general">General</string>