mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-21 05:09:34 -06:00
Android: Hook up global settings to the new config system
This commit is contained in:
@ -0,0 +1,57 @@
|
||||
package org.dolphinemu.dolphinemu.features.settings.model;
|
||||
|
||||
public class AdHocBooleanSetting extends AbstractLegacySetting implements AbstractBooleanSetting
|
||||
{
|
||||
private final boolean mDefaultValue;
|
||||
|
||||
public AdHocBooleanSetting(String file, String section, String key, boolean defaultValue)
|
||||
{
|
||||
super(file, section, key);
|
||||
mDefaultValue = defaultValue;
|
||||
|
||||
if (!NativeConfig.isSettingSaveable(file, section, key))
|
||||
{
|
||||
throw new IllegalArgumentException("File/section/key is unknown or legacy");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(Settings settings)
|
||||
{
|
||||
if (!settings.isGameSpecific())
|
||||
{
|
||||
return NativeConfig.deleteKey(NativeConfig.LAYER_BASE_OR_CURRENT, mFile, mSection, mKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
return settings.getSection(mFile, mSection).delete(mKey);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getBoolean(Settings settings)
|
||||
{
|
||||
if (!settings.isGameSpecific())
|
||||
{
|
||||
return NativeConfig.getBoolean(NativeConfig.LAYER_BASE_OR_CURRENT, mFile, mSection, mKey,
|
||||
mDefaultValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
return settings.getSection(mFile, mSection).getBoolean(mKey, mDefaultValue);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBoolean(Settings settings, boolean newValue)
|
||||
{
|
||||
if (!settings.isGameSpecific())
|
||||
{
|
||||
NativeConfig.setBoolean(NativeConfig.LAYER_BASE_OR_CURRENT, mFile, mSection, mKey, newValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
settings.getSection(mFile, mSection).setBoolean(mKey, newValue);
|
||||
}
|
||||
}
|
||||
}
|
@ -110,18 +110,40 @@ public enum BooleanSetting implements AbstractBooleanSetting
|
||||
@Override
|
||||
public boolean delete(Settings settings)
|
||||
{
|
||||
return settings.getSection(mFile, mSection).delete(mKey);
|
||||
if (NativeConfig.isSettingSaveable(mFile, mSection, mKey) && !settings.isGameSpecific())
|
||||
{
|
||||
return NativeConfig.deleteKey(NativeConfig.LAYER_BASE_OR_CURRENT, mFile, mSection, mKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
return settings.getSection(mFile, mSection).delete(mKey);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getBoolean(Settings settings)
|
||||
{
|
||||
return settings.getSection(mFile, mSection).getBoolean(mKey, mDefaultValue);
|
||||
if (NativeConfig.isSettingSaveable(mFile, mSection, mKey) && !settings.isGameSpecific())
|
||||
{
|
||||
return NativeConfig.getBoolean(NativeConfig.LAYER_BASE_OR_CURRENT, mFile, mSection, mKey,
|
||||
mDefaultValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
return settings.getSection(mFile, mSection).getBoolean(mKey, mDefaultValue);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBoolean(Settings settings, boolean newValue)
|
||||
{
|
||||
settings.getSection(mFile, mSection).setBoolean(mKey, newValue);
|
||||
if (NativeConfig.isSettingSaveable(mFile, mSection, mKey) && !settings.isGameSpecific())
|
||||
{
|
||||
NativeConfig.setBoolean(NativeConfig.LAYER_BASE_OR_CURRENT, mFile, mSection, mKey, newValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
settings.getSection(mFile, mSection).setBoolean(mKey, newValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,18 +23,40 @@ public enum FloatSetting implements AbstractFloatSetting
|
||||
@Override
|
||||
public boolean delete(Settings settings)
|
||||
{
|
||||
return settings.getSection(mFile, mSection).delete(mKey);
|
||||
if (NativeConfig.isSettingSaveable(mFile, mSection, mKey) && !settings.isGameSpecific())
|
||||
{
|
||||
return NativeConfig.deleteKey(NativeConfig.LAYER_BASE_OR_CURRENT, mFile, mSection, mKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
return settings.getSection(mFile, mSection).delete(mKey);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getFloat(Settings settings)
|
||||
{
|
||||
return settings.getSection(mFile, mSection).getFloat(mKey, mDefaultValue);
|
||||
if (NativeConfig.isSettingSaveable(mFile, mSection, mKey) && !settings.isGameSpecific())
|
||||
{
|
||||
return NativeConfig.getFloat(NativeConfig.LAYER_BASE_OR_CURRENT, mFile, mSection, mKey,
|
||||
mDefaultValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
return settings.getSection(mFile, mSection).getFloat(mKey, mDefaultValue);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFloat(Settings settings, float newValue)
|
||||
{
|
||||
settings.getSection(mFile, mSection).setFloat(mKey, newValue);
|
||||
if (NativeConfig.isSettingSaveable(mFile, mSection, mKey) && !settings.isGameSpecific())
|
||||
{
|
||||
NativeConfig.setFloat(NativeConfig.LAYER_BASE_OR_CURRENT, mFile, mSection, mKey, newValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
settings.getSection(mFile, mSection).setFloat(mKey, newValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -50,18 +50,40 @@ public enum IntSetting implements AbstractIntSetting
|
||||
@Override
|
||||
public boolean delete(Settings settings)
|
||||
{
|
||||
return settings.getSection(mFile, mSection).delete(mKey);
|
||||
if (NativeConfig.isSettingSaveable(mFile, mSection, mKey) && !settings.isGameSpecific())
|
||||
{
|
||||
return NativeConfig.deleteKey(NativeConfig.LAYER_BASE_OR_CURRENT, mFile, mSection, mKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
return settings.getSection(mFile, mSection).delete(mKey);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInt(Settings settings)
|
||||
{
|
||||
return settings.getSection(mFile, mSection).getInt(mKey, mDefaultValue);
|
||||
if (NativeConfig.isSettingSaveable(mFile, mSection, mKey) && !settings.isGameSpecific())
|
||||
{
|
||||
return NativeConfig.getInt(NativeConfig.LAYER_BASE_OR_CURRENT, mFile, mSection, mKey,
|
||||
mDefaultValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
return settings.getSection(mFile, mSection).getInt(mKey, mDefaultValue);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInt(Settings settings, int newValue)
|
||||
{
|
||||
settings.getSection(mFile, mSection).setInt(mKey, newValue);
|
||||
if (NativeConfig.isSettingSaveable(mFile, mSection, mKey) && !settings.isGameSpecific())
|
||||
{
|
||||
NativeConfig.setInt(NativeConfig.LAYER_BASE_OR_CURRENT, mFile, mSection, mKey, newValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
settings.getSection(mFile, mSection).setInt(mKey, newValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,36 @@
|
||||
package org.dolphinemu.dolphinemu.features.settings.model;
|
||||
|
||||
public class NativeConfig
|
||||
{
|
||||
public static final int LAYER_BASE_OR_CURRENT = 0;
|
||||
public static final int LAYER_LOCAL_GAME = 1;
|
||||
|
||||
public static native boolean isSettingSaveable(String file, String section, String key);
|
||||
|
||||
public static native void save(int layer);
|
||||
|
||||
public static native boolean deleteKey(int layer, String file, String section, String key);
|
||||
|
||||
public static native String getString(int layer, String file, String section, String key,
|
||||
String defaultValue);
|
||||
|
||||
public static native boolean getBoolean(int layer, String file, String section, String key,
|
||||
boolean defaultValue);
|
||||
|
||||
public static native int getInt(int layer, String file, String section, String key,
|
||||
int defaultValue);
|
||||
|
||||
public static native float getFloat(int layer, String file, String section, String key,
|
||||
float defaultValue);
|
||||
|
||||
public static native void setString(int layer, String file, String section, String key,
|
||||
String value);
|
||||
|
||||
public static native void setBoolean(int layer, String file, String section, String key,
|
||||
boolean value);
|
||||
|
||||
public static native void setInt(int layer, String file, String section, String key, int value);
|
||||
|
||||
public static native void setFloat(int layer, String file, String section, String key,
|
||||
float value);
|
||||
}
|
@ -59,7 +59,7 @@ public class Settings
|
||||
|
||||
private IniFile getGameSpecificFile()
|
||||
{
|
||||
if (TextUtils.isEmpty(gameId) || mIniFiles.size() != 1)
|
||||
if (!isGameSpecific() || mIniFiles.size() != 1)
|
||||
throw new IllegalStateException();
|
||||
|
||||
return mIniFiles.get(GAME_SETTINGS_PLACEHOLDER_FILE_NAME);
|
||||
@ -67,7 +67,7 @@ public class Settings
|
||||
|
||||
public IniFile.Section getSection(String fileName, String sectionName)
|
||||
{
|
||||
if (TextUtils.isEmpty(gameId))
|
||||
if (!isGameSpecific())
|
||||
{
|
||||
return mIniFiles.get(fileName).getOrCreateSection(sectionName);
|
||||
}
|
||||
@ -78,6 +78,11 @@ public class Settings
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isGameSpecific()
|
||||
{
|
||||
return !TextUtils.isEmpty(gameId);
|
||||
}
|
||||
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return mIniFiles.isEmpty();
|
||||
@ -87,7 +92,7 @@ public class Settings
|
||||
{
|
||||
mIniFiles = new HashMap<>();
|
||||
|
||||
if (TextUtils.isEmpty(gameId))
|
||||
if (!isGameSpecific())
|
||||
{
|
||||
loadDolphinSettings(view);
|
||||
}
|
||||
@ -129,7 +134,7 @@ public class Settings
|
||||
|
||||
public void saveSettings(SettingsActivityView view, Context context)
|
||||
{
|
||||
if (TextUtils.isEmpty(gameId))
|
||||
if (!isGameSpecific())
|
||||
{
|
||||
if (context != null)
|
||||
Toast.makeText(context, "Saved settings to INI files", Toast.LENGTH_SHORT).show();
|
||||
@ -139,6 +144,8 @@ public class Settings
|
||||
SettingsFile.saveFile(entry.getKey(), entry.getValue(), view);
|
||||
}
|
||||
|
||||
NativeConfig.save(NativeConfig.LAYER_BASE_OR_CURRENT);
|
||||
|
||||
// Notify the native code of the changes
|
||||
NativeLibrary.ReloadConfig();
|
||||
NativeLibrary.ReloadWiimoteConfig();
|
||||
@ -190,7 +197,7 @@ public class Settings
|
||||
// possible to know which lines were added intentionally by the user and which lines were added
|
||||
// unintentionally, which is why we have to delete the whole file in order to fix everything.
|
||||
|
||||
if (TextUtils.isEmpty(gameId))
|
||||
if (!isGameSpecific())
|
||||
return false;
|
||||
|
||||
return getSection(Settings.FILE_DOLPHIN, SECTION_INI_INTERFACE).exists("ThemeName");
|
||||
|
@ -36,18 +36,40 @@ public enum StringSetting implements AbstractStringSetting
|
||||
@Override
|
||||
public boolean delete(Settings settings)
|
||||
{
|
||||
return settings.getSection(mFile, mSection).delete(mKey);
|
||||
if (NativeConfig.isSettingSaveable(mFile, mSection, mKey) && !settings.isGameSpecific())
|
||||
{
|
||||
return NativeConfig.deleteKey(NativeConfig.LAYER_BASE_OR_CURRENT, mFile, mSection, mKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
return settings.getSection(mFile, mSection).delete(mKey);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString(Settings settings)
|
||||
{
|
||||
return settings.getSection(mFile, mSection).getString(mKey, mDefaultValue);
|
||||
if (NativeConfig.isSettingSaveable(mFile, mSection, mKey) && !settings.isGameSpecific())
|
||||
{
|
||||
return NativeConfig.getString(NativeConfig.LAYER_BASE_OR_CURRENT, mFile, mSection, mKey,
|
||||
mDefaultValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
return settings.getSection(mFile, mSection).getString(mKey, mDefaultValue);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setString(Settings settings, String newValue)
|
||||
{
|
||||
settings.getSection(mFile, mSection).setString(mKey, newValue);
|
||||
if (NativeConfig.isSettingSaveable(mFile, mSection, mKey) && !settings.isGameSpecific())
|
||||
{
|
||||
NativeConfig.setString(NativeConfig.LAYER_BASE_OR_CURRENT, mFile, mSection, mKey, newValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
settings.getSection(mFile, mSection).setString(mKey, newValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package org.dolphinemu.dolphinemu.features.settings.model.view;
|
||||
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.LegacyBooleanSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.AdHocBooleanSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
|
||||
|
||||
public class LogCheckBoxSetting extends CheckBoxSetting
|
||||
@ -9,7 +9,7 @@ public class LogCheckBoxSetting extends CheckBoxSetting
|
||||
|
||||
public LogCheckBoxSetting(String key, int titleId, int descriptionId)
|
||||
{
|
||||
super(new LegacyBooleanSetting(Settings.FILE_LOGGER, Settings.SECTION_LOGGER_LOGS, key, false),
|
||||
super(new AdHocBooleanSetting(Settings.FILE_LOGGER, Settings.SECTION_LOGGER_LOGS, key, false),
|
||||
titleId, descriptionId);
|
||||
mKey = key;
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import org.dolphinemu.dolphinemu.R;
|
||||
import org.dolphinemu.dolphinemu.dialogs.MotionAlertDialog;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.LegacyBooleanSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.AdHocBooleanSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.StringSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.view.CheckBoxSetting;
|
||||
@ -335,7 +335,7 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
|
||||
|
||||
for (Map.Entry<String, String> entry : SettingsFragmentPresenter.LOG_TYPE_NAMES.entrySet())
|
||||
{
|
||||
new LegacyBooleanSetting(Settings.FILE_LOGGER, Settings.SECTION_LOGGER_LOGS, entry.getKey(),
|
||||
new AdHocBooleanSetting(Settings.FILE_LOGGER, Settings.SECTION_LOGGER_LOGS, entry.getKey(),
|
||||
false).setBoolean(settings, value);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user