Merge pull request #9835 from JosJuice/android-hardcoded-strings

Android: Clean up some hardcoded strings
This commit is contained in:
Mai M 2021-06-22 11:57:41 -04:00 committed by GitHub
commit a904cb846a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 71 additions and 57 deletions

View File

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

View File

@ -88,20 +88,8 @@ public final class GameRowPresenter extends Presenter
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;

View File

@ -90,7 +90,8 @@ public final class GameDetailsDialog extends DialogFragment
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())
{

View File

@ -96,7 +96,7 @@ public class GamePropertiesDialog extends DialogFragment
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();
}
@ -113,18 +113,20 @@ public class GamePropertiesDialog extends DialogFragment
{
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();
}
}

View File

@ -5,6 +5,7 @@ import android.text.TextUtils;
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;
@ -207,7 +208,7 @@ public class Settings implements Closeable
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())
{
@ -238,7 +239,10 @@ public class Settings implements Closeable
// 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());

View File

@ -170,7 +170,7 @@ public final class SettingsActivityPresenter
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;
}
}

View File

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

View File

@ -121,7 +121,7 @@ public final class SettingsFragmentPresenter
{
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<>();
@ -217,8 +217,7 @@ public final class SettingsFragmentPresenter
break;
default:
mView.showToastMessage("Unimplemented menu");
return;
throw new UnsupportedOperationException("Unimplemented menu");
}
mSettingsList = sl;

View File

@ -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;
private Uri appLinkIntentUri;
public HomeScreenChannel()
{
}
public HomeScreenChannel(String name, String description, String appLinkIntentUri)
public HomeScreenChannel(String name, String description, Uri appLinkIntentUri)
{
this.name = name;
this.description = description;
@ -52,12 +49,12 @@ public class HomeScreenChannel
this.description = description;
}
public String getAppLinkIntentUri()
public Uri getAppLinkIntentUri()
{
return appLinkIntentUri;
}
public void setAppLinkIntentUri(String appLinkIntentUri)
public void setAppLinkIntentUri(Uri appLinkIntentUri)
{
this.appLinkIntentUri = appLinkIntentUri;
}

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);
@ -111,7 +111,7 @@ public class SyncChannelJobService extends JobService
}
// 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)

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);
@ -388,8 +388,7 @@ public final class TvMainActivity extends FragmentActivity
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);
}

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)));
}
return subs;
}

View File

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