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.
This commit is contained in:
JosJuice 2021-06-22 15:04:40 +02:00
parent 5b8fe1e748
commit cbc4989095
7 changed files with 32 additions and 17 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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;
}
}

View File

@ -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)

View File

@ -251,20 +251,20 @@ public class TvUtil
/**
* 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;
}

View File

@ -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>