Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android: Add Paths to UI #7920

Merged
merged 4 commits into from
Mar 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.dolphinemu.dolphinemu.activities;

import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;

import androidx.annotation.Nullable;
Expand All @@ -10,21 +12,38 @@
import org.dolphinemu.dolphinemu.fragments.CustomFilePickerFragment;

import java.io.File;
import java.util.HashSet;

public class CustomFilePickerActivity extends FilePickerActivity

{
public static final String EXTRA_EXTENSIONS = "dolphinemu.org.filepicker.extensions";

private HashSet<String> mExtensions;

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

Intent intent = getIntent();
if (intent != null)
{
mExtensions = (HashSet<String>) intent.getSerializableExtra(EXTRA_EXTENSIONS);
}
}

@Override
protected AbstractFilePickerFragment<File> getFragment(
@Nullable final String startPath, final int mode, final boolean allowMultiple,
final boolean allowCreateDir, final boolean allowExistingFile,
final boolean singleClick)
{
AbstractFilePickerFragment<File> fragment = new CustomFilePickerFragment();
CustomFilePickerFragment fragment = new CustomFilePickerFragment();
// startPath is allowed to be null. In that case, default folder should be SD-card and not "/"
fragment.setArgs(
startPath != null ? startPath : Environment.getExternalStorageDirectory().getPath(),
mode, allowMultiple, allowCreateDir, allowExistingFile, singleClick);
fragment.setExtensions(mExtensions);
return fragment;
}
}
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 Expand Up @@ -634,7 +633,8 @@ public void handleMenuAction(@MenuAction int menuAction)
return;

case MENU_ACTION_CHANGE_DISC:
FileBrowserHelper.openFilePicker(this, REQUEST_CHANGE_DISC, false);
FileBrowserHelper.openFilePicker(this, REQUEST_CHANGE_DISC, false,
FileBrowserHelper.GAME_EXTENSIONS);
return;

case MENU_SET_IR_SENSITIVITY:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@

import android.widget.Toast;

import org.dolphinemu.dolphinemu.NativeLibrary;
import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
import org.dolphinemu.dolphinemu.features.settings.ui.MenuTag;
import org.dolphinemu.dolphinemu.features.settings.ui.SettingsActivity;
import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile;
import org.dolphinemu.dolphinemu.ui.platform.Platform;
import org.dolphinemu.dolphinemu.utils.DirectoryInitialization;

Expand Down Expand Up @@ -61,22 +64,28 @@ public Dialog onCreateDialog(Bundle savedInstanceState)
.getSupportFragmentManager(), "game_details");
break;
case 1:
SettingsActivity.launch(getContext(), MenuTag.CONFIG, gameId);
NativeLibrary.SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini",
Settings.SECTION_INI_CORE, SettingsFile.KEY_DEFAULT_ISO, path);
NativeLibrary.ReloadConfig();
Toast.makeText(getContext(), "Default ISO set", Toast.LENGTH_SHORT).show();
break;
case 2:
SettingsActivity.launch(getContext(), MenuTag.GRAPHICS, gameId);
SettingsActivity.launch(getContext(), MenuTag.CONFIG, gameId);
break;
case 3:
SettingsActivity.launch(getContext(), MenuTag.GCPAD_TYPE, gameId);
SettingsActivity.launch(getContext(), MenuTag.GRAPHICS, gameId);
break;
case 4:
SettingsActivity.launch(getContext(), MenuTag.GCPAD_TYPE, gameId);
break;
case 5:
// Clear option for GC, Wii controls for else
if (platform == Platform.GAMECUBE.toInt())
clearGameSettings(gameId);
else
SettingsActivity.launch(getActivity(), MenuTag.WIIMOTE, gameId);
break;
case 5:
case 6:
clearGameSettings(gameId);
break;
}
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,50 @@
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 mFile;
private String mDefaultValue;
private int mRequestType;

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

public String getFile()
{
return mFile + ".ini";
}

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,32 @@ 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.shouldSave())
{
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 @@ -184,6 +184,11 @@ public void saveState(Bundle outState)
outState.putBoolean(KEY_SHOULD_SAVE, mShouldSave);
}

public boolean shouldSave()
{
return mShouldSave;
}

public void onGcPadSettingChanged(MenuTag key, int value)
{
if (value != 0) // Not disabled
Expand Down Expand Up @@ -217,4 +222,9 @@ public void onExtensionSettingChanged(MenuTag menuTag, int value)
mView.showSettingsFragment(menuTag, bundle, true, gameId);
}
}

public void onFileConfirmed(String file)
{
SettingsAdapter.onFilePickerConfirmation(file);
}
}
Loading