From 9ea8f297655b25949026a92cc8c51a591a47eb62 Mon Sep 17 00:00:00 2001 From: Ryan Meredith Date: Mon, 1 Jun 2020 07:43:19 -0400 Subject: [PATCH] Android: Conditionally respond to modified settings --- .../features/settings/model/Settings.java | 67 ++++++++++++------- .../settings/ui/SettingsActivity.java | 6 +- .../ui/SettingsActivityPresenter.java | 21 ++++-- .../settings/ui/SettingsActivityView.java | 4 +- .../features/settings/ui/SettingsAdapter.java | 14 ++-- .../settings/ui/SettingsFragment.java | 4 +- .../ui/SettingsFragmentPresenter.java | 3 +- .../settings/ui/SettingsFragmentView.java | 4 +- .../app/src/main/res/values/strings.xml | 1 - 9 files changed, 78 insertions(+), 46 deletions(-) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/Settings.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/Settings.java index b0ffbb1dc9..df0dd985ab 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/Settings.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/Settings.java @@ -1,15 +1,18 @@ package org.dolphinemu.dolphinemu.features.settings.model; +import android.content.Context; import android.text.TextUtils; import org.dolphinemu.dolphinemu.NativeLibrary; import org.dolphinemu.dolphinemu.features.settings.ui.SettingsActivityView; import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile; +import org.dolphinemu.dolphinemu.services.GameFileCacheService; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.TreeMap; public class Settings @@ -164,7 +167,7 @@ public class Settings loadSettings(view); } - public void saveSettings(SettingsActivityView view) + public void saveSettings(SettingsActivityView view, Context context, Set modifiedSettings) { if (TextUtils.isEmpty(gameId)) { @@ -183,38 +186,52 @@ public class Settings SettingsFile.saveFile(fileName, iniSections, view); } - switch (NativeLibrary - .GetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_DSP, - SettingsFile.KEY_DSP_ENGINE, DSP_HLE)) + if (modifiedSettings.contains(SettingsFile.KEY_DSP_ENGINE)) { - case DSP_HLE: - NativeLibrary - .SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_CORE, - SettingsFile.KEY_DSP_HLE, "True"); - NativeLibrary.SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_DSP, - SettingsFile.KEY_DSP_ENABLE_JIT, "True"); - break; + switch (NativeLibrary + .GetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_DSP, + SettingsFile.KEY_DSP_ENGINE, DSP_HLE)) + { + case DSP_HLE: + NativeLibrary + .SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_CORE, + SettingsFile.KEY_DSP_HLE, "True"); + NativeLibrary + .SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_DSP, + SettingsFile.KEY_DSP_ENABLE_JIT, "True"); + break; - case DSP_LLE_RECOMPILER: - NativeLibrary - .SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_CORE, - SettingsFile.KEY_DSP_HLE, "False"); - NativeLibrary.SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_DSP, - SettingsFile.KEY_DSP_ENABLE_JIT, "True"); - break; + case DSP_LLE_RECOMPILER: + NativeLibrary + .SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_CORE, + SettingsFile.KEY_DSP_HLE, "False"); + NativeLibrary + .SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_DSP, + SettingsFile.KEY_DSP_ENABLE_JIT, "True"); + break; - case DSP_LLE_INTERPRETER: - NativeLibrary - .SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_CORE, - SettingsFile.KEY_DSP_HLE, "False"); - NativeLibrary.SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_DSP, - SettingsFile.KEY_DSP_ENABLE_JIT, "False"); - break; + case DSP_LLE_INTERPRETER: + NativeLibrary + .SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_CORE, + SettingsFile.KEY_DSP_HLE, "False"); + NativeLibrary + .SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_DSP, + SettingsFile.KEY_DSP_ENABLE_JIT, "False"); + break; + } } // Notify the native code of the changes NativeLibrary.ReloadConfig(); NativeLibrary.ReloadWiimoteConfig(); + + if (modifiedSettings.contains(SettingsFile.KEY_RECURSIVE_ISO_PATHS)) + { + // Refresh game library + GameFileCacheService.startRescan(context); + } + + modifiedSettings.clear(); } else { diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivity.java index e34460f532..947a5d9722 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivity.java @@ -51,7 +51,7 @@ public final class SettingsActivity extends AppCompatActivity implements Setting Intent launcher = getIntent(); String gameID = launcher.getStringExtra(ARG_GAME_ID); MenuTag menuTag = (MenuTag) launcher.getSerializableExtra(ARG_MENU_TAG); - mPresenter.onCreate(savedInstanceState, menuTag, gameID); + mPresenter.onCreate(savedInstanceState, menuTag, gameID, getApplicationContext()); } @Override @@ -275,9 +275,9 @@ public final class SettingsActivity extends AppCompatActivity implements Setting } @Override - public void onSettingChanged() + public void onSettingChanged(String key) { - mPresenter.onSettingChanged(); + mPresenter.onSettingChanged(key); } @Override diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivityPresenter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivityPresenter.java index 77ce9cee9c..a66391d8bb 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivityPresenter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivityPresenter.java @@ -1,5 +1,6 @@ package org.dolphinemu.dolphinemu.features.settings.ui; +import android.content.Context; import android.content.IntentFilter; import android.os.Bundle; import android.text.TextUtils; @@ -11,6 +12,9 @@ import org.dolphinemu.dolphinemu.utils.DirectoryInitialization.DirectoryInitiali import org.dolphinemu.dolphinemu.utils.DirectoryStateReceiver; import org.dolphinemu.dolphinemu.utils.Log; +import java.util.HashSet; +import java.util.Set; + public final class SettingsActivityPresenter { private static final String KEY_SHOULD_SAVE = "should_save"; @@ -27,18 +31,22 @@ public final class SettingsActivityPresenter private MenuTag menuTag; private String gameId; + private Context context; + + private final Set modifiedSettings = new HashSet<>(); SettingsActivityPresenter(SettingsActivityView view) { mView = view; } - public void onCreate(Bundle savedInstanceState, MenuTag menuTag, String gameId) + public void onCreate(Bundle savedInstanceState, MenuTag menuTag, String gameId, Context context) { if (savedInstanceState == null) { this.menuTag = menuTag; this.gameId = gameId; + this.context = context; } else { @@ -126,7 +134,7 @@ public final class SettingsActivityPresenter public void clearSettings() { mSettings.clearSettings(); - onSettingChanged(); + onSettingChanged(null); } public void onStop(boolean finishing) @@ -140,7 +148,7 @@ public final class SettingsActivityPresenter if (mSettings != null && finishing && mShouldSave) { Log.debug("[SettingsActivity] Settings activity stopping. Saving settings to INI..."); - mSettings.saveSettings(mView); + mSettings.saveSettings(mView, context, modifiedSettings); } } @@ -174,8 +182,13 @@ public final class SettingsActivityPresenter return false; } - public void onSettingChanged() + public void onSettingChanged(String key) { + if (key != null) + { + modifiedSettings.add(key); + } + mShouldSave = true; } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivityView.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivityView.java index 71583aa989..3ad0c6b9cd 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivityView.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivityView.java @@ -69,8 +69,10 @@ public interface SettingsActivityView /** * Called by a containing Fragment to tell the Activity that a setting was changed; * unless this has been called, the Activity will not save to disk. + * + * @param key Key of the modified setting. */ - void onSettingChanged(); + void onSettingChanged(String key); /** * Called by a containing Fragment to tell the containing Activity that a GCPad's setting diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsAdapter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsAdapter.java index 2c2e009a44..e13eb36eb6 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsAdapter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsAdapter.java @@ -182,7 +182,7 @@ public final class SettingsAdapter extends RecyclerView.Adapter Paths Search Subfolders for Game Files - Refresh library after changing this setting. Default ISO Wii NAND Root Dump Path