Android: Refactor MainActivity, add forEachPlatformGamesView

This commit is contained in:
JosJuice 2021-02-20 17:55:31 +01:00
parent 5e4c6d42a1
commit 3a8793f93f
1 changed files with 6 additions and 11 deletions

View File

@ -28,6 +28,7 @@ import org.dolphinemu.dolphinemu.features.settings.ui.SettingsActivity;
import org.dolphinemu.dolphinemu.services.GameFileCacheService; import org.dolphinemu.dolphinemu.services.GameFileCacheService;
import org.dolphinemu.dolphinemu.ui.platform.Platform; import org.dolphinemu.dolphinemu.ui.platform.Platform;
import org.dolphinemu.dolphinemu.ui.platform.PlatformGamesView; import org.dolphinemu.dolphinemu.ui.platform.PlatformGamesView;
import org.dolphinemu.dolphinemu.utils.Action1;
import org.dolphinemu.dolphinemu.utils.AfterDirectoryInitializationRunner; import org.dolphinemu.dolphinemu.utils.AfterDirectoryInitializationRunner;
import org.dolphinemu.dolphinemu.utils.DirectoryInitialization; import org.dolphinemu.dolphinemu.utils.DirectoryInitialization;
import org.dolphinemu.dolphinemu.utils.FileBrowserHelper; 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, // In case the user changed a setting that affects how games are displayed,
// such as system language, cover downloading... // such as system language, cover downloading...
refetchMetadata(); forEachPlatformGamesView(PlatformGamesView::refetchMetadata);
if (sShouldRescanLibrary) if (sShouldRescanLibrary)
{ {
@ -266,26 +267,20 @@ public final class MainActivity extends AppCompatActivity implements MainView
return mPresenter.handleOptionSelection(item.getItemId(), this); return mPresenter.handleOptionSelection(item.getItemId(), this);
} }
@Override
public void showGames() public void showGames()
{ {
for (Platform platform : Platform.values()) forEachPlatformGamesView(PlatformGamesView::showGames);
{
PlatformGamesView fragment = getPlatformGamesView(platform);
if (fragment != null)
{
fragment.showGames();
}
}
} }
private void refetchMetadata() private void forEachPlatformGamesView(Action1<PlatformGamesView> action)
{ {
for (Platform platform : Platform.values()) for (Platform platform : Platform.values())
{ {
PlatformGamesView fragment = getPlatformGamesView(platform); PlatformGamesView fragment = getPlatformGamesView(platform);
if (fragment != null) if (fragment != null)
{ {
fragment.refetchMetadata(); action.call(fragment);
} }
} }
} }