Skip to content

Commit

Permalink
Android: Add Paths to UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Ebola16 committed Jan 24, 2020
1 parent 202e64a commit da0a5be
Show file tree
Hide file tree
Showing 20 changed files with 270 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.Surface;
import android.view.View;
import android.widget.SeekBar;
import android.widget.TextView;
Expand Down Expand Up @@ -402,7 +401,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent result)
// If the user picked a file, as opposed to just backing out.
if (resultCode == MainActivity.RESULT_OK)
{
String newDiscPath = FileBrowserHelper.getSelectedDirectory(result);
String newDiscPath = FileBrowserHelper.getSelectedPath(result);
if (!TextUtils.isEmpty(newDiscPath))
{
NativeLibrary.ChangeDisc(newDiscPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

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_GENERAL = "General";
public static final String SECTION_INI_CORE = "Core";
public static final String SECTION_INI_INTERFACE = "Interface";
public static final String SECTION_INI_DSP = "DSP";
Expand Down Expand Up @@ -42,7 +42,8 @@ public class Settings
static
{
configFileSectionsMap.put(SettingsFile.FILE_NAME_DOLPHIN,
Arrays.asList(SECTION_INI_CORE, SECTION_INI_INTERFACE, SECTION_INI_DSP,
Arrays.asList(SECTION_INI_GENERAL, SECTION_INI_CORE, SECTION_INI_INTERFACE,
SECTION_INI_DSP,
SECTION_BINDINGS, SECTION_ANALYTICS, SECTION_DEBUG));
configFileSectionsMap.put(SettingsFile.FILE_NAME_GFX,
Arrays.asList(SECTION_GFX_SETTINGS, SECTION_GFX_ENHANCEMENTS, SECTION_GFX_HACKS,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.dolphinemu.dolphinemu.features.settings.model.view;

import org.dolphinemu.dolphinemu.features.settings.model.Setting;
import org.dolphinemu.dolphinemu.features.settings.model.StringSetting;

public final class FilePicker extends SettingsItem
{
private String mDefaultValue;
private boolean mIsDirectory;

public FilePicker(String key, String section, int titleId, int descriptionId,
String defaultVault, boolean isDirectory, Setting setting)
{
super(key, section, setting, titleId, descriptionId);
mDefaultValue = defaultVault;
mIsDirectory = isDirectory;
}

public boolean getIsDirectory()
{
return mIsDirectory;
}

public String getSelectedValue()
{
StringSetting setting = (StringSetting) getSetting();

if (setting == null)
{
return mDefaultValue;
}
else
{
return setting.getValue();
}
}

@Override
public int getType()
{
return TYPE_FILE_PICKER;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public abstract class SettingsItem
public static final int TYPE_STRING_SINGLE_CHOICE = 6;
public static final int TYPE_RUMBLE_BINDING = 7;
public static final int TYPE_SINGLE_CHOICE_DYNAMIC_DESCRIPTIONS = 8;
public static final int TYPE_FILE_PICKER = 9;

private String mKey;
private String mSection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public enum MenuTag
CONFIG("config"),
CONFIG_GENERAL("config_general"),
CONFIG_INTERFACE("config_interface"),
CONFIG_PATHS("config_paths"),
CONFIG_GAME_CUBE("config_gamecube"),
CONFIG_WII("config_wii"),
WIIMOTE("wiimote"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
import android.widget.Toast;

import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.ui.main.MainActivity;
import org.dolphinemu.dolphinemu.utils.DirectoryInitialization;
import org.dolphinemu.dolphinemu.utils.DirectoryStateReceiver;
import org.dolphinemu.dolphinemu.utils.FileBrowserHelper;

public final class SettingsActivity extends AppCompatActivity implements SettingsActivityView
{
Expand Down Expand Up @@ -154,6 +156,27 @@ public void stopListeningToDirectoryInitializationService(DirectoryStateReceiver
LocalBroadcastManager.getInstance(this).unregisterReceiver(receiver);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent result)
{
super.onActivityResult(requestCode, resultCode, result);

// TODO: Save modified non-FilePicker settings beforehand since finish() won't save them.
// onStop() must come before handling the resultCode to properly save FilePicker selection.
// Is there a better method?
mPresenter.onStop(true);

// If the user picked a file, as opposed to just backing out.
if (resultCode == MainActivity.RESULT_OK)
{
mPresenter.onFileConfirmed(FileBrowserHelper.getSelectedPath(result));
Toast.makeText(this, "Saved selection", Toast.LENGTH_SHORT).show();
}
// TODO: After result of FilePicker, duplicate SettingsActivity appears.
// Finish to avoid this. Is there a better method?
finish();
}

@Override
public void showLoading()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,9 @@ public void onExtensionSettingChanged(MenuTag menuTag, int value)
mView.showSettingsFragment(menuTag, bundle, true, gameId);
}
}

public void onFileConfirmed(String file)
{
SettingsAdapter.onFilePickerConfirmation(file);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.widget.SeekBar;
import android.widget.TextView;

import org.dolphinemu.dolphinemu.NativeLibrary;
import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.dialogs.MotionAlertDialog;
import org.dolphinemu.dolphinemu.features.settings.model.BooleanSetting;
Expand All @@ -31,6 +32,7 @@
import org.dolphinemu.dolphinemu.features.settings.model.view.StringSingleChoiceSetting;
import org.dolphinemu.dolphinemu.features.settings.model.view.SubmenuSetting;
import org.dolphinemu.dolphinemu.features.settings.ui.viewholder.CheckBoxSettingViewHolder;
import org.dolphinemu.dolphinemu.features.settings.ui.viewholder.FilePickerViewHolder;
import org.dolphinemu.dolphinemu.features.settings.ui.viewholder.HeaderViewHolder;
import org.dolphinemu.dolphinemu.features.settings.ui.viewholder.InputBindingSettingViewHolder;
import org.dolphinemu.dolphinemu.features.settings.ui.viewholder.RumbleBindingViewHolder;
Expand All @@ -39,6 +41,8 @@
import org.dolphinemu.dolphinemu.features.settings.ui.viewholder.SliderViewHolder;
import org.dolphinemu.dolphinemu.features.settings.ui.viewholder.SubmenuViewHolder;
import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile;
import org.dolphinemu.dolphinemu.ui.main.MainPresenter;
import org.dolphinemu.dolphinemu.utils.FileBrowserHelper;
import org.dolphinemu.dolphinemu.utils.Log;

import java.util.ArrayList;
Expand All @@ -57,6 +61,8 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
private AlertDialog mDialog;
private TextView mTextSliderValue;

private static SettingsItem mItem;

public SettingsAdapter(SettingsFragmentView view, Context context)
{
mView = view;
Expand Down Expand Up @@ -102,6 +108,10 @@ public SettingViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
view = inflater.inflate(R.layout.list_item_setting, parent, false);
return new RumbleBindingViewHolder(view, this, mContext);

case SettingsItem.TYPE_FILE_PICKER:
view = inflater.inflate(R.layout.list_item_setting, parent, false);
return new FilePickerViewHolder(view, this);

default:
Log.error("[SettingsAdapter] Invalid view type: " + viewType);
return null;
Expand Down Expand Up @@ -274,6 +284,28 @@ public void onInputBindingClick(final InputBindingSetting item, final int positi
dialog.show();
}

public void onFilePickerDirectoryClick(SettingsItem item)
{
mItem = item;

FileBrowserHelper.openDirectoryPicker(mView.getActivity());
}

public void onFilePickerSingleFileClick(SettingsItem item)
{
mItem = item;

FileBrowserHelper.openFilePicker(mView.getActivity(), MainPresenter.REQUEST_SELECT_FILE, false);
}

public static void onFilePickerConfirmation(String file)
{
NativeLibrary
.SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", mItem.getSection(), mItem.getKey(),
file);
NativeLibrary.ReloadConfig();
}

@Override
public void onClick(DialogInterface dialog, int which)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public final class SettingsFragment extends Fragment implements SettingsFragment
titles.put(MenuTag.CONFIG, R.string.preferences_settings);
titles.put(MenuTag.CONFIG_GENERAL, R.string.general_submenu);
titles.put(MenuTag.CONFIG_INTERFACE, R.string.interface_submenu);
titles.put(MenuTag.CONFIG_PATHS, R.string.paths_submenu);
titles.put(MenuTag.CONFIG_GAME_CUBE, R.string.gamecube_submenu);
titles.put(MenuTag.CONFIG_WII, R.string.wii_submenu);
titles.put(MenuTag.WIIMOTE, R.string.grid_menu_wiimote_settings);
Expand Down Expand Up @@ -217,5 +218,4 @@ public void onExtensionSettingChanged(MenuTag menuTag, int value)
{
mActivity.onExtensionSettingChanged(menuTag, value);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.os.Bundle;
import android.text.TextUtils;

import org.dolphinemu.dolphinemu.DolphinApplication;
import org.dolphinemu.dolphinemu.NativeLibrary;
import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.features.settings.model.BooleanSetting;
Expand All @@ -13,6 +12,7 @@
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;
import org.dolphinemu.dolphinemu.features.settings.model.view.FilePicker;
import org.dolphinemu.dolphinemu.features.settings.model.view.HeaderSetting;
import org.dolphinemu.dolphinemu.features.settings.model.view.InputBindingSetting;
import org.dolphinemu.dolphinemu.features.settings.model.view.RumbleBindingSetting;
Expand All @@ -26,7 +26,6 @@
import org.dolphinemu.dolphinemu.utils.DirectoryInitialization;
import org.dolphinemu.dolphinemu.utils.EGLHelper;
import org.dolphinemu.dolphinemu.utils.Log;
import org.dolphinemu.dolphinemu.utils.TvUtil;

import java.io.File;
import java.util.ArrayList;
Expand Down Expand Up @@ -135,6 +134,10 @@ private void loadSettingsList()
addInterfaceSettings(sl);
break;

case CONFIG_PATHS:
addPathsSettings(sl);
break;

case CONFIG_GAME_CUBE:
addGameCubeSettings(sl);
break;
Expand Down Expand Up @@ -205,6 +208,7 @@ private void addConfigSettings(ArrayList<SettingsItem> sl)
{
sl.add(new SubmenuSetting(null, null, R.string.general_submenu, 0, MenuTag.CONFIG_GENERAL));
sl.add(new SubmenuSetting(null, null, R.string.interface_submenu, 0, MenuTag.CONFIG_INTERFACE));
sl.add(new SubmenuSetting(null, null, R.string.paths_submenu, 0, MenuTag.CONFIG_PATHS));

sl.add(new SubmenuSetting(null, null, R.string.gamecube_submenu, 0, MenuTag.CONFIG_GAME_CUBE));
sl.add(new SubmenuSetting(null, null, R.string.wii_submenu, 0, MenuTag.CONFIG_WII));
Expand Down Expand Up @@ -307,6 +311,38 @@ private void addInterfaceSettings(ArrayList<SettingsItem> sl)
onScreenDisplayMessages));
}

private void addPathsSettings(ArrayList<SettingsItem> sl)
{
Setting defaultISO = null;
Setting NANDRootPath = null;
Setting dumpPath = null;
Setting loadPath = null;
Setting resourcePackPath = null;
Setting wiiSDCardPath = null;

SettingSection coreSection = mSettings.getSection(Settings.SECTION_INI_CORE);
SettingSection generalSection = mSettings.getSection(Settings.SECTION_INI_GENERAL);
defaultISO = coreSection.getSetting(SettingsFile.KEY_DEFAULT_ISO);
NANDRootPath = generalSection.getSetting(SettingsFile.KEY_NAND_ROOT_PATH);
dumpPath = generalSection.getSetting(SettingsFile.KEY_DUMP_PATH);
loadPath = generalSection.getSetting(SettingsFile.KEY_LOAD_PATH);
resourcePackPath = generalSection.getSetting(SettingsFile.KEY_RESOURCE_PACK_PATH);
wiiSDCardPath = generalSection.getSetting(SettingsFile.KEY_WII_SD_CARD_PATH);

sl.add(new FilePicker(SettingsFile.KEY_DEFAULT_ISO, Settings.SECTION_INI_CORE,
R.string.default_ISO, 0, "", false, defaultISO));
sl.add(new FilePicker(SettingsFile.KEY_NAND_ROOT_PATH, Settings.SECTION_INI_GENERAL,
R.string.wii_NAND_root, 0, getDefaultNANDRootPath(), true, NANDRootPath));
sl.add(new FilePicker(SettingsFile.KEY_DUMP_PATH, Settings.SECTION_INI_GENERAL,
R.string.dump_path, 0, getDefaultDumpPath(), true, dumpPath));
sl.add(new FilePicker(SettingsFile.KEY_LOAD_PATH, Settings.SECTION_INI_GENERAL,
R.string.load_path, 0, getDefaultLoadPath(), true, loadPath));
sl.add(new FilePicker(SettingsFile.KEY_RESOURCE_PACK_PATH, Settings.SECTION_INI_GENERAL,
R.string.resource_pack_path, 0, getDefaultResourcePackPath(), true, resourcePackPath));
sl.add(new FilePicker(SettingsFile.KEY_WII_SD_CARD_PATH, Settings.SECTION_INI_GENERAL,
R.string.SD_card_path, 0, getDefaultSDPath(), false, wiiSDCardPath));
}

private void addGameCubeSettings(ArrayList<SettingsItem> sl)
{
Setting systemLanguage = null;
Expand Down Expand Up @@ -1540,4 +1576,29 @@ else if (extension.equals("Turntable"))

return extensionValue;
}

private static String getDefaultNANDRootPath()
{
return DirectoryInitialization.getUserDirectory() + "/Wii";
}

private static String getDefaultDumpPath()
{
return DirectoryInitialization.getUserDirectory() + "/Dump";
}

private static String getDefaultLoadPath()
{
return DirectoryInitialization.getUserDirectory() + "/Load";
}

private static String getDefaultResourcePackPath()
{
return DirectoryInitialization.getUserDirectory() + "/ResourcePacks";
}

private static String getDefaultSDPath()
{
return DirectoryInitialization.getUserDirectory() + "/Wii/sd.raw";
}
}
Loading

0 comments on commit da0a5be

Please sign in to comment.