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 Mar 10, 2020
1 parent 7145bd1 commit 240bec8
Show file tree
Hide file tree
Showing 22 changed files with 490 additions and 38 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 All @@ -26,7 +27,8 @@ public enum MenuTag
WIIMOTE_EXTENSION_1("wiimote_extension", 4),
WIIMOTE_EXTENSION_2("wiimote_extension", 5),
WIIMOTE_EXTENSION_3("wiimote_extension", 6),
WIIMOTE_EXTENSION_4("wiimote_extension", 7);
WIIMOTE_EXTENSION_4("wiimote_extension", 7),
BLANK("Blank");

private String tag;
private int subType = -1;
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 @@ -103,13 +105,13 @@ public void onBackPressed()

@Override
public void showSettingsFragment(MenuTag menuTag, Bundle extras, boolean addToStack,
String gameID)
boolean reload, String gameID)
{
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

if (addToStack)
{
if (areSystemAnimationsEnabled())
if (areSystemAnimationsEnabled() && !reload)
{
transaction.setCustomAnimations(
R.animator.settings_enter,
Expand Down Expand Up @@ -154,6 +156,31 @@ public void stopListeningToDirectoryInitializationService(DirectoryStateReceiver
LocalBroadcastManager.getInstance(this).unregisterReceiver(receiver);
}

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

// Save modified non-FilePicker settings beforehand since finish() won't save them.
// onStop() must come before handling the resultCode to properly save FilePicker selection.
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));

// Prevent duplicate Toasts.
if (!mPresenter.mShouldSave)
{
Toast.makeText(this, "Saved settings to INI files", 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 @@ -21,7 +21,7 @@ public final class SettingsActivityPresenter

private int mStackCount;

private boolean mShouldSave;
boolean mShouldSave;

private DirectoryStateReceiver directoryStateReceiver;

Expand Down Expand Up @@ -70,7 +70,7 @@ private void loadSettingsUI()
}
}

mView.showSettingsFragment(menuTag, null, false, gameId);
mView.showSettingsFragment(menuTag, null, false, false, gameId);
mView.onSettingsFileLoaded(mSettings);
}

Expand Down Expand Up @@ -190,7 +190,7 @@ public void onGcPadSettingChanged(MenuTag key, int value)
{
Bundle bundle = new Bundle();
bundle.putInt(SettingsFragmentPresenter.ARG_CONTROLLER_TYPE, value / 6);
mView.showSettingsFragment(key, bundle, true, gameId);
mView.showSettingsFragment(key, bundle, true, false, gameId);
}
}

Expand All @@ -199,7 +199,7 @@ public void onWiimoteSettingChanged(MenuTag menuTag, int value)
switch (value)
{
case 1:
mView.showSettingsFragment(menuTag, null, true, gameId);
mView.showSettingsFragment(menuTag, null, true, false, gameId);
break;

case 2:
Expand All @@ -214,7 +214,12 @@ public void onExtensionSettingChanged(MenuTag menuTag, int value)
{
Bundle bundle = new Bundle();
bundle.putInt(SettingsFragmentPresenter.ARG_CONTROLLER_TYPE, value);
mView.showSettingsFragment(menuTag, bundle, true, gameId);
mView.showSettingsFragment(menuTag, bundle, true, false, gameId);
}
}

public void onFileConfirmed(String file)
{
SettingsAdapter.onFilePickerConfirmation(file);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ public interface SettingsActivityView
*
* @param menuTag Identifier for the settings group that should be displayed.
* @param addToStack Whether or not this fragment should replace a previous one.
* @param reload Custom animations are not used if set to true.
*/
void showSettingsFragment(MenuTag menuTag, Bundle extras, boolean addToStack, String gameId);
void showSettingsFragment(MenuTag menuTag, Bundle extras, boolean addToStack, boolean reload,
String gameId);

/**
* Called by a contained Fragment to get access to the Setting HashMap
Expand Down
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,15 @@
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;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

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

private static FilePicker mFilePicker;
private static SettingsItem mItem;

private static final Set<String> gameExtensions = new HashSet<>(Arrays.asList(
"gcm", "tgc", "iso", "ciso", "gcz", "wbfs", "wad", "dol", "elf", "dff"));

private static final Set<String> SDExtensions = new HashSet<>(Collections.singletonList("raw"));

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

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

public void onFilePickerDirectoryClick()
{
FileBrowserHelper.openDirectoryPicker(mView.getActivity());
}

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

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

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

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

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

@Override
public void onClick(DialogInterface dialog, int which)
{
Expand Down
Loading

0 comments on commit 240bec8

Please sign in to comment.