From 3a8793f93ffe836a7a503905199083867036ad52 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sat, 20 Feb 2021 17:55:31 +0100 Subject: [PATCH] Android: Refactor MainActivity, add forEachPlatformGamesView --- .../dolphinemu/ui/main/MainActivity.java | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) 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 2beb2112f2..1addf82258 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 @@ -28,6 +28,7 @@ import org.dolphinemu.dolphinemu.features.settings.ui.SettingsActivity; import org.dolphinemu.dolphinemu.services.GameFileCacheService; import org.dolphinemu.dolphinemu.ui.platform.Platform; import org.dolphinemu.dolphinemu.ui.platform.PlatformGamesView; +import org.dolphinemu.dolphinemu.utils.Action1; import org.dolphinemu.dolphinemu.utils.AfterDirectoryInitializationRunner; import org.dolphinemu.dolphinemu.utils.DirectoryInitialization; import org.dolphinemu.dolphinemu.utils.FileBrowserHelper; @@ -90,7 +91,7 @@ public final class MainActivity extends AppCompatActivity implements MainView // In case the user changed a setting that affects how games are displayed, // such as system language, cover downloading... - refetchMetadata(); + forEachPlatformGamesView(PlatformGamesView::refetchMetadata); if (sShouldRescanLibrary) { @@ -266,26 +267,20 @@ public final class MainActivity extends AppCompatActivity implements MainView return mPresenter.handleOptionSelection(item.getItemId(), this); } + @Override public void showGames() { - for (Platform platform : Platform.values()) - { - PlatformGamesView fragment = getPlatformGamesView(platform); - if (fragment != null) - { - fragment.showGames(); - } - } + forEachPlatformGamesView(PlatformGamesView::showGames); } - private void refetchMetadata() + private void forEachPlatformGamesView(Action1 action) { for (Platform platform : Platform.values()) { PlatformGamesView fragment = getPlatformGamesView(platform); if (fragment != null) { - fragment.refetchMetadata(); + action.call(fragment); } } }