From 195b551d87c46684032a698f5a1988ab4015a8f2 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sun, 11 Oct 2020 19:08:37 +0200 Subject: [PATCH 1/3] Android: Allow reading global settings without a Settings object This makes things more convenient for code that just wants to read the current value of a setting. --- .../settings/model/AdHocBooleanSetting.java | 6 ++ .../settings/model/AdHocStringSetting.java | 57 +++++++++++++++++++ .../settings/model/BooleanSetting.java | 5 ++ .../features/settings/model/FloatSetting.java | 5 ++ .../features/settings/model/IntSetting.java | 5 ++ .../settings/model/StringSetting.java | 5 ++ .../dolphinemu/fragments/MenuFragment.java | 3 +- .../dolphinemu/model/GameFileCache.java | 7 +-- .../dolphinemu/ui/main/MainActivity.java | 6 +- .../dolphinemu/utils/Analytics.java | 31 +++++----- .../dolphinemu/dolphinemu/utils/Rumble.java | 6 +- 11 files changed, 103 insertions(+), 33 deletions(-) create mode 100644 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/AdHocStringSetting.java diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/AdHocBooleanSetting.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/AdHocBooleanSetting.java index 0626852b5d..e3e8bacaad 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/AdHocBooleanSetting.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/AdHocBooleanSetting.java @@ -49,4 +49,10 @@ public class AdHocBooleanSetting implements AbstractBooleanSetting { NativeConfig.setBoolean(settings.getWriteLayer(), mFile, mSection, mKey, newValue); } + + public static boolean getBooleanGlobal(String file, String section, String key, + boolean defaultValue) + { + return NativeConfig.getBoolean(NativeConfig.LAYER_ACTIVE, file, section, key, defaultValue); + } } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/AdHocStringSetting.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/AdHocStringSetting.java new file mode 100644 index 0000000000..5d69b92158 --- /dev/null +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/AdHocStringSetting.java @@ -0,0 +1,57 @@ +package org.dolphinemu.dolphinemu.features.settings.model; + +public class AdHocStringSetting implements AbstractStringSetting +{ + private final String mFile; + private final String mSection; + private final String mKey; + private final String mDefaultValue; + + public AdHocStringSetting(String file, String section, String key, String defaultValue) + { + mFile = file; + mSection = section; + mKey = key; + mDefaultValue = defaultValue; + + if (!NativeConfig.isSettingSaveable(file, section, key)) + { + throw new IllegalArgumentException("File/section/key is unknown or legacy"); + } + } + + @Override + public boolean isOverridden(Settings settings) + { + return NativeConfig.isOverridden(mFile, mSection, mKey); + } + + @Override + public boolean isRuntimeEditable() + { + return true; + } + + @Override + public boolean delete(Settings settings) + { + return NativeConfig.deleteKey(settings.getWriteLayer(), mFile, mSection, mKey); + } + + @Override + public String getString(Settings settings) + { + return NativeConfig.getString(NativeConfig.LAYER_ACTIVE, mFile, mSection, mKey, mDefaultValue); + } + + @Override + public void setString(Settings settings, String newValue) + { + NativeConfig.setString(settings.getWriteLayer(), mFile, mSection, mKey, newValue); + } + + public static String getStringGlobal(String file, String section, String key, String defaultValue) + { + return NativeConfig.getString(NativeConfig.LAYER_ACTIVE, file, section, key, defaultValue); + } +} diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/BooleanSetting.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/BooleanSetting.java index 15d5d9069e..53cfc419b3 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/BooleanSetting.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/BooleanSetting.java @@ -191,4 +191,9 @@ public enum BooleanSetting implements AbstractBooleanSetting settings.getSection(mFile, mSection).setBoolean(mKey, newValue); } } + + public boolean getBooleanGlobal() + { + return NativeConfig.getBoolean(NativeConfig.LAYER_ACTIVE, mFile, mSection, mKey, mDefaultValue); + } } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/FloatSetting.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/FloatSetting.java index d5fea9894a..d418302179 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/FloatSetting.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/FloatSetting.java @@ -73,4 +73,9 @@ public enum FloatSetting implements AbstractFloatSetting settings.getSection(mFile, mSection).setFloat(mKey, newValue); } } + + public float getFloatGlobal() + { + return NativeConfig.getFloat(NativeConfig.LAYER_ACTIVE, mFile, mSection, mKey, mDefaultValue); + } } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/IntSetting.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/IntSetting.java index 7c2824ca1d..031f93cf0c 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/IntSetting.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/IntSetting.java @@ -130,4 +130,9 @@ public enum IntSetting implements AbstractIntSetting settings.getSection(mFile, mSection).setInt(mKey, newValue); } } + + public int getIntGlobal() + { + return NativeConfig.getInt(NativeConfig.LAYER_ACTIVE, mFile, mSection, mKey, mDefaultValue); + } } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/StringSetting.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/StringSetting.java index 387ee3a504..3ca6f86606 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/StringSetting.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/StringSetting.java @@ -104,4 +104,9 @@ public enum StringSetting implements AbstractStringSetting settings.getSection(mFile, mSection).setString(mKey, newValue); } } + + public String getStringGlobal() + { + return NativeConfig.getString(NativeConfig.LAYER_ACTIVE, mFile, mSection, mKey, mDefaultValue); + } } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/MenuFragment.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/MenuFragment.java index 3badbd3e48..1da21470e8 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/MenuFragment.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/MenuFragment.java @@ -152,8 +152,7 @@ public final class MenuFragment extends Fragment implements View.OnClickListener LinearLayout options = requireView().findViewById(R.id.layout_options); - Settings settings = ((EmulationActivity) requireActivity()).getSettings(); - boolean savestatesEnabled = BooleanSetting.MAIN_ENABLE_SAVESTATES.getBoolean(settings); + boolean savestatesEnabled = BooleanSetting.MAIN_ENABLE_SAVESTATES.getBooleanGlobal(); int savestateVisibility = savestatesEnabled ? View.VISIBLE : View.GONE; options.findViewById(R.id.menu_quicksave).setVisibility(savestateVisibility); options.findViewById(R.id.menu_quickload).setVisibility(savestateVisibility); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/GameFileCache.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/GameFileCache.java index 5672553711..af417dac8f 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/GameFileCache.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/GameFileCache.java @@ -81,12 +81,7 @@ public class GameFileCache */ public boolean scanLibrary(Context context) { - boolean recursiveScan; - try (Settings settings = new Settings()) - { - settings.loadSettings(null); - recursiveScan = BooleanSetting.MAIN_RECURSIVE_ISO_PATHS.getBoolean(settings); - } + boolean recursiveScan = BooleanSetting.MAIN_RECURSIVE_ISO_PATHS.getBooleanGlobal(); removeNonExistentGameFolders(context); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java index a36a5dfe34..c2993edbf3 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java @@ -291,11 +291,7 @@ public final class MainActivity extends AppCompatActivity implements MainView } }); - try (Settings settings = new Settings()) - { - settings.loadSettings(null); - mViewPager.setCurrentItem(IntSetting.MAIN_LAST_PLATFORM_TAB.getInt(settings)); - } + mViewPager.setCurrentItem(IntSetting.MAIN_LAST_PLATFORM_TAB.getIntGlobal()); showGames(); GameFileCacheService.startLoad(this); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/Analytics.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/Analytics.java index 062f694219..b4aabebfb9 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/Analytics.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/Analytics.java @@ -24,44 +24,41 @@ public class Analytics { new AfterDirectoryInitializationRunner().run(context, false, () -> { - Settings settings = new Settings(); - settings.loadSettings(null); - if (!BooleanSetting.MAIN_ANALYTICS_PERMISSION_ASKED.getBoolean(settings)) + if (!BooleanSetting.MAIN_ANALYTICS_PERMISSION_ASKED.getBooleanGlobal()) { - showMessage(context, settings); - } - else - { - settings.close(); + showMessage(context); } }); } - private static void showMessage(Context context, Settings settings) + private static void showMessage(Context context) { new AlertDialog.Builder(context, R.style.DolphinDialogBase) .setTitle(context.getString(R.string.analytics)) .setMessage(context.getString(R.string.analytics_desc)) .setPositiveButton(R.string.yes, (dialogInterface, i) -> { - firstAnalyticsAdd(settings, true); + firstAnalyticsAdd(true); }) .setNegativeButton(R.string.no, (dialogInterface, i) -> { - firstAnalyticsAdd(settings, false); + firstAnalyticsAdd(false); }) .show(); } - private static void firstAnalyticsAdd(Settings settings, boolean enabled) + private static void firstAnalyticsAdd(boolean enabled) { - BooleanSetting.MAIN_ANALYTICS_ENABLED.setBoolean(settings, enabled); - BooleanSetting.MAIN_ANALYTICS_PERMISSION_ASKED.setBoolean(settings, true); + try (Settings settings = new Settings()) + { + settings.loadSettings(null); - // Context is set to null to avoid toasts - settings.saveSettings(null, null); + BooleanSetting.MAIN_ANALYTICS_ENABLED.setBoolean(settings, enabled); + BooleanSetting.MAIN_ANALYTICS_PERMISSION_ASKED.setBoolean(settings, true); - settings.close(); + // Context is set to null to avoid toasts + settings.saveSettings(null, null); + } } public static void sendReport(String endpoint, byte[] data) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/Rumble.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/Rumble.java index e7b7360537..908541d62b 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/Rumble.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/Rumble.java @@ -9,6 +9,7 @@ import android.util.SparseArray; import android.view.InputDevice; import org.dolphinemu.dolphinemu.activities.EmulationActivity; +import org.dolphinemu.dolphinemu.features.settings.model.AdHocStringSetting; import org.dolphinemu.dolphinemu.features.settings.model.Settings; import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile; @@ -28,9 +29,8 @@ public class Rumble for (int i = 0; i < 8; i++) { - String deviceName = activity.getSettings() - .getSection(Settings.FILE_DOLPHIN, Settings.SECTION_BINDINGS) - .getString(SettingsFile.KEY_EMU_RUMBLE + i, ""); + String deviceName = AdHocStringSetting.getStringGlobal(Settings.FILE_DOLPHIN, + Settings.SECTION_BINDINGS, SettingsFile.KEY_EMU_RUMBLE + i, ""); if (!deviceName.isEmpty()) { From 5e70dda4cc2ad9b1ecc9bda8b1b30916a3ee1661 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sun, 11 Oct 2020 19:32:27 +0200 Subject: [PATCH 2/3] Android: Allow disabling cover downloading In case someone wants to be very careful with how much bandwidth they use or with what data GameTDB.com collects on you. This is already an option in DolphinQt (though in DolphinQt it will switch entirely from using covers to banners when turned off). --- .../features/settings/model/BooleanSetting.java | 2 ++ .../settings/ui/SettingsFragmentPresenter.java | 3 ++- .../dolphinemu/utils/PicassoUtils.java | 14 +++++++++++++- .../Android/app/src/main/res/values/strings.xml | 2 +- Source/Core/Core/Config/UISettings.cpp | 4 ++++ Source/Core/UICommon/GameFile.cpp | 17 ++++++++++++++--- 6 files changed, 36 insertions(+), 6 deletions(-) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/BooleanSetting.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/BooleanSetting.java index 53cfc419b3..92085ea204 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/BooleanSetting.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/BooleanSetting.java @@ -38,6 +38,8 @@ public enum BooleanSetting implements AbstractBooleanSetting MAIN_RECURSIVE_ISO_PATHS(Settings.FILE_DOLPHIN, Settings.SECTION_INI_GENERAL, "RecursiveISOPaths", false), + MAIN_USE_GAME_COVERS(Settings.FILE_DOLPHIN, Settings.SECTION_INI_GENERAL, + "UseGameCovers", true), SYSCONF_SCREENSAVER(Settings.FILE_SYSCONF, "IPL", "SSV", false), SYSCONF_WIDESCREEN(Settings.FILE_SYSCONF, "IPL", "AR", true), diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.java index f3855edc84..410c9acd5f 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.java @@ -224,7 +224,6 @@ public final class SettingsFragmentPresenter sl.add(new SubmenuSetting(R.string.advanced_submenu, MenuTag.CONFIG_ADVANCED)); sl.add(new SubmenuSetting(R.string.log_submenu, MenuTag.CONFIG_LOG)); sl.add(new SubmenuSetting(R.string.debug_submenu, MenuTag.DEBUG)); - sl.add(new HeaderSetting(R.string.gametdb_thanks, 0)); } private void addGeneralSettings(ArrayList sl) @@ -247,6 +246,8 @@ public final class SettingsFragmentPresenter R.string.panic_handlers_description)); sl.add(new CheckBoxSetting(BooleanSetting.MAIN_OSD_MESSAGES, R.string.osd_messages, R.string.osd_messages_description)); + sl.add(new CheckBoxSetting(BooleanSetting.MAIN_USE_GAME_COVERS, R.string.download_game_covers, + 0)); } private void addAudioSettings(ArrayList sl) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/PicassoUtils.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/PicassoUtils.java index 07d51fd466..429480e34e 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/PicassoUtils.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/PicassoUtils.java @@ -10,6 +10,7 @@ import com.squareup.picasso.Callback; import com.squareup.picasso.Picasso; import org.dolphinemu.dolphinemu.R; +import org.dolphinemu.dolphinemu.features.settings.model.BooleanSetting; import org.dolphinemu.dolphinemu.model.GameFile; import java.io.File; @@ -62,7 +63,7 @@ public class PicassoUtils } // GameTDB has a pretty close to complete collection for US/EN covers. First pass at getting // the cover will be by the disk's region, second will be the US cover, and third EN. - else + else if (BooleanSetting.MAIN_USE_GAME_COVERS.getBooleanGlobal()) { Picasso.get() .load(CoverHelper.buildGameTDBUrl(gameFile, CoverHelper.getRegion(gameFile))) @@ -136,5 +137,16 @@ public class PicassoUtils } }); } + else + { + Picasso.get() + .load(R.drawable.no_banner) + .noFade() + .noPlaceholder() + .fit() + .centerInside() + .config(Bitmap.Config.ARGB_8888) + .into(imageView); + } } } diff --git a/Source/Android/app/src/main/res/values/strings.xml b/Source/Android/app/src/main/res/values/strings.xml index 6e92780e04..459ba566e9 100644 --- a/Source/Android/app/src/main/res/values/strings.xml +++ b/Source/Android/app/src/main/res/values/strings.xml @@ -158,7 +158,6 @@ Some touch controls will require additional tweaking if played in portrait Enable usage statistics reporting If authorized, Dolphin can collect data on its performance, feature usage, and configuration, as well as data on your system\'s hardware and operating system.\n\nNo private data is ever collected. This data helps us understand how people and emulated games use Dolphin and prioritize our efforts. It also helps us identify rare configurations that are causing bugs, performance and stability issues. This authorization can be revoked at any time through Dolphin\'s settings. - Thanks to GameTDB.com for providing GameCube and Wii covers! Interface @@ -166,6 +165,7 @@ Show a message box when a potentially serious error has occurred. Disabling this may avoid annoying and non-fatal messages, but it may result in major crashes having no explanation at all. Show On-Screen Display Messages Display messages over the emulation screen area. These messages include memory card writes, video backend and CPU information, and JIT cache clearing. + Download Game Covers from GameTDB.com Audio diff --git a/Source/Core/Core/Config/UISettings.cpp b/Source/Core/Core/Config/UISettings.cpp index bdd61b1d1e..60d33033ca 100644 --- a/Source/Core/Core/Config/UISettings.cpp +++ b/Source/Core/Core/Config/UISettings.cpp @@ -9,7 +9,11 @@ namespace Config // UI.General const Info MAIN_USE_DISCORD_PRESENCE{{System::Main, "General", "UseDiscordPresence"}, true}; +#ifdef ANDROID +const Info MAIN_USE_GAME_COVERS{{System::Main, "General", "UseGameCovers"}, true}; +#else const Info MAIN_USE_GAME_COVERS{{System::Main, "General", "UseGameCovers"}, false}; +#endif const Info MAIN_FOCUSED_HOTKEYS{{System::Main, "General", "HotkeysRequireFocus"}, true}; const Info MAIN_RECURSIVE_ISO_PATHS{{System::Main, "General", "RecursiveISOPaths"}, false}; diff --git a/Source/Core/UICommon/GameFile.cpp b/Source/Core/UICommon/GameFile.cpp index 102075e510..a169ef0f66 100644 --- a/Source/Core/UICommon/GameFile.cpp +++ b/Source/Core/UICommon/GameFile.cpp @@ -52,6 +52,17 @@ namespace UICommon namespace { const std::string EMPTY_STRING; + +bool UseGameCovers() +{ +#ifdef ANDROID + // Android has its own code for handling covers, written completely in Java. + // It's best if we disable the C++ cover code on Android to avoid duplicated data and such. + return false; +#else + return Config::Get(Config::MAIN_USE_GAME_COVERS); +#endif +} } // Anonymous namespace DiscIO::Language GameFile::GetConfigLanguage() const @@ -169,7 +180,7 @@ bool GameFile::IsValid() const bool GameFile::CustomCoverChanged() { - if (!m_custom_cover.buffer.empty() || !Config::Get(Config::MAIN_USE_GAME_COVERS)) + if (!m_custom_cover.buffer.empty() || !UseGameCovers()) return false; std::string path, name; @@ -196,7 +207,7 @@ bool GameFile::CustomCoverChanged() void GameFile::DownloadDefaultCover() { - if (!m_default_cover.buffer.empty() || !Config::Get(Config::MAIN_USE_GAME_COVERS)) + if (!m_default_cover.buffer.empty() || !UseGameCovers()) return; const auto cover_path = File::GetUserPath(D_COVERCACHE_IDX) + DIR_SEP; @@ -262,7 +273,7 @@ void GameFile::DownloadDefaultCover() bool GameFile::DefaultCoverChanged() { - if (!m_default_cover.buffer.empty() || !Config::Get(Config::MAIN_USE_GAME_COVERS)) + if (!m_default_cover.buffer.empty() || !UseGameCovers()) return false; const auto cover_path = File::GetUserPath(D_COVERCACHE_IDX) + DIR_SEP; From 6380c65ff858c9147e5f7d7da21219db52853682 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sun, 11 Oct 2020 20:51:23 +0200 Subject: [PATCH 3/3] Android: Refetch game metadata after returning from settings --- .../dolphinemu/adapters/GameAdapter.java | 8 ++++++++ .../dolphinemu/ui/main/MainActivity.java | 16 ++++++++++++++++ .../dolphinemu/ui/main/TvMainActivity.java | 19 +++++++++++++++++++ .../ui/platform/PlatformGamesFragment.java | 6 ++++++ .../ui/platform/PlatformGamesView.java | 5 +++++ 5 files changed, 54 insertions(+) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameAdapter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameAdapter.java index 5fd27ad5ab..5e813fd099 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameAdapter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameAdapter.java @@ -120,6 +120,14 @@ public final class GameAdapter extends RecyclerView.Adapter impl notifyDataSetChanged(); } + /** + * Re-fetches game metadata from the game file cache. + */ + public void refetchMetadata() + { + notifyItemRangeChanged(0, getItemCount()); + } + /** * Launches the game that was clicked on. * diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java index c2993edbf3..77c792fca7 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java @@ -87,6 +87,10 @@ public final class MainActivity extends AppCompatActivity implements MainView mPresenter.addDirIfNeeded(this); + // In case the user changed a setting that affects how games are displayed, + // such as system language, cover downloading... + refetchMetadata(); + if (sShouldRescanLibrary) { GameFileCacheService.startRescan(this); @@ -256,6 +260,18 @@ public final class MainActivity extends AppCompatActivity implements MainView } } + private void refetchMetadata() + { + for (Platform platform : Platform.values()) + { + PlatformGamesView fragment = getPlatformGamesView(platform); + if (fragment != null) + { + fragment.refetchMetadata(); + } + } + } + @Nullable private PlatformGamesView getPlatformGamesView(Platform platform) { diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/TvMainActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/TvMainActivity.java index 4f3146ef05..c53de7e0cb 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/TvMainActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/TvMainActivity.java @@ -32,6 +32,7 @@ import org.dolphinemu.dolphinemu.utils.StartupHandler; import org.dolphinemu.dolphinemu.utils.TvUtil; import org.dolphinemu.dolphinemu.viewholders.TvGameViewHolder; +import java.util.ArrayList; import java.util.Collection; public final class TvMainActivity extends FragmentActivity implements MainView @@ -42,6 +43,8 @@ public final class TvMainActivity extends FragmentActivity implements MainView private BrowseSupportFragment mBrowseFragment; + private ArrayList mGameRows = new ArrayList<>(); + @Override protected void onCreate(Bundle savedInstanceState) { @@ -72,6 +75,10 @@ public final class TvMainActivity extends FragmentActivity implements MainView mPresenter.addDirIfNeeded(this); + // In case the user changed a setting that affects how games are displayed, + // such as system language, cover downloading... + refetchMetadata(); + if (sShouldRescanLibrary) { GameFileCacheService.startRescan(this); @@ -185,6 +192,14 @@ public final class TvMainActivity extends FragmentActivity implements MainView buildRowsAdapter(); } + private void refetchMetadata() + { + for (ArrayObjectAdapter row : mGameRows) + { + row.notifyArrayItemRangeChanged(0, row.size()); + } + } + /** * Callback from AddDirectoryActivity. Applies any changes necessary to the GameGridActivity. * @@ -247,6 +262,7 @@ public final class TvMainActivity extends FragmentActivity implements MainView private void buildRowsAdapter() { ArrayObjectAdapter rowsAdapter = new ArrayObjectAdapter(new ListRowPresenter()); + mGameRows.clear(); if (PermissionsHandler.hasWriteAccess(this)) { @@ -281,6 +297,9 @@ public final class TvMainActivity extends FragmentActivity implements MainView ArrayObjectAdapter row = new ArrayObjectAdapter(new GameRowPresenter()); row.addAll(0, gameFiles); + // Keep a reference to the row in case we need to refresh it. + mGameRows.add(row); + // Create a header for this row. HeaderItem header = new HeaderItem(platform.toInt(), platform.getHeaderName()); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/platform/PlatformGamesFragment.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/platform/PlatformGamesFragment.java index 83040034ae..50d2499705 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/platform/PlatformGamesFragment.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/platform/PlatformGamesFragment.java @@ -85,6 +85,12 @@ public final class PlatformGamesFragment extends Fragment implements PlatformGam } } + @Override + public void refetchMetadata() + { + mAdapter.refetchMetadata(); + } + private void findViews(View root) { mRecyclerView = root.findViewById(R.id.grid_games); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/platform/PlatformGamesView.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/platform/PlatformGamesView.java index 50b3e25ba7..918f40c6e0 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/platform/PlatformGamesView.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/platform/PlatformGamesView.java @@ -25,4 +25,9 @@ public interface PlatformGamesView * To be called when the game file cache is updated. */ void showGames(); + + /** + * Re-fetches game metadata from the game file cache. + */ + void refetchMetadata(); }