Permalink
Browse files

Merge pull request #7292 from mahdihijazi/settings_refactor

Android: Settings refactor & Fix custom game settings
  • Loading branch information...
degasus committed Aug 9, 2018
2 parents 7be818a + f41785e commit bfbf9ed2ee969a29703eb7d302306f477a12d122
Showing with 1,711 additions and 1,536 deletions.
  1. +1 −1 Source/Android/app/src/main/AndroidManifest.xml
  2. +2 −2 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameAdapter.java
  3. +2 −2 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameRowPresenter.java
  4. +1 −1 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/MotionAlertDialog.java
  5. +3 −3 ...ain/java/org/dolphinemu/dolphinemu/{model/settings → features/settings/model}/BooleanSetting.java
  6. +3 −3 .../main/java/org/dolphinemu/dolphinemu/{model/settings → features/settings/model}/FloatSetting.java
  7. +6 −6 ...rc/main/java/org/dolphinemu/dolphinemu/{model/settings → features/settings/model}/IntSetting.java
  8. +2 −13 ...p/src/main/java/org/dolphinemu/dolphinemu/{model/settings → features/settings/model}/Setting.java
  9. +9 −1 ...ain/java/org/dolphinemu/dolphinemu/{model/settings → features/settings/model}/SettingSection.java
  10. +179 −0 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/Settings.java
  11. +3 −3 ...main/java/org/dolphinemu/dolphinemu/{model/settings → features/settings/model}/StringSetting.java
  12. +6 −6 ...va/org/dolphinemu/dolphinemu/{model/settings → features/settings/model}/view/CheckBoxSetting.java
  13. +3 −3 ...java/org/dolphinemu/dolphinemu/{model/settings → features/settings/model}/view/HeaderSetting.java
  14. +6 −7 ...rg/dolphinemu/dolphinemu/{model/settings → features/settings/model}/view/InputBindingSetting.java
  15. +5 −14 .../java/org/dolphinemu/dolphinemu/{model/settings → features/settings/model}/view/SettingsItem.java
  16. +9 −9 ...rg/dolphinemu/dolphinemu/{model/settings → features/settings/model}/view/SingleChoiceSetting.java
  17. +9 −9 ...java/org/dolphinemu/dolphinemu/{model/settings → features/settings/model}/view/SliderSetting.java
  18. +6 −6 ...phinemu/dolphinemu/{model/settings → features/settings/model}/view/StringSingleChoiceSetting.java
  19. +4 −4 ...ava/org/dolphinemu/dolphinemu/{model/settings → features/settings/model}/view/SubmenuSetting.java
  20. +1 −1 ...oid/app/src/main/java/org/dolphinemu/dolphinemu/{ui/settings → features/settings/ui}/MenuTag.java
  21. +6 −8 ...rc/main/java/org/dolphinemu/dolphinemu/{ui/settings → features/settings/ui}/SettingsActivity.java
  22. +206 −0 ...d/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivityPresenter.java
  23. +5 −9 ...ain/java/org/dolphinemu/dolphinemu/{ui/settings → features/settings/ui}/SettingsActivityView.java
  24. +45 −45 ...src/main/java/org/dolphinemu/dolphinemu/{ui/settings → features/settings/ui}/SettingsAdapter.java
  25. +6 −15 ...rc/main/java/org/dolphinemu/dolphinemu/{ui/settings → features/settings/ui}/SettingsFragment.java
  26. +974 −0 ...d/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.java
  27. +6 −7 ...ain/java/org/dolphinemu/dolphinemu/{ui/settings → features/settings/ui}/SettingsFragmentView.java
  28. +1 −1 ...main/java/org/dolphinemu/dolphinemu/{ui/settings → features/settings/ui}/SettingsFrameLayout.java
  29. +4 −4 ...phinemu/dolphinemu/{ui/settings → features/settings/ui}/viewholder/CheckBoxSettingViewHolder.java
  30. +3 −3 ...a/org/dolphinemu/dolphinemu/{ui/settings → features/settings/ui}/viewholder/HeaderViewHolder.java
  31. +4 −4 ...emu/dolphinemu/{ui/settings → features/settings/ui}/viewholder/InputBindingSettingViewHolder.java
  32. +3 −3 .../org/dolphinemu/dolphinemu/{ui/settings → features/settings/ui}/viewholder/SettingViewHolder.java
  33. +5 −5 ...dolphinemu/dolphinemu/{ui/settings → features/settings/ui}/viewholder/SingleChoiceViewHolder.java
  34. +4 −4 ...a/org/dolphinemu/dolphinemu/{ui/settings → features/settings/ui}/viewholder/SliderViewHolder.java
  35. +4 −4 .../org/dolphinemu/dolphinemu/{ui/settings → features/settings/ui}/viewholder/SubmenuViewHolder.java
  36. +138 −96 ...ndroid/app/src/main/java/org/dolphinemu/dolphinemu/{ → features/settings}/utils/SettingsFile.java
  37. +2 −2 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java
  38. +1 −1 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainPresenter.java
  39. +1 −1 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainView.java
  40. +2 −2 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/TvMainActivity.java
  41. +0 −230 ...ce/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsActivityPresenter.java
  42. +0 −994 ...ce/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsFragmentPresenter.java
  43. +27 −0 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/BiMap.java
  44. +4 −4 Source/Android/app/src/main/res/layout/fragment_settings.xml
@@ -54,7 +54,7 @@
</activity>
<activity
android:name=".ui.settings.SettingsActivity"
android:name=".features.settings.ui.SettingsActivity"
android:theme="@style/DolphinSettingsGamecube"
android:label="@string/preferences_settings"/>
@@ -14,8 +14,8 @@
import org.dolphinemu.dolphinemu.activities.EmulationActivity;
import org.dolphinemu.dolphinemu.model.GameFile;
import org.dolphinemu.dolphinemu.services.DirectoryInitializationService;
import org.dolphinemu.dolphinemu.ui.settings.MenuTag;
import org.dolphinemu.dolphinemu.ui.settings.SettingsActivity;
import org.dolphinemu.dolphinemu.features.settings.ui.MenuTag;
import org.dolphinemu.dolphinemu.features.settings.ui.SettingsActivity;
import org.dolphinemu.dolphinemu.utils.PicassoUtils;
import org.dolphinemu.dolphinemu.viewholders.GameViewHolder;
@@ -17,8 +17,8 @@
import org.dolphinemu.dolphinemu.model.GameFile;
import org.dolphinemu.dolphinemu.services.DirectoryInitializationService;
import org.dolphinemu.dolphinemu.ui.platform.Platform;
import org.dolphinemu.dolphinemu.ui.settings.MenuTag;
import org.dolphinemu.dolphinemu.ui.settings.SettingsActivity;
import org.dolphinemu.dolphinemu.features.settings.ui.MenuTag;
import org.dolphinemu.dolphinemu.features.settings.ui.SettingsActivity;
import org.dolphinemu.dolphinemu.utils.PicassoUtils;
import org.dolphinemu.dolphinemu.viewholders.TvGameViewHolder;
@@ -8,7 +8,7 @@
import android.view.KeyEvent;
import android.view.MotionEvent;
import org.dolphinemu.dolphinemu.model.settings.view.InputBindingSetting;
import org.dolphinemu.dolphinemu.features.settings.model.view.InputBindingSetting;
import org.dolphinemu.dolphinemu.utils.ControllerMappingHelper;
import org.dolphinemu.dolphinemu.utils.Log;
@@ -1,12 +1,12 @@
package org.dolphinemu.dolphinemu.model.settings;
package org.dolphinemu.dolphinemu.features.settings.model;
public final class BooleanSetting extends Setting
{
private boolean mValue;
public BooleanSetting(String key, String section, int file, boolean value)
public BooleanSetting(String key, String section, boolean value)
{
super(key, section, file);
super(key, section);
mValue = value;
}
@@ -1,12 +1,12 @@
package org.dolphinemu.dolphinemu.model.settings;
package org.dolphinemu.dolphinemu.features.settings.model;
public final class FloatSetting extends Setting
{
private float mValue;
public FloatSetting(String key, String section, int file, float value)
public FloatSetting(String key, String section, float value)
{
super(key, section, file);
super(key, section);
mValue = value;
}
@@ -1,21 +1,21 @@
package org.dolphinemu.dolphinemu.model.settings;
package org.dolphinemu.dolphinemu.features.settings.model;
import org.dolphinemu.dolphinemu.ui.settings.MenuTag;
import org.dolphinemu.dolphinemu.features.settings.ui.MenuTag;
public final class IntSetting extends Setting
{
private int mValue;
private MenuTag menuTag;
public IntSetting(String key, String section, int file, int value)
public IntSetting(String key, String section, int value)
{
super(key, section, file);
super(key, section);
mValue = value;
}
public IntSetting(String key, String section, int file, int value, MenuTag menuTag)
public IntSetting(String key, String section, int value, MenuTag menuTag)
{
super(key, section, file);
super(key, section);
mValue = value;
this.menuTag = menuTag;
}
@@ -1,4 +1,4 @@
package org.dolphinemu.dolphinemu.model.settings;
package org.dolphinemu.dolphinemu.features.settings.model;
/**
* Abstraction for a setting item as read from / written to Dolphin's configuration ini files.
@@ -10,20 +10,17 @@
{
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, int file)
public Setting(String key, String section)
{
mKey = key;
mSection = section;
mFile = file;
}
/**
@@ -44,14 +41,6 @@ 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).
@@ -1,4 +1,4 @@
package org.dolphinemu.dolphinemu.model.settings;
package org.dolphinemu.dolphinemu.features.settings.model;
import java.util.HashMap;
@@ -52,4 +52,12 @@ public Setting getSetting(String key)
{
return mSettings;
}
public void mergeSection(SettingSection settingSection)
{
for (Setting setting : settingSection.mSettings.values())
{
putSetting(setting);
}
}
}
@@ -0,0 +1,179 @@
package org.dolphinemu.dolphinemu.features.settings.model;
import android.text.TextUtils;
import org.dolphinemu.dolphinemu.features.settings.ui.SettingsActivityView;
import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
public class Settings
{
public static final String SECTION_INI_CORE = "Core";
public static final String SECTION_INI_INTERFACE = "Interface";
public static final String SECTION_GFX_SETTINGS = "Settings";
public static final String SECTION_GFX_ENHANCEMENTS = "Enhancements";
public static final String SECTION_GFX_HACKS = "Hacks";
public static final String SECTION_STEREOSCOPY = "Stereoscopy";
public static final String SECTION_WIIMOTE = "Wiimote";
public static final String SECTION_BINDINGS = "Android";
private String gameId;
private static final Map<String, List<String>> configFileSectionsMap = new HashMap<>();
static
{
configFileSectionsMap.put(SettingsFile.FILE_NAME_DOLPHIN, Arrays.asList(SECTION_INI_CORE, SECTION_INI_INTERFACE, SECTION_BINDINGS));
configFileSectionsMap.put(SettingsFile.FILE_NAME_GFX, Arrays.asList(SECTION_GFX_SETTINGS, SECTION_GFX_ENHANCEMENTS, SECTION_GFX_HACKS, SECTION_STEREOSCOPY));
configFileSectionsMap.put(SettingsFile.FILE_NAME_WIIMOTE, Arrays.asList(SECTION_WIIMOTE + 1, SECTION_WIIMOTE + 2, SECTION_WIIMOTE + 3, SECTION_WIIMOTE + 4));
}
/**
* A HashMap<String, SettingSection> that constructs a new SettingSection instead of returning null
* when getting a key not already in the map
*/
public static final class SettingsSectionMap extends HashMap<String, SettingSection>
{
@Override
public SettingSection get(Object key)
{
if (!(key instanceof String))
{
return null;
}
String stringKey = (String) key;
if (!super.containsKey(stringKey))
{
SettingSection section = new SettingSection(stringKey);
super.put(stringKey, section);
return section;
}
return super.get(key);
}
}
private HashMap<String, SettingSection> sections = new Settings.SettingsSectionMap();
public SettingSection getSection(String sectionName)
{
return sections.get(sectionName);
}
public boolean isEmpty()
{
return sections.isEmpty();
}
public HashMap<String, SettingSection> getSections()
{
return sections;
}
public void loadSettings(SettingsActivityView view)
{
sections = new Settings.SettingsSectionMap();
HashSet<String> filesToExclude = new HashSet<>();
if (!TextUtils.isEmpty(gameId))
{
// for per-game settings, don't load the WiiMoteNew.ini settings
filesToExclude.add(SettingsFile.FILE_NAME_WIIMOTE);
}
loadDolphinSettings(view, filesToExclude);
if (!TextUtils.isEmpty(gameId))
{
loadGenericGameSettings(gameId, view);
loadCustomGameSettings(gameId, view);
}
}
private void loadDolphinSettings(SettingsActivityView view, HashSet<String> filesToExclude)
{
for (Map.Entry<String, List<String>> entry : configFileSectionsMap.entrySet())
{
String fileName = entry.getKey();
if(filesToExclude == null || !filesToExclude.contains(fileName))
{
sections.putAll(SettingsFile.readFile(fileName, view));
}
}
}
private void loadGenericGameSettings(String gameId, SettingsActivityView view)
{
// generic game settings
mergeSections(SettingsFile.readGenericGameSettings(gameId, view));
mergeSections(SettingsFile.readGenericGameSettingsForAllRegions(gameId, view));
}
private void loadCustomGameSettings(String gameId, SettingsActivityView view)
{
// custom game settings
mergeSections(SettingsFile.readCustomGameSettings(gameId, view));
}
private void mergeSections(HashMap<String, SettingSection> updatedSections)
{
for (Map.Entry<String, SettingSection> entry : updatedSections.entrySet())
{
if (sections.containsKey(entry.getKey()))
{
SettingSection originalSection = sections.get(entry.getKey());
SettingSection updatedSection = entry.getValue();
originalSection.mergeSection(updatedSection);
}
else
{
sections.put(entry.getKey(), entry.getValue());
}
}
}
public void loadSettings(String gameId, SettingsActivityView view)
{
this.gameId = gameId;
loadSettings(view);
}
public void saveSettings(SettingsActivityView view)
{
if (TextUtils.isEmpty(gameId))
{
view.showToastMessage("Saved settings to INI files");
for (Map.Entry<String, List<String>> entry : configFileSectionsMap.entrySet())
{
String fileName = entry.getKey();
List<String> sectionNames = entry.getValue();
TreeMap<String, SettingSection> iniSections = new TreeMap<>();
for (String section : sectionNames)
{
iniSections.put(section, sections.get(section));
}
SettingsFile.saveFile(fileName, iniSections, view);
}
}
else
{
// custom game settings
view.showToastMessage("Saved settings for " + gameId);
SettingsFile.saveCustomGameSettings(gameId, sections);
}
}
}
@@ -1,12 +1,12 @@
package org.dolphinemu.dolphinemu.model.settings;
package org.dolphinemu.dolphinemu.features.settings.model;
public final class StringSetting extends Setting
{
private String mValue;
public StringSetting(String key, String section, int file, String value)
public StringSetting(String key, String section, String value)
{
super(key, section, file);
super(key, section);
mValue = value;
}
@@ -1,15 +1,15 @@
package org.dolphinemu.dolphinemu.model.settings.view;
package org.dolphinemu.dolphinemu.features.settings.model.view;
import org.dolphinemu.dolphinemu.model.settings.BooleanSetting;
import org.dolphinemu.dolphinemu.model.settings.Setting;
import org.dolphinemu.dolphinemu.features.settings.model.BooleanSetting;
import org.dolphinemu.dolphinemu.features.settings.model.Setting;
public final class CheckBoxSetting extends SettingsItem
{
private boolean mDefaultValue;
public CheckBoxSetting(String key, String section, int file, int titleId, int descriptionId, boolean defaultValue, Setting setting)
public CheckBoxSetting(String key, String section, int titleId, int descriptionId, boolean defaultValue, Setting setting)
{
super(key, section, file, setting, titleId, descriptionId);
super(key, section, setting, titleId, descriptionId);
mDefaultValue = defaultValue;
}
@@ -35,7 +35,7 @@ public BooleanSetting setChecked(boolean checked)
{
if (getSetting() == null)
{
BooleanSetting setting = new BooleanSetting(getKey(), getSection(), getFile(), checked);
BooleanSetting setting = new BooleanSetting(getKey(), getSection(), checked);
setSetting(setting);
return setting;
}
Oops, something went wrong.

0 comments on commit bfbf9ed

Please sign in to comment.