Skip to content

Commit

Permalink
Android: Clean up hardcoded platform names
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
JosJuice committed Jun 22, 2021
1 parent 5b8fe1e commit cbc4989
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 17 deletions.
Expand Up @@ -85,7 +85,7 @@ protected Boolean doInBackground(Void... voids)
}
else
{
subscriptions = TvUtil.createUniversalSubscriptions();
subscriptions = TvUtil.createUniversalSubscriptions(context);
for (HomeScreenChannel subscription : subscriptions)
{
long channelId = createChannel(subscription);
Expand Down
Expand Up @@ -96,7 +96,8 @@ protected Boolean doInBackground(Long... channelIds)
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);
Expand Down
Expand Up @@ -349,7 +349,7 @@ private ListRow buildGamesRow(Platform platform, Collection<GameFile> gameFiles)
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);
Expand Down
@@ -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)
Expand All @@ -40,8 +44,13 @@ public int toInt()
return value;
}

public String getHeaderName()
public int getHeaderName()
{
return headerName;
}

public String getIdString()
{
return idString;
}
}
Expand Up @@ -4,6 +4,8 @@

import androidx.annotation.StringDef;

import org.dolphinemu.dolphinemu.ui.platform.Platform;

import java.util.List;

/**
Expand All @@ -29,9 +31,9 @@ public static Uri buildGameUri(long channelId, String gameId)
.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)
Expand Down
Expand Up @@ -251,20 +251,20 @@ private static int getJobIdForChannelId(long channelId)
/**
* Generates all subscriptions for homescreen channels.
*/
public static List<HomeScreenChannel> createUniversalSubscriptions()
public static List<HomeScreenChannel> createUniversalSubscriptions(Context context)
{
return new ArrayList<>(createPlatformSubscriptions());
return new ArrayList<>(createPlatformSubscriptions(context));
}

private static List<HomeScreenChannel> createPlatformSubscriptions()
private static List<HomeScreenChannel> createPlatformSubscriptions(Context context)
{
List<HomeScreenChannel> 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;
}
Expand Down
3 changes: 3 additions & 0 deletions Source/Android/app/src/main/res/values/strings.xml
Expand Up @@ -334,6 +334,9 @@
<string name="continue_anyway">Continue Anyway</string>

<!-- Game Grid Screen-->
<string name="platform_gamecube">GameCube Games</string>
<string name="platform_wii">Wii Games</string>
<string name="platform_wiiware">WiiWare Games</string>
<string name="add_directory_title">Add Folder to Library</string>
<string name="grid_menu_settings">Settings</string>
<string name="grid_menu_refresh">Refresh Library</string>
Expand Down

0 comments on commit cbc4989

Please sign in to comment.