Skip to content

Commit

Permalink
Android: Specify ini file for every setting
Browse files Browse the repository at this point in the history
Load all the inis at once, choose which one to write to, and save them all
at the same time. This allows us to modify settings from different files
on the same settings page.
  • Loading branch information
Hydr8gon committed Nov 14, 2016
1 parent 017ab71 commit 128c1f0
Show file tree
Hide file tree
Showing 20 changed files with 291 additions and 321 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ public final class BooleanSetting extends Setting
{
private boolean mValue;

public BooleanSetting(String key, String section, boolean value)
public BooleanSetting(String key, String section, int file, boolean value)
{
super(key, section);
super(key, section, file);
mValue = value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ public final class FloatSetting extends Setting
{
private float mValue;

public FloatSetting(String key, String section, float value)
public FloatSetting(String key, String section, int file, float value)
{
super(key, section);
super(key, section, file);
mValue = value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ public final class IntSetting extends Setting
{
private int mValue;

public IntSetting(String key, String section, int value)
public IntSetting(String key, String section, int file, int value)
{
super(key, section);
super(key, section, file);
mValue = value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@ public abstract class Setting
{
private String mKey;
private String mSection;
private int mFile;

/**
* Base constructor.
*
* @param key Everything to the left of the = in a line from the ini file.
* @param section The corresponding recent section header; e.g. [Core] or [Enhancements] without the brackets.
* @param file The ini file the Setting is stored in.
*/
public Setting(String key, String section)
public Setting(String key, String section, int file)
{
mKey = key;
mSection = section;
mFile = file;
}

/**
Expand All @@ -41,6 +44,15 @@ public String getSection()
return mSection;
}

/**
*
* @return The ini file the Setting is stored in.
*/
public int getFile()
{
return mFile;
}

/**
* @return A representation of this Setting's backing value converted to a String (e.g. for serialization).
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* A semantically-related group of Settings objects. These Settings are
* internally stored as a Hashmap.
* internally stored as a HashMap.
*/
public final class SettingSection
{
Expand All @@ -28,18 +28,17 @@ public String getName()
}

/**
* Convenience method; inserts a value directly into the backing Hashmap.
* Convenience method; inserts a value directly into the backing HashMap.
*
* @param key The key where the Setting will be inserted.
* @param setting The Setting to be inserted.
*/
public void putSetting(String key, Setting setting)
public void putSetting(Setting setting)
{
mSettings.put(key, setting);
mSettings.put(setting.getKey(), setting);
}

/**
* Convenience method; gets a value directly from the backing Hashmap.
* Convenience method; gets a value directly from the backing HashMap.
*
* @param key Used to retrieve the Setting.
* @return A Setting object (you should probably cast this before using)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ public final class StringSetting extends Setting
{
private String mValue;

public StringSetting(String key, String section, String value)
public StringSetting(String key, String section, int file, String value)
{
super(key, section);
super(key, section, file);
mValue = value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ public final class CheckBoxSetting extends SettingsItem
{
private boolean mDefaultValue;

public CheckBoxSetting(String key, String section, int titleId, int descriptionId, boolean defaultValue, Setting setting)
public CheckBoxSetting(String key, String section, int file, int titleId, int descriptionId, boolean defaultValue, Setting setting)
{
super(key, section, setting, titleId, descriptionId);
super(key, section, file, setting, titleId, descriptionId);
mDefaultValue = defaultValue;
}

Expand All @@ -35,7 +35,7 @@ public BooleanSetting setChecked(boolean checked)
{
if (getSetting() == null)
{
BooleanSetting setting = new BooleanSetting(getKey(), getSection(), checked);
BooleanSetting setting = new BooleanSetting(getKey(), getSection(), getFile(), checked);
setSetting(setting);
return setting;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public final class HeaderSetting extends SettingsItem
{
public HeaderSetting(String key, Setting setting, int titleId, int descriptionId)
{
super(key, null, setting, titleId, descriptionId);
super(key, null, 0, setting, titleId, descriptionId);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public abstract class SettingsItem

private String mKey;
private String mSection;
private int mFile;

private Setting mSetting;

Expand All @@ -35,10 +36,11 @@ public abstract class SettingsItem
* @param nameId Resource ID for a text string to be displayed as this setting's name.
* @param descriptionId Resource ID for a text string to be displayed as this setting's description.
*/
public SettingsItem(String key, String section, Setting setting, int nameId, int descriptionId)
public SettingsItem(String key, String section, int file, Setting setting, int nameId, int descriptionId)
{
mKey = key;
mSection = section;
mFile = file;
mSetting = setting;
mNameId = nameId;
mDescriptionId = descriptionId;
Expand All @@ -62,6 +64,15 @@ public String getSection()
return mSection;
}

/**
*
* @return The file the backing Setting is saved to.
*/
public int getFile()
{
return mFile;
}

/**
*
* @return The backing Setting, possibly null.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ public final class SingleChoiceSetting extends SettingsItem
private int mChoicesId;
private int mValuesId;

public SingleChoiceSetting(String key, String section, int titleId, int descriptionId, int choicesId, int valuesId, int defaultValue, Setting setting)
public SingleChoiceSetting(String key, String section, int file, int titleId, int descriptionId, int choicesId, int valuesId, int defaultValue, Setting setting)
{
super(key, section, setting, titleId, descriptionId);
super(key, section, file, setting, titleId, descriptionId);
mValuesId = valuesId;
mChoicesId = choicesId;
mDefaultValue = defaultValue;
Expand Down Expand Up @@ -52,7 +52,7 @@ public IntSetting setSelectedValue(int selection)
{
if (getSetting() == null)
{
IntSetting setting = new IntSetting(getKey(), getSection(), selection);
IntSetting setting = new IntSetting(getKey(), getSection(), getFile(), selection);
setSetting(setting);
return setting;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public final class SliderSetting extends SettingsItem

private String mUnits;

public SliderSetting(String key, String section, int titleId, int descriptionId, int max, String units, int defaultValue, Setting setting)
public SliderSetting(String key, String section, int file, int titleId, int descriptionId, int max, String units, int defaultValue, Setting setting)
{
super(key, section, setting, titleId, descriptionId);
super(key, section, file, setting, titleId, descriptionId);
mMax = max;
mUnits = units;
mDefaultValue = defaultValue;
Expand Down Expand Up @@ -70,7 +70,7 @@ public IntSetting setSelectedValue(int selection)
{
if (getSetting() == null)
{
IntSetting setting = new IntSetting(getKey(), getSection(), selection);
IntSetting setting = new IntSetting(getKey(), getSection(), getFile(), selection);
setSetting(setting);
return setting;
}
Expand All @@ -93,7 +93,7 @@ public FloatSetting setSelectedValue(float selection)
{
if (getSetting() == null)
{
FloatSetting setting = new FloatSetting(getKey(), getSection(), selection);
FloatSetting setting = new FloatSetting(getKey(), getSection(), getFile(), selection);
setSetting(setting);
return setting;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public final class SubmenuSetting extends SettingsItem

public SubmenuSetting(String key, Setting setting, int titleId, int descriptionId, String menuKey)
{
super(key, null, setting, titleId, descriptionId);
super(key, null, 0, setting, titleId, descriptionId);
mMenuKey = menuKey;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.model.settings.SettingSection;

import java.util.ArrayList;
import java.util.HashMap;

public final class SettingsActivity extends AppCompatActivity implements SettingsActivityView
Expand Down Expand Up @@ -98,19 +99,19 @@ public void showSettingsFragment(String menuTag, boolean addToStack)
}

@Override
public HashMap<String, SettingSection> getSettings()
public HashMap<String, SettingSection> getSettings(int file)
{
return mPresenter.getSettings();
return mPresenter.getSettings(file);
}

@Override
public void setSettings(HashMap<String, SettingSection> settings)
public void setSettings(ArrayList<HashMap<String, SettingSection>> settings)
{
mPresenter.setSettings(settings);
}

@Override
public void onSettingsFileLoaded(HashMap<String, SettingSection> settings)
public void onSettingsFileLoaded(ArrayList<HashMap<String, SettingSection>> settings)
{
SettingsFragmentView fragment = getFragment();

Expand Down
Loading

0 comments on commit 128c1f0

Please sign in to comment.