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 Feb 13, 2020
1 parent 7145bd1 commit 13e1808
Show file tree
Hide file tree
Showing 23 changed files with 479 additions and 30 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,38 @@
package org.dolphinemu.dolphinemu.features.settings.model.view;

public final class ConfirmRunnable extends SettingsItem
{
private int mAlertText;
private int mConfirmationText;
private Runnable mRunnable;

public ConfirmRunnable(int titleId, int descriptionId, int alertText, int confirmationText,
Runnable runnable)
{
super(null, null, null, titleId, descriptionId);
mAlertText = alertText;
mConfirmationText = confirmationText;
mRunnable = runnable;
}

public int getAlertText()
{
return mAlertText;
}

public int getConfirmationText()
{
return mConfirmationText;
}

public Runnable getRunnable()
{
return mRunnable;
}

@Override
public int getType()
{
return TYPE_CONFIRM_RUNNABLE;
}
}
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 int mRequestType;

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

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

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

public int getRequestType()
{
return mRequestType;
}

@Override
public int getType()
{
return TYPE_FILE_PICKER;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ 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;
public static final int TYPE_CONFIRM_RUNNABLE = 10;

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 @@ -22,6 +23,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.InputBindingSetting;
import org.dolphinemu.dolphinemu.features.settings.model.view.RumbleBindingSetting;
import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem;
Expand All @@ -31,6 +33,8 @@
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.ConfirmRunnableViewHolder;
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,9 +43,13 @@
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.fragments.CustomFilePickerFragment;
import org.dolphinemu.dolphinemu.ui.main.MainPresenter;
import org.dolphinemu.dolphinemu.utils.FileBrowserHelper;
import org.dolphinemu.dolphinemu.utils.Log;

import java.util.ArrayList;
import java.util.Set;

public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolder>
implements DialogInterface.OnClickListener, SeekBar.OnSeekBarChangeListener
Expand All @@ -57,6 +65,9 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
private AlertDialog mDialog;
private TextView mTextSliderValue;

private static FilePicker mFilePicker;
private static SettingsItem mItem;

public SettingsAdapter(SettingsFragmentView view, Context context)
{
mView = view;
Expand Down Expand Up @@ -102,6 +113,14 @@ 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);

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

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

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

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

public void onFilePickerFileClick(SettingsItem item)
{
mFilePicker = (FilePicker) item;
mItem = item;

FileBrowserHelper
.openFilePicker(mView.getActivity(), mFilePicker.getRequestType(), allowMulti());
}

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

public static void clearDefaultISO(SettingsFragmentView view)
{
NativeLibrary
.SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_CORE,
SettingsFile.KEY_DEFAULT_ISO, "");
NativeLibrary.ReloadConfig();
view.reloadSubMenu(MenuTag.CONFIG_PATHS);
}

public static boolean allowMulti()
{
return mFilePicker.getRequestType() == MainPresenter.REQUEST_SELECT_MULTI_GAMES;
}

public static Set<String> getExtensions()
{
try
{
if (mFilePicker.getRequestType() == MainPresenter.REQUEST_SD_FILE)
{
return CustomFilePickerFragment.SDExtensions;
}
else
{
return CustomFilePickerFragment.gameExtensions;
}
}
catch (NullPointerException e)
{
return CustomFilePickerFragment.gameExtensions;
}
}

@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 @@ -182,6 +183,14 @@ public void loadSubMenu(MenuTag menuKey)
mActivity.showSettingsFragment(menuKey, null, true, getArguments().getString(ARGUMENT_GAME_ID));
}

@Override
public void reloadSubMenu(MenuTag menuKey)
{
// TODO: Minor visual issue when pressing back afterwards. The transitions display, then menu items update.
mActivity
.showSettingsFragment(menuKey, null, false, getArguments().getString(ARGUMENT_GAME_ID));
}

@Override
public void showToastMessage(String message)
{
Expand Down Expand Up @@ -217,5 +226,4 @@ public void onExtensionSettingChanged(MenuTag menuTag, int value)
{
mActivity.onExtensionSettingChanged(menuTag, value);
}

}
Loading

0 comments on commit 13e1808

Please sign in to comment.