From cbc4989095baff7b84694802bb195c0c79d56ebe Mon Sep 17 00:00:00 2001 From: JosJuice Date: Tue, 22 Jun 2021 15:04:40 +0200 Subject: [PATCH] Android: Clean up hardcoded platform names The same kind of change as the changes made in the previous commit, but this change is more involved, in particular because of how SyncProgramsJobService was using display names as keys. --- .../services/SyncChannelJobService.java | 2 +- .../services/SyncProgramsJobService.java | 3 ++- .../dolphinemu/ui/main/TvMainActivity.java | 2 +- .../dolphinemu/ui/platform/Platform.java | 21 +++++++++++++------ .../dolphinemu/utils/AppLinkHelper.java | 6 ++++-- .../dolphinemu/dolphinemu/utils/TvUtil.java | 12 +++++------ .../app/src/main/res/values/strings.xml | 3 +++ 7 files changed, 32 insertions(+), 17 deletions(-) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/services/SyncChannelJobService.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/services/SyncChannelJobService.java index da4d885de0..79e953d163 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/services/SyncChannelJobService.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/services/SyncChannelJobService.java @@ -85,7 +85,7 @@ public class SyncChannelJobService extends JobService } else { - subscriptions = TvUtil.createUniversalSubscriptions(); + subscriptions = TvUtil.createUniversalSubscriptions(context); for (HomeScreenChannel subscription : subscriptions) { long channelId = createChannel(subscription); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/services/SyncProgramsJobService.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/services/SyncProgramsJobService.java index 9818c30a4e..340c3684c9 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/services/SyncProgramsJobService.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/services/SyncProgramsJobService.java @@ -96,7 +96,8 @@ public class SyncProgramsJobService extends JobService Channel channel = TvUtil.getChannelById(context, channelId); for (Platform platform : Platform.values()) { - if (channel != null && channel.getDisplayName().equals(platform.getHeaderName())) + if (channel != null && + channel.getAppLinkIntentUri().equals(AppLinkHelper.buildBrowseUri(platform))) { getGamesByPlatform(platform); syncPrograms(channelId); 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 e7b522a10d..7207cb2d4f 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 @@ -349,7 +349,7 @@ public final class TvMainActivity extends FragmentActivity mGameRows.add(row); // Create a header for this row. - HeaderItem header = new HeaderItem(platform.toInt(), platform.getHeaderName()); + HeaderItem header = new HeaderItem(platform.toInt(), getString(platform.getHeaderName())); // Create the row, passing it the filled adapter and the header, and give it to the master adapter. return new ListRow(header, row); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/platform/Platform.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/platform/Platform.java index 914f13bb61..3ebf49c298 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/platform/Platform.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/platform/Platform.java @@ -1,21 +1,25 @@ package org.dolphinemu.dolphinemu.ui.platform; +import org.dolphinemu.dolphinemu.R; + /** * Enum to represent platform (eg GameCube, Wii). */ public enum Platform { - GAMECUBE(0, "GameCube Games"), - WII(1, "Wii Games"), - WIIWARE(2, "WiiWare Games"); + GAMECUBE(0, R.string.platform_gamecube, "GameCube Games"), + WII(1, R.string.platform_wii, "Wii Games"), + WIIWARE(2, R.string.platform_wiiware, "WiiWare Games"); private final int value; - private final String headerName; + private final int headerName; + private final String idString; - Platform(int value, String headerName) + Platform(int value, int headerName, String idString) { this.value = value; this.headerName = headerName; + this.idString = idString; } public static Platform fromInt(int i) @@ -40,8 +44,13 @@ public enum Platform return value; } - public String getHeaderName() + public int getHeaderName() { return headerName; } + + public String getIdString() + { + return idString; + } } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/AppLinkHelper.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/AppLinkHelper.java index efb70913f6..054ff7a187 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/AppLinkHelper.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/AppLinkHelper.java @@ -4,6 +4,8 @@ import android.net.Uri; import androidx.annotation.StringDef; +import org.dolphinemu.dolphinemu.ui.platform.Platform; + import java.util.List; /** @@ -29,9 +31,9 @@ public class AppLinkHelper .build(); } - public static Uri buildBrowseUri(String subscriptionName) + public static Uri buildBrowseUri(Platform platform) { - return Uri.parse(URI_VIEW).buildUpon().appendPath(subscriptionName).build(); + return Uri.parse(URI_VIEW).buildUpon().appendPath(platform.getIdString()).build(); } public static AppLinkAction extractAction(Uri uri) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/TvUtil.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/TvUtil.java index da3b87c060..4f3965553d 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/TvUtil.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/TvUtil.java @@ -251,20 +251,20 @@ public class TvUtil /** * Generates all subscriptions for homescreen channels. */ - public static List createUniversalSubscriptions() + public static List createUniversalSubscriptions(Context context) { - return new ArrayList<>(createPlatformSubscriptions()); + return new ArrayList<>(createPlatformSubscriptions(context)); } - private static List createPlatformSubscriptions() + private static List createPlatformSubscriptions(Context context) { List subs = new ArrayList<>(); for (Platform platform : Platform.values()) { subs.add(new HomeScreenChannel( - platform.getHeaderName(), - platform.getHeaderName(), - AppLinkHelper.buildBrowseUri(platform.getHeaderName()).toString())); + context.getString(platform.getHeaderName()), + context.getString(platform.getHeaderName()), + AppLinkHelper.buildBrowseUri(platform).toString())); } return subs; } diff --git a/Source/Android/app/src/main/res/values/strings.xml b/Source/Android/app/src/main/res/values/strings.xml index 9c59383d33..7943ebbf8e 100644 --- a/Source/Android/app/src/main/res/values/strings.xml +++ b/Source/Android/app/src/main/res/values/strings.xml @@ -334,6 +334,9 @@ Continue Anyway + GameCube Games + Wii Games + WiiWare Games Add Folder to Library Settings Refresh Library