Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #9835 from JosJuice/android-hardcoded-strings
Android: Clean up some hardcoded strings
  • Loading branch information
lioncash committed Jun 22, 2021
2 parents 89a5bdf + 0cfd364 commit a904cb8
Show file tree
Hide file tree
Showing 16 changed files with 71 additions and 57 deletions.
2 changes: 1 addition & 1 deletion Source/Android/app/src/main/AndroidManifest.xml
Expand Up @@ -74,7 +74,7 @@
android:exported="false"
android:configChanges="orientation|screenSize"
android:theme="@style/DolphinSettingsBase"
android:label="@string/preferences_settings"/>
android:label="@string/settings"/>

<activity
android:name=".activities.EmulationActivity"
Expand Down
Expand Up @@ -88,20 +88,8 @@ public void onBindViewHolder(ViewHolder viewHolder, Object item)
holder.cardParent.setOnLongClickListener((view) ->
{
FragmentActivity activity = (FragmentActivity) view.getContext();
String gameId = gameFile.getGameId();

if (gameId.isEmpty())
{
AlertDialog.Builder builder = new AlertDialog.Builder(activity, R.style.DolphinDialogBase);
builder.setTitle("Game Settings");
builder.setMessage("Files without game IDs don't support game-specific settings.");

builder.show();
return true;
}

GamePropertiesDialog fragment = GamePropertiesDialog.newInstance(holder.gameFile);
((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction()
activity.getSupportFragmentManager().beginTransaction()
.add(fragment, GamePropertiesDialog.TAG).commit();

return true;
Expand Down
Expand Up @@ -90,7 +90,8 @@ public Dialog onCreateDialog(Bundle savedInstanceState)
long blockSize = gameFile.getBlockSize();
String compression = gameFile.getCompressionMethod();

textFileFormat.setText(String.format("%1$s (%2$s)", gameFile.getFileFormatName(), fileSize));
textFileFormat.setText(getResources().getString(R.string.game_details_size_and_format,
gameFile.getFileFormatName(), fileSize));

if (compression.isEmpty())
{
Expand Down
Expand Up @@ -96,7 +96,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState)
R.style.DolphinDialogBase);
itemsBuilder.applyToBuilder(builder);
builder.setTitle(requireContext()
.getString(R.string.preferences_game_properties) + ": " + gameId);
.getString(R.string.preferences_game_properties_with_game_id, gameId));
return builder.create();
}

Expand All @@ -113,18 +113,20 @@ private void clearGameSettings(String gameId)
{
if (gameSettingsFile.delete() || hadGameProfiles)
{
Toast.makeText(getContext(), "Cleared settings for " + gameId, Toast.LENGTH_SHORT)
.show();
Toast.makeText(getContext(),
getResources().getString(R.string.properties_clear_success, gameId),
Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(getContext(), "Unable to clear settings for " + gameId,
Toast.makeText(getContext(),
getResources().getString(R.string.properties_clear_failure, gameId),
Toast.LENGTH_SHORT).show();
}
}
else
{
Toast.makeText(getContext(), "No game settings to delete", Toast.LENGTH_SHORT).show();
Toast.makeText(getContext(), R.string.properties_clear_missing, Toast.LENGTH_SHORT).show();
}
}

Expand Down
Expand Up @@ -5,6 +5,7 @@
import android.widget.Toast;

import org.dolphinemu.dolphinemu.NativeLibrary;
import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.features.settings.ui.SettingsActivityView;
import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile;
import org.dolphinemu.dolphinemu.services.GameFileCacheService;
Expand Down Expand Up @@ -207,7 +208,7 @@ public void saveSettings(SettingsActivityView view, Context context)
if (!isGameSpecific())
{
if (context != null)
Toast.makeText(context, "Saved settings to INI files", Toast.LENGTH_SHORT).show();
Toast.makeText(context, R.string.settings_saved, Toast.LENGTH_SHORT).show();

for (Map.Entry<String, IniFile> entry : mIniFiles.entrySet())
{
Expand Down Expand Up @@ -238,7 +239,10 @@ public void saveSettings(SettingsActivityView view, Context context)
// custom game settings

if (context != null)
Toast.makeText(context, "Saved settings for " + mGameId, Toast.LENGTH_SHORT).show();
{
Toast.makeText(context, context.getString(R.string.settings_saved_game_specific, mGameId),
Toast.LENGTH_SHORT).show();
}

SettingsFile.saveCustomGameSettings(mGameId, getGameSpecificFile());

Expand Down
Expand Up @@ -170,7 +170,7 @@ public void onWiimoteSettingChanged(MenuTag menuTag, int value)
break;

case 2:
mView.showToastMessage("Please make sure Continuous Scanning is enabled in Core Settings.");
mView.showToastMessage(mContext.getString(R.string.make_sure_continuous_scan_enabled));
break;
}
}
Expand Down
Expand Up @@ -35,7 +35,7 @@ public final class SettingsFragment extends Fragment implements SettingsFragment

static
{
titles.put(MenuTag.SETTINGS, R.string.preferences_settings);
titles.put(MenuTag.SETTINGS, R.string.settings);
titles.put(MenuTag.CONFIG, R.string.config);
titles.put(MenuTag.CONFIG_GENERAL, R.string.general_submenu);
titles.put(MenuTag.CONFIG_INTERFACE, R.string.interface_submenu);
Expand Down
Expand Up @@ -121,7 +121,7 @@ private void loadSettingsList()
{
if (!TextUtils.isEmpty(mGameID))
{
mView.getActivity().setTitle("Game Settings: " + mGameID);
mView.getActivity().setTitle(mContext.getString(R.string.game_settings, mGameID));
}
ArrayList<SettingsItem> sl = new ArrayList<>();

Expand Down Expand Up @@ -217,8 +217,7 @@ private void loadSettingsList()
break;

default:
mView.showToastMessage("Unimplemented menu");
return;
throw new UnsupportedOperationException("Unimplemented menu");
}

mSettingsList = sl;
Expand Down
@@ -1,21 +1,18 @@
package org.dolphinemu.dolphinemu.model;

import android.net.Uri;

/**
* Represents a home screen channel for Android TV api 26+
*/
public class HomeScreenChannel
{

private long channelId;
private String name;
private String description;
private String appLinkIntentUri;

public HomeScreenChannel()
{
}
private Uri appLinkIntentUri;

public HomeScreenChannel(String name, String description, String appLinkIntentUri)
public HomeScreenChannel(String name, String description, Uri appLinkIntentUri)
{
this.name = name;
this.description = description;
Expand Down Expand Up @@ -52,12 +49,12 @@ public void setDescription(String description)
this.description = description;
}

public String getAppLinkIntentUri()
public Uri getAppLinkIntentUri()
{
return appLinkIntentUri;
}

public void setAppLinkIntentUri(String appLinkIntentUri)
public void setAppLinkIntentUri(Uri appLinkIntentUri)
{
this.appLinkIntentUri = appLinkIntentUri;
}
Expand Down
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 All @@ -111,7 +111,7 @@ private long createChannel(HomeScreenChannel subscription)
}

// Create the channel since it has not been added to the TV Provider.
Uri appLinkIntentUri = Uri.parse(subscription.getAppLinkIntentUri());
Uri appLinkIntentUri = subscription.getAppLinkIntentUri();

Channel.Builder builder = new Channel.Builder();
builder.setType(TvContractCompat.Channels.TYPE_PREVIEW)
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 Expand Up @@ -388,8 +388,7 @@ private ListRow buildSettingsRow()
R.string.grid_menu_import_nand_backup));

// Create a header for this row.
HeaderItem header =
new HeaderItem(R.string.preferences_settings, getString(R.string.preferences_settings));
HeaderItem header = new HeaderItem(R.string.settings, getString(R.string.settings));

return new ListRow(header, rowItems);
}
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)));
}
return subs;
}
Expand Down
14 changes: 13 additions & 1 deletion Source/Android/app/src/main/res/values/strings.xml
Expand Up @@ -122,10 +122,14 @@
<string name="turntable_crossfade">Crossfade</string>

<!-- Main Preference Fragment -->
<string name="settings">Settings</string>
<string name="game_settings">Game Settings: %1$s</string>
<string name="config">Config</string>
<string name="graphics_settings">Graphics Settings</string>
<string name="gcpad_settings">GameCube Input</string>
<string name="wiimote_settings">Wii Input</string>
<string name="settings_saved">Saved settings to INI files</string>
<string name="settings_saved_game_specific">Saved settings for %1$s</string>

<!-- General Preference Fragment -->
<string name="general_submenu">General</string>
Expand Down Expand Up @@ -330,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 All @@ -354,9 +361,12 @@
<string name="properties_set_default_iso">Set as Default ISO</string>
<string name="properties_edit_game_settings">Edit Game Settings</string>
<string name="properties_clear_game_settings">Clear Game Settings</string>
<string name="properties_clear_success">Cleared settings for %1$s</string>
<string name="properties_clear_failure">Unable to clear settings for %1$s</string>
<string name="properties_clear_missing">No game settings to delete</string>
<string name="preferences_save_exit">Save and Exit</string>
<string name="preferences_settings">Settings</string>
<string name="preferences_game_properties">Game Properties</string>
<string name="preferences_game_properties_with_game_id">Game Properties: %1$s</string>
<string name="preferences_extensions">Extension Bindings</string>
<string name="game_ini_junk_title">Junk Data Found</string>
<string name="game_ini_junk_question">The settings file for this game contains extraneous data added by an old version of Dolphin. This will likely prevent global settings from working as intended.\n\nWould you like to fix this by deleting the settings file for this game? All game-specific settings and cheats that you have added will be removed. This cannot be undone.</string>
Expand All @@ -369,6 +379,7 @@
<string name="game_details_compression">Compression</string>
<string name="game_details_block_size">Block Size</string>
<string name="game_details_no_compression">No Compression</string>
<string name="game_details_size_and_format">%1$s (%2$s)</string>

<!-- Convert Screen -->
<string name="convert_format">Format</string>
Expand Down Expand Up @@ -468,5 +479,6 @@ It can efficiently compress both junk data and encrypted Wii data.
<string name="disc_number">Disc %1$d</string>
<string name="disabled_gc_overlay_notice">GameCube Controller 1 is set to \"None\"</string>
<string name="ignore_warning_alert_messages">Ignore for this session</string>
<string name="make_sure_continuous_scan_enabled">Please make sure Continuous Scanning is enabled in Core Settings.</string>

</resources>

0 comments on commit a904cb8

Please sign in to comment.