Android: Conditionally respond to modified settings
This commit is contained in:
parent
77f539355d
commit
9ea8f29765
|
@ -1,15 +1,18 @@
|
|||
package org.dolphinemu.dolphinemu.features.settings.model;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import org.dolphinemu.dolphinemu.NativeLibrary;
|
||||
import org.dolphinemu.dolphinemu.features.settings.ui.SettingsActivityView;
|
||||
import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile;
|
||||
import org.dolphinemu.dolphinemu.services.GameFileCacheService;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Settings
|
||||
|
@ -164,7 +167,7 @@ public class Settings
|
|||
loadSettings(view);
|
||||
}
|
||||
|
||||
public void saveSettings(SettingsActivityView view)
|
||||
public void saveSettings(SettingsActivityView view, Context context, Set<String> modifiedSettings)
|
||||
{
|
||||
if (TextUtils.isEmpty(gameId))
|
||||
{
|
||||
|
@ -183,6 +186,8 @@ public class Settings
|
|||
SettingsFile.saveFile(fileName, iniSections, view);
|
||||
}
|
||||
|
||||
if (modifiedSettings.contains(SettingsFile.KEY_DSP_ENGINE))
|
||||
{
|
||||
switch (NativeLibrary
|
||||
.GetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_DSP,
|
||||
SettingsFile.KEY_DSP_ENGINE, DSP_HLE))
|
||||
|
@ -191,7 +196,8 @@ public class Settings
|
|||
NativeLibrary
|
||||
.SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_CORE,
|
||||
SettingsFile.KEY_DSP_HLE, "True");
|
||||
NativeLibrary.SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_DSP,
|
||||
NativeLibrary
|
||||
.SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_DSP,
|
||||
SettingsFile.KEY_DSP_ENABLE_JIT, "True");
|
||||
break;
|
||||
|
||||
|
@ -199,7 +205,8 @@ public class Settings
|
|||
NativeLibrary
|
||||
.SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_CORE,
|
||||
SettingsFile.KEY_DSP_HLE, "False");
|
||||
NativeLibrary.SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_DSP,
|
||||
NativeLibrary
|
||||
.SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_DSP,
|
||||
SettingsFile.KEY_DSP_ENABLE_JIT, "True");
|
||||
break;
|
||||
|
||||
|
@ -207,14 +214,24 @@ public class Settings
|
|||
NativeLibrary
|
||||
.SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_CORE,
|
||||
SettingsFile.KEY_DSP_HLE, "False");
|
||||
NativeLibrary.SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_DSP,
|
||||
NativeLibrary
|
||||
.SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_DSP,
|
||||
SettingsFile.KEY_DSP_ENABLE_JIT, "False");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Notify the native code of the changes
|
||||
NativeLibrary.ReloadConfig();
|
||||
NativeLibrary.ReloadWiimoteConfig();
|
||||
|
||||
if (modifiedSettings.contains(SettingsFile.KEY_RECURSIVE_ISO_PATHS))
|
||||
{
|
||||
// Refresh game library
|
||||
GameFileCacheService.startRescan(context);
|
||||
}
|
||||
|
||||
modifiedSettings.clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -51,7 +51,7 @@ public final class SettingsActivity extends AppCompatActivity implements Setting
|
|||
Intent launcher = getIntent();
|
||||
String gameID = launcher.getStringExtra(ARG_GAME_ID);
|
||||
MenuTag menuTag = (MenuTag) launcher.getSerializableExtra(ARG_MENU_TAG);
|
||||
mPresenter.onCreate(savedInstanceState, menuTag, gameID);
|
||||
mPresenter.onCreate(savedInstanceState, menuTag, gameID, getApplicationContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -275,9 +275,9 @@ public final class SettingsActivity extends AppCompatActivity implements Setting
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onSettingChanged()
|
||||
public void onSettingChanged(String key)
|
||||
{
|
||||
mPresenter.onSettingChanged();
|
||||
mPresenter.onSettingChanged(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.dolphinemu.dolphinemu.features.settings.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
|
@ -11,6 +12,9 @@ import org.dolphinemu.dolphinemu.utils.DirectoryInitialization.DirectoryInitiali
|
|||
import org.dolphinemu.dolphinemu.utils.DirectoryStateReceiver;
|
||||
import org.dolphinemu.dolphinemu.utils.Log;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public final class SettingsActivityPresenter
|
||||
{
|
||||
private static final String KEY_SHOULD_SAVE = "should_save";
|
||||
|
@ -27,18 +31,22 @@ public final class SettingsActivityPresenter
|
|||
|
||||
private MenuTag menuTag;
|
||||
private String gameId;
|
||||
private Context context;
|
||||
|
||||
private final Set<String> modifiedSettings = new HashSet<>();
|
||||
|
||||
SettingsActivityPresenter(SettingsActivityView view)
|
||||
{
|
||||
mView = view;
|
||||
}
|
||||
|
||||
public void onCreate(Bundle savedInstanceState, MenuTag menuTag, String gameId)
|
||||
public void onCreate(Bundle savedInstanceState, MenuTag menuTag, String gameId, Context context)
|
||||
{
|
||||
if (savedInstanceState == null)
|
||||
{
|
||||
this.menuTag = menuTag;
|
||||
this.gameId = gameId;
|
||||
this.context = context;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -126,7 +134,7 @@ public final class SettingsActivityPresenter
|
|||
public void clearSettings()
|
||||
{
|
||||
mSettings.clearSettings();
|
||||
onSettingChanged();
|
||||
onSettingChanged(null);
|
||||
}
|
||||
|
||||
public void onStop(boolean finishing)
|
||||
|
@ -140,7 +148,7 @@ public final class SettingsActivityPresenter
|
|||
if (mSettings != null && finishing && mShouldSave)
|
||||
{
|
||||
Log.debug("[SettingsActivity] Settings activity stopping. Saving settings to INI...");
|
||||
mSettings.saveSettings(mView);
|
||||
mSettings.saveSettings(mView, context, modifiedSettings);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -174,8 +182,13 @@ public final class SettingsActivityPresenter
|
|||
return false;
|
||||
}
|
||||
|
||||
public void onSettingChanged()
|
||||
public void onSettingChanged(String key)
|
||||
{
|
||||
if (key != null)
|
||||
{
|
||||
modifiedSettings.add(key);
|
||||
}
|
||||
|
||||
mShouldSave = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -69,8 +69,10 @@ public interface SettingsActivityView
|
|||
/**
|
||||
* Called by a containing Fragment to tell the Activity that a setting was changed;
|
||||
* unless this has been called, the Activity will not save to disk.
|
||||
*
|
||||
* @param key Key of the modified setting.
|
||||
*/
|
||||
void onSettingChanged();
|
||||
void onSettingChanged(String key);
|
||||
|
||||
/**
|
||||
* Called by a containing Fragment to tell the containing Activity that a GCPad's setting
|
||||
|
|
|
@ -182,7 +182,7 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
|
|||
mView.putSetting(new BooleanSetting(item.getKey(), item.getSection(), !checked));
|
||||
}
|
||||
|
||||
mView.onSettingChanged();
|
||||
mView.onSettingChanged(item.getKey());
|
||||
}
|
||||
|
||||
public void onSingleChoiceClick(SingleChoiceSetting item, int position)
|
||||
|
@ -294,7 +294,7 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
|
|||
mView.putSetting(setting);
|
||||
}
|
||||
|
||||
mView.onSettingChanged();
|
||||
mView.onSettingChanged(item.getKey());
|
||||
});
|
||||
dialog.setCanceledOnTouchOutside(false);
|
||||
dialog.show();
|
||||
|
@ -366,7 +366,7 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
|
|||
sView.putSetting(resourcePackPath);
|
||||
sView.putSetting(sdPath);
|
||||
|
||||
sView.onSettingChanged();
|
||||
sView.onSettingChanged(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -378,7 +378,7 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
|
|||
|
||||
int value = getValueForSingleChoiceSelection(scSetting, which);
|
||||
if (scSetting.getSelectedValue() != value)
|
||||
mView.onSettingChanged();
|
||||
mView.onSettingChanged(mClickedItem.getKey());
|
||||
|
||||
MenuTag menuTag = scSetting.getMenuTag();
|
||||
if (menuTag != null)
|
||||
|
@ -434,7 +434,7 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
|
|||
|
||||
int value = getValueForSingleChoiceDynamicDescriptionsSelection(scSetting, which);
|
||||
if (scSetting.getSelectedValue() != value)
|
||||
mView.onSettingChanged();
|
||||
mView.onSettingChanged(mClickedItem.getKey());
|
||||
|
||||
// Get the backing Setting, which may be null (if for example it was missing from the file)
|
||||
IntSetting setting = scSetting.setSelectedValue(value);
|
||||
|
@ -450,7 +450,7 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
|
|||
StringSingleChoiceSetting scSetting = (StringSingleChoiceSetting) mClickedItem;
|
||||
String value = scSetting.getValueAt(which);
|
||||
if (!scSetting.getSelectedValue().equals(value))
|
||||
mView.onSettingChanged();
|
||||
mView.onSettingChanged(mClickedItem.getKey());
|
||||
|
||||
StringSetting setting = scSetting.setSelectedValue(value);
|
||||
if (setting != null)
|
||||
|
@ -464,7 +464,7 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
|
|||
{
|
||||
SliderSetting sliderSetting = (SliderSetting) mClickedItem;
|
||||
if (sliderSetting.getSelectedValue() != mSeekbarProgress)
|
||||
mView.onSettingChanged();
|
||||
mView.onSettingChanged(mClickedItem.getKey());
|
||||
|
||||
if (sliderSetting.isPercentSetting() || sliderSetting.getSetting() instanceof FloatSetting)
|
||||
{
|
||||
|
|
|
@ -197,9 +197,9 @@ public final class SettingsFragment extends Fragment implements SettingsFragment
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onSettingChanged()
|
||||
public void onSettingChanged(String key)
|
||||
{
|
||||
mActivity.onSettingChanged();
|
||||
mActivity.onSettingChanged(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -336,8 +336,7 @@ public final class SettingsFragmentPresenter
|
|||
wiiSDCardPath = generalSection.getSetting(SettingsFile.KEY_WII_SD_CARD_PATH);
|
||||
|
||||
sl.add(new CheckBoxSetting(SettingsFile.KEY_RECURSIVE_ISO_PATHS, Settings.SECTION_INI_GENERAL,
|
||||
R.string.search_subfolders, R.string.search_subfolders_description, false,
|
||||
recursiveISOPaths));
|
||||
R.string.search_subfolders, 0, false, recursiveISOPaths));
|
||||
sl.add(new FilePicker(SettingsFile.FILE_NAME_DOLPHIN, SettingsFile.KEY_DEFAULT_ISO,
|
||||
Settings.SECTION_INI_CORE, R.string.default_ISO, 0, "",
|
||||
MainPresenter.REQUEST_GAME_FILE, defaultISO));
|
||||
|
|
|
@ -73,8 +73,10 @@ public interface SettingsFragmentView
|
|||
|
||||
/**
|
||||
* Have the fragment tell the containing Activity that a setting was modified.
|
||||
*
|
||||
* @param key Key of the modified setting, potentially null for multiple settings.
|
||||
*/
|
||||
void onSettingChanged();
|
||||
void onSettingChanged(String key);
|
||||
|
||||
/**
|
||||
* Have the fragment tell the containing Activity that a GCPad's setting was modified.
|
||||
|
|
|
@ -165,7 +165,6 @@
|
|||
<!-- Path Settings -->
|
||||
<string name="paths_submenu">Paths</string>
|
||||
<string name="search_subfolders">Search Subfolders for Game Files</string>
|
||||
<string name="search_subfolders_description">Refresh library after changing this setting.</string>
|
||||
<string name="default_ISO">Default ISO</string>
|
||||
<string name="wii_NAND_root">Wii NAND Root</string>
|
||||
<string name="dump_path">Dump Path</string>
|
||||
|
|
Loading…
Reference in New Issue