Permalink
Browse files

RfC: Refactor the settings for Android to use dedicated tags

Before we used different way of identifying which settings menu to
show, someotimes we used the section name, other times we used the
settings file name. This one replaces all those different ways by just
one way based on a menu tag which is more clear and easy to follow.
  • Loading branch information...
mahdihijazi committed Feb 6, 2018
1 parent 9cfcbfa commit 87534f1b2f6f3ef62470cacb7891aa9a62d99d95
Showing with 277 additions and 130 deletions.
  1. +3 −3 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameAdapter.java
  2. +3 −3 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameRowPresenter.java
  3. +16 −0 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/settings/IntSetting.java
  4. +14 −1 .../Android/app/src/main/java/org/dolphinemu/dolphinemu/model/settings/view/SingleChoiceSetting.java
  5. +4 −3 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/settings/view/SubmenuSetting.java
  6. +2 −1 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java
  7. +5 −5 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainPresenter.java
  8. +2 −5 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainView.java
  9. +2 −1 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/TvMainActivity.java
  10. +104 −0 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/MenuTag.java
  11. +11 −14 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsActivity.java
  12. +15 −11 ...ce/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsActivityPresenter.java
  13. +8 −8 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsActivityView.java
  14. +14 −11 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsAdapter.java
  15. +18 −12 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsFragment.java
  16. +49 −44 ...ce/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsFragmentPresenter.java
  17. +7 −8 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsFragmentView.java
@@ -14,9 +14,9 @@
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.utils.PicassoUtils;
import org.dolphinemu.dolphinemu.utils.SettingsFile;
import org.dolphinemu.dolphinemu.viewholders.GameViewHolder;
import java.io.File;
@@ -156,10 +156,10 @@ public boolean onLongClick(View view)
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case 0:
SettingsActivity.launch(activity, SettingsFile.FILE_NAME_DOLPHIN, gameId);
SettingsActivity.launch(activity, MenuTag.CONFIG, gameId);
break;
case 1:
SettingsActivity.launch(activity, SettingsFile.FILE_NAME_GFX, gameId);
SettingsActivity.launch(activity, MenuTag.GRAPHICS, gameId);
break;
case 2:
String path = DirectoryInitializationService.getUserDirectory() + "/GameSettings/" + gameId + ".ini";
@@ -17,9 +17,9 @@
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.utils.PicassoUtils;
import org.dolphinemu.dolphinemu.utils.SettingsFile;
import org.dolphinemu.dolphinemu.viewholders.TvGameViewHolder;
import java.io.File;
@@ -103,10 +103,10 @@ public boolean onLongClick(View view)
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case 0:
SettingsActivity.launch(activity, SettingsFile.FILE_NAME_DOLPHIN, gameId);
SettingsActivity.launch(activity, MenuTag.CONFIG, gameId);
break;
case 1:
SettingsActivity.launch(activity, SettingsFile.FILE_NAME_GFX, gameId);
SettingsActivity.launch(activity, MenuTag.GRAPHICS, gameId);
break;
case 2:
String path = DirectoryInitializationService.getUserDirectory() + "/GameSettings/" + gameId + ".ini";
@@ -1,15 +1,25 @@
package org.dolphinemu.dolphinemu.model.settings;
import org.dolphinemu.dolphinemu.ui.settings.MenuTag;
public final class IntSetting extends Setting
{
private int mValue;
private MenuTag menuTag;
public IntSetting(String key, String section, int file, int value)
{
super(key, section, file);
mValue = value;
}
public IntSetting(String key, String section, int file, int value, MenuTag menuTag)
{
super(key, section, file);
mValue = value;
this.menuTag = menuTag;
}
public int getValue()
{
return mValue;
@@ -25,4 +35,10 @@ public String getValueAsString()
{
return Integer.toString(mValue);
}
public MenuTag getMenuTag()
{
return menuTag;
}
}
@@ -2,20 +2,28 @@
import org.dolphinemu.dolphinemu.model.settings.IntSetting;
import org.dolphinemu.dolphinemu.model.settings.Setting;
import org.dolphinemu.dolphinemu.ui.settings.MenuTag;
public final class SingleChoiceSetting extends SettingsItem
{
private int mDefaultValue;
private int mChoicesId;
private int mValuesId;
private MenuTag menuTag;
public SingleChoiceSetting(String key, String section, int file, 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, MenuTag menuTag)
{
super(key, section, file, setting, titleId, descriptionId);
mValuesId = valuesId;
mChoicesId = choicesId;
mDefaultValue = defaultValue;
this.menuTag = menuTag;
}
public SingleChoiceSetting(String key, String section, int file, int titleId, int descriptionId, int choicesId, int valuesId, int defaultValue, Setting setting)
{
this(key, section, file, titleId, descriptionId, choicesId, valuesId, defaultValue, setting, null);
}
public int getChoicesId()
@@ -41,6 +49,11 @@ public int getSelectedValue()
}
}
public MenuTag getMenuTag()
{
return menuTag;
}
/**
* Write a value to the backing int. If that int was previously null,
* initializes a new one and returns it, so it can be added to the Hashmap.
@@ -1,18 +1,19 @@
package org.dolphinemu.dolphinemu.model.settings.view;
import org.dolphinemu.dolphinemu.model.settings.Setting;
import org.dolphinemu.dolphinemu.ui.settings.MenuTag;
public final class SubmenuSetting extends SettingsItem
{
private String mMenuKey;
private MenuTag mMenuKey;
public SubmenuSetting(String key, Setting setting, int titleId, int descriptionId, String menuKey)
public SubmenuSetting(String key, Setting setting, int titleId, int descriptionId, MenuTag menuKey)
{
super(key, null, 0, setting, titleId, descriptionId);
mMenuKey = menuKey;
}
public String getMenuKey()
public MenuTag getMenuKey()
{
return mMenuKey;
}
@@ -21,6 +21,7 @@
import org.dolphinemu.dolphinemu.services.GameFileCacheService;
import org.dolphinemu.dolphinemu.ui.platform.Platform;
import org.dolphinemu.dolphinemu.ui.platform.PlatformGamesView;
import org.dolphinemu.dolphinemu.ui.settings.MenuTag;
import org.dolphinemu.dolphinemu.ui.settings.SettingsActivity;
import org.dolphinemu.dolphinemu.utils.FileBrowserHelper;
import org.dolphinemu.dolphinemu.utils.PermissionsHandler;
@@ -129,7 +130,7 @@ public void refreshFragmentScreenshot(int fragmentPosition)
}
@Override
public void launchSettingsActivity(String menuTag)
public void launchSettingsActivity(MenuTag menuTag)
{
SettingsActivity.launch(this, menuTag, "");
}
@@ -10,7 +10,7 @@
import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.model.GameFileCache;
import org.dolphinemu.dolphinemu.services.GameFileCacheService;
import org.dolphinemu.dolphinemu.utils.SettingsFile;
import org.dolphinemu.dolphinemu.ui.settings.MenuTag;
public final class MainPresenter
{
@@ -64,19 +64,19 @@ public boolean handleOptionSelection(int itemId, Context context)
switch (itemId)
{
case R.id.menu_settings_core:
mView.launchSettingsActivity(SettingsFile.FILE_NAME_DOLPHIN);
mView.launchSettingsActivity(MenuTag.CONFIG);
return true;
case R.id.menu_settings_video:
mView.launchSettingsActivity(SettingsFile.FILE_NAME_GFX);
mView.launchSettingsActivity(MenuTag.GRAPHICS);
return true;
case R.id.menu_settings_gcpad:
mView.launchSettingsActivity(SettingsFile.FILE_NAME_GCPAD);
mView.launchSettingsActivity(MenuTag.GCPAD_TYPE);
return true;
case R.id.menu_settings_wiimote:
mView.launchSettingsActivity(SettingsFile.FILE_NAME_WIIMOTE);
mView.launchSettingsActivity(MenuTag.WIIMOTE);
return true;
case R.id.menu_refresh:
@@ -1,9 +1,6 @@
package org.dolphinemu.dolphinemu.ui.main;
import android.database.Cursor;
import org.dolphinemu.dolphinemu.model.GameFile;
import org.dolphinemu.dolphinemu.ui.platform.Platform;
import org.dolphinemu.dolphinemu.ui.settings.MenuTag;
/**
* Abstraction for the screen that shows on application launch.
@@ -29,7 +26,7 @@
void refreshFragmentScreenshot(int fragmentPosition);
void launchSettingsActivity(String menuTag);
void launchSettingsActivity(MenuTag menuTag);
void launchFileListActivity();
@@ -23,6 +23,7 @@
import org.dolphinemu.dolphinemu.services.DirectoryInitializationService;
import org.dolphinemu.dolphinemu.services.GameFileCacheService;
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.utils.FileBrowserHelper;
import org.dolphinemu.dolphinemu.utils.PermissionsHandler;
@@ -119,7 +120,7 @@ public void refreshFragmentScreenshot(int fragmentPosition)
}
@Override
public void launchSettingsActivity(String menuTag)
public void launchSettingsActivity(MenuTag menuTag)
{
SettingsActivity.launch(this, menuTag, "");
}
@@ -0,0 +1,104 @@
package org.dolphinemu.dolphinemu.ui.settings;
public enum MenuTag
{
CONFIG("config"),
CONFIG_GENERAL("config_general"),
CONFIG_INTERFACE("config_interface"),
WIIMOTE("wiimote"),
WIIMOTE_EXTENSION("wiimote_extension"),
GCPAD_TYPE("gc_pad_type"),
GRAPHICS("graphics"),
HACKS("hacks"),
ENHANCEMENTS("enhancements"),
STEREOSCOPY("stereoscopy"),
GCPAD_1("gcpad", 0),
GCPAD_2("gcpad", 1),
GCPAD_3("gcpad", 2),
GCPAD_4("gcpad", 3),
WIIMOTE_1("wiimote", 1),
WIIMOTE_2("wiimote", 2),
WIIMOTE_3("wiimote", 3),
WIIMOTE_4("wiimote", 4),
WIIMOTE_EXTENSION_1("wiimote_extension", 1),
WIIMOTE_EXTENSION_2("wiimote_extension", 2),
WIIMOTE_EXTENSION_3("wiimote_extension", 3),
WIIMOTE_EXTENSION_4("wiimote_extension", 4);
private String tag;
private int subType = -1;
MenuTag(String tag)
{
this.tag = tag;
}
MenuTag(String tag, int subtype)
{
this.tag = tag;
this.subType = subtype;
}
@Override
public String toString()
{
if (subType != -1)
{
return tag + subType;
}
return tag;
}
public String getTag()
{
return tag;
}
public int getSubType()
{
return subType;
}
public boolean isGCPadMenu()
{
return this == GCPAD_1 || this == GCPAD_2 || this == GCPAD_3 || this == GCPAD_4;
}
public boolean isWiimoteMenu()
{
return this == WIIMOTE_1 || this == WIIMOTE_2 || this == WIIMOTE_3 || this == WIIMOTE_4;
}
public boolean isWiimoteExtensionMenu()
{
return this == WIIMOTE_EXTENSION_1 || this == WIIMOTE_EXTENSION_2
|| this == WIIMOTE_EXTENSION_3 || this == WIIMOTE_EXTENSION_4;
}
public static MenuTag getGCPadMenuTag(int subtype)
{
return getMenuTag("gcpad", subtype);
}
public static MenuTag getWiimoteMenuTag(int subtype)
{
return getMenuTag("wiimote", subtype);
}
public static MenuTag getWiimoteExtensionMenuTag(int subtype)
{
return getMenuTag("wiimote_extension", subtype);
}
private static MenuTag getMenuTag(String tag, int subtype)
{
for (MenuTag menuTag : MenuTag.values())
{
if (menuTag.tag.equals(tag) && menuTag.subType == subtype) return menuTag;
}
throw new IllegalArgumentException("You are asking for a menu that is not available or " +
"passing a wrong subtype");
}
}
Oops, something went wrong.

0 comments on commit 87534f1

Please sign in to comment.