From 6380c65ff858c9147e5f7d7da21219db52853682 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sun, 11 Oct 2020 20:51:23 +0200 Subject: [PATCH] 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(); }