From eeb85545354076ce1308bfa3c018b2df4cca0adf Mon Sep 17 00:00:00 2001 From: agnostic-apollo Date: Wed, 24 Mar 2021 06:15:45 +0500 Subject: [PATCH] Fix string resources naming convention --- app/src/main/AndroidManifest.xml | 4 +- .../com/termux/app/RunCommandService.java | 8 +- .../java/com/termux/app/TermuxActivity.java | 30 ++-- .../termux/app/activities/ReportActivity.java | 2 +- .../app/terminal/TermuxSessionClient.java | 4 +- .../termux/app/terminal/TermuxViewClient.java | 10 +- .../java/com/termux/app/utils/FileUtils.java | 28 ++-- .../com/termux/app/utils/PluginUtils.java | 2 +- .../java/com/termux/app/utils/ShareUtils.java | 2 +- .../filepicker/TermuxDocumentsProvider.java | 4 +- .../TermuxFileReceiverActivity.java | 4 +- app/src/main/res/layout/activity_termux.xml | 4 +- app/src/main/res/menu/menu_report.xml | 4 +- app/src/main/res/values/strings.xml | 153 +++++++++++------- app/src/main/res/xml/shortcuts.xml | 4 +- 15 files changed, 149 insertions(+), 114 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e986f0c4..888d2694 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -15,9 +15,9 @@ diff --git a/app/src/main/java/com/termux/app/RunCommandService.java b/app/src/main/java/com/termux/app/RunCommandService.java index f8abb0a9..d91ed52c 100644 --- a/app/src/main/java/com/termux/app/RunCommandService.java +++ b/app/src/main/java/com/termux/app/RunCommandService.java @@ -186,13 +186,13 @@ public class RunCommandService extends Service { runStartForeground(); ExecutionCommand executionCommand = new ExecutionCommand(); - executionCommand.pluginAPIHelp = this.getString(R.string.run_command_service_api_help); + executionCommand.pluginAPIHelp = this.getString(R.string.error_run_command_service_api_help); String errmsg; // If invalid action passed, then just return if (!RUN_COMMAND_SERVICE.ACTION_RUN_COMMAND.equals(intent.getAction())) { - errmsg = this.getString(R.string.run_command_service_invalid_action, intent.getAction()); + errmsg = this.getString(R.string.error_run_command_service_invalid_intent_action, intent.getAction()); executionCommand.setStateFailed(1, errmsg, null); PluginUtils.processPluginExecutionCommandError(this, LOG_TAG, executionCommand); return Service.START_NOT_STICKY; @@ -227,7 +227,7 @@ public class RunCommandService extends Service { null, PluginUtils.PLUGIN_EXECUTABLE_FILE_PERMISSIONS, false, false); if (errmsg != null) { - errmsg += "\n" + this.getString(R.string.executable_absolute_path, executionCommand.executable); + errmsg += "\n" + this.getString(R.string.msg_executable_absolute_path, executionCommand.executable); executionCommand.setStateFailed(1, errmsg, null); PluginUtils.processPluginExecutionCommandError(this, LOG_TAG, executionCommand); return Service.START_NOT_STICKY; @@ -248,7 +248,7 @@ public class RunCommandService extends Service { true, true, false, true); if (errmsg != null) { - errmsg += "\n" + this.getString(R.string.working_directory_absolute_path, executionCommand.workingDirectory); + errmsg += "\n" + this.getString(R.string.msg_working_directory_absolute_path, executionCommand.workingDirectory); executionCommand.setStateFailed(1, errmsg, null); PluginUtils.processPluginExecutionCommandError(this, LOG_TAG, executionCommand); return Service.START_NOT_STICKY; diff --git a/app/src/main/java/com/termux/app/TermuxActivity.java b/app/src/main/java/com/termux/app/TermuxActivity.java index b87ba145..dd6f5058 100644 --- a/app/src/main/java/com/termux/app/TermuxActivity.java +++ b/app/src/main/java/com/termux/app/TermuxActivity.java @@ -395,8 +395,8 @@ public final class TermuxActivity extends Activity implements ServiceConnection View newSessionButton = findViewById(R.id.new_session_button); newSessionButton.setOnClickListener(v -> mTermuxSessionClient.addNewSession(false, null)); newSessionButton.setOnLongClickListener(v -> { - DialogUtils.textInput(TermuxActivity.this, R.string.session_new_named_title, null, R.string.session_new_named_positive_button, - text -> mTermuxSessionClient.addNewSession(false, text), R.string.new_session_failsafe, text -> mTermuxSessionClient.addNewSession(true, text) + DialogUtils.textInput(TermuxActivity.this, R.string.title_create_named_session, null, R.string.action_create_named_session_confirm, + text -> mTermuxSessionClient.addNewSession(false, text), R.string.action_new_session_failsafe, text -> mTermuxSessionClient.addNewSession(true, text) , -1, null, null); return true; }); @@ -489,15 +489,15 @@ public final class TermuxActivity extends Activity implements ServiceConnection } } - menu.add(Menu.NONE, CONTEXT_MENU_SELECT_URL_ID, Menu.NONE, R.string.select_url); - menu.add(Menu.NONE, CONTEXT_MENU_SHARE_TRANSCRIPT_ID, Menu.NONE, R.string.select_all_and_share); - if (addAutoFillMenu) menu.add(Menu.NONE, CONTEXT_MENU_AUTOFILL_ID, Menu.NONE, R.string.autofill_password); - menu.add(Menu.NONE, CONTEXT_MENU_RESET_TERMINAL_ID, Menu.NONE, R.string.reset_terminal); - menu.add(Menu.NONE, CONTEXT_MENU_KILL_PROCESS_ID, Menu.NONE, getResources().getString(R.string.kill_process, getCurrentSession().getPid())).setEnabled(currentSession.isRunning()); - menu.add(Menu.NONE, CONTEXT_MENU_STYLING_ID, Menu.NONE, R.string.style_terminal); - menu.add(Menu.NONE, CONTEXT_MENU_TOGGLE_KEEP_SCREEN_ON, Menu.NONE, R.string.toggle_keep_screen_on).setCheckable(true).setChecked(mPreferences.getKeepScreenOn()); - menu.add(Menu.NONE, CONTEXT_MENU_HELP_ID, Menu.NONE, R.string.help); - menu.add(Menu.NONE, CONTEXT_MENU_SETTINGS_ID, Menu.NONE, R.string.settings); + menu.add(Menu.NONE, CONTEXT_MENU_SELECT_URL_ID, Menu.NONE, R.string.action_select_url); + menu.add(Menu.NONE, CONTEXT_MENU_SHARE_TRANSCRIPT_ID, Menu.NONE, R.string.action_share_transcript); + if (addAutoFillMenu) menu.add(Menu.NONE, CONTEXT_MENU_AUTOFILL_ID, Menu.NONE, R.string.action_autofill_password); + menu.add(Menu.NONE, CONTEXT_MENU_RESET_TERMINAL_ID, Menu.NONE, R.string.action_reset_terminal); + menu.add(Menu.NONE, CONTEXT_MENU_KILL_PROCESS_ID, Menu.NONE, getResources().getString(R.string.action_kill_process, getCurrentSession().getPid())).setEnabled(currentSession.isRunning()); + menu.add(Menu.NONE, CONTEXT_MENU_STYLING_ID, Menu.NONE, R.string.action_style_terminal); + menu.add(Menu.NONE, CONTEXT_MENU_TOGGLE_KEEP_SCREEN_ON, Menu.NONE, R.string.action_toggle_keep_screen_on).setCheckable(true).setChecked(mPreferences.getKeepScreenOn()); + menu.add(Menu.NONE, CONTEXT_MENU_HELP_ID, Menu.NONE, R.string.action_open_help); + menu.add(Menu.NONE, CONTEXT_MENU_SETTINGS_ID, Menu.NONE, R.string.action_open_settings); } /** Hook system menu to show context menu instead. */ @@ -552,7 +552,7 @@ public final class TermuxActivity extends Activity implements ServiceConnection final AlertDialog.Builder b = new AlertDialog.Builder(this); b.setIcon(android.R.drawable.ic_dialog_alert); - b.setMessage(R.string.confirm_kill_process); + b.setMessage(R.string.title_confirm_kill_process); b.setPositiveButton(android.R.string.yes, (dialog, id) -> { dialog.dismiss(); session.finishIfRunning(); @@ -564,7 +564,7 @@ public final class TermuxActivity extends Activity implements ServiceConnection private void resetSession(TerminalSession session) { if (session != null) { session.reset(); - showToast(getResources().getString(R.string.reset_toast_notification), true); + showToast(getResources().getString(R.string.msg_terminal_reset), true); } } @@ -576,8 +576,8 @@ public final class TermuxActivity extends Activity implements ServiceConnection } catch (ActivityNotFoundException | IllegalArgumentException e) { // The startActivity() call is not documented to throw IllegalArgumentException. // However, crash reporting shows that it sometimes does, so catch it here. - new AlertDialog.Builder(this).setMessage(getString(R.string.styling_not_installed)) - .setPositiveButton(R.string.styling_install, (dialog, which) -> startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://f-droid.org/en/packages/" + TermuxConstants.TERMUX_STYLING_PACKAGE_NAME + " /")))).setNegativeButton(android.R.string.cancel, null).show(); + new AlertDialog.Builder(this).setMessage(getString(R.string.error_styling_not_installed)) + .setPositiveButton(R.string.action_styling_install, (dialog, which) -> startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://f-droid.org/en/packages/" + TermuxConstants.TERMUX_STYLING_PACKAGE_NAME + " /")))).setNegativeButton(android.R.string.cancel, null).show(); } } private void toggleKeepScreenOn() { diff --git a/app/src/main/java/com/termux/app/activities/ReportActivity.java b/app/src/main/java/com/termux/app/activities/ReportActivity.java index 5b033b56..cf4ccdd3 100644 --- a/app/src/main/java/com/termux/app/activities/ReportActivity.java +++ b/app/src/main/java/com/termux/app/activities/ReportActivity.java @@ -129,7 +129,7 @@ public class ReportActivity extends AppCompatActivity { int id = item.getItemId(); if (id == R.id.menu_item_share_report) { if (mReportInfo != null) - ShareUtils.shareText(this, getString(R.string.report_text), mReportInfo.reportString); + ShareUtils.shareText(this, getString(R.string.title_report_text), mReportInfo.reportString); } else if (id == R.id.menu_item_copy_report) { if (mReportInfo != null) ShareUtils.copyTextToClipboard(this, mReportInfo.reportString, null); diff --git a/app/src/main/java/com/termux/app/terminal/TermuxSessionClient.java b/app/src/main/java/com/termux/app/terminal/TermuxSessionClient.java index 4229cc91..c3e4df7f 100644 --- a/app/src/main/java/com/termux/app/terminal/TermuxSessionClient.java +++ b/app/src/main/java/com/termux/app/terminal/TermuxSessionClient.java @@ -176,7 +176,7 @@ public class TermuxSessionClient extends TermuxSessionClientBase { public void renameSession(final TerminalSession sessionToRename) { if (sessionToRename == null) return; - DialogUtils.textInput(mActivity, R.string.session_rename_title, sessionToRename.mSessionName, R.string.session_rename_positive_button, text -> { + DialogUtils.textInput(mActivity, R.string.title_rename_session, sessionToRename.mSessionName, R.string.action_rename_session_confirm, text -> { sessionToRename.mSessionName = text; terminalSessionListNotifyUpdated(); }, -1, null, -1, null, null); @@ -184,7 +184,7 @@ public class TermuxSessionClient extends TermuxSessionClientBase { public void addNewSession(boolean isFailSafe, String sessionName) { if (mActivity.getTermuxService().getSessions().size() >= MAX_SESSIONS) { - new AlertDialog.Builder(mActivity).setTitle(R.string.max_terminals_reached_title).setMessage(R.string.max_terminals_reached_message) + new AlertDialog.Builder(mActivity).setTitle(R.string.title_max_terminals_reached).setMessage(R.string.msg_max_terminals_reached) .setPositiveButton(android.R.string.ok, null).show(); } else { TerminalSession currentSession = mActivity.getCurrentSession(); diff --git a/app/src/main/java/com/termux/app/terminal/TermuxViewClient.java b/app/src/main/java/com/termux/app/terminal/TermuxViewClient.java index 6f3e29cb..98d5d146 100644 --- a/app/src/main/java/com/termux/app/terminal/TermuxViewClient.java +++ b/app/src/main/java/com/termux/app/terminal/TermuxViewClient.java @@ -346,8 +346,8 @@ public class TermuxViewClient implements TerminalViewClient { intent.setType("text/plain"); transcriptText = TextDataUtils.getTruncatedCommandOutput(transcriptText, 100_000); intent.putExtra(Intent.EXTRA_TEXT, transcriptText); - intent.putExtra(Intent.EXTRA_SUBJECT, mActivity.getString(R.string.share_transcript_title)); - mActivity.startActivity(Intent.createChooser(intent, mActivity.getString(R.string.share_transcript_chooser_title))); + intent.putExtra(Intent.EXTRA_SUBJECT, mActivity.getString(R.string.title_share_transcript)); + mActivity.startActivity(Intent.createChooser(intent, mActivity.getString(R.string.title_share_transcript_with))); } catch (Exception e) { Logger.logStackTraceWithMessage("Failed to get share session transcript of length " + transcriptText.length(), e); } @@ -361,7 +361,7 @@ public class TermuxViewClient implements TerminalViewClient { LinkedHashSet urlSet = TextDataUtils.extractUrls(text); if (urlSet.isEmpty()) { - new AlertDialog.Builder(mActivity).setMessage(R.string.select_url_no_found).show(); + new AlertDialog.Builder(mActivity).setMessage(R.string.title_select_url_none_found).show(); return; } @@ -373,8 +373,8 @@ public class TermuxViewClient implements TerminalViewClient { String url = (String) urls[which]; ClipboardManager clipboard = (ClipboardManager) mActivity.getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setPrimaryClip(new ClipData(null, new String[]{"text/plain"}, new ClipData.Item(url))); - Toast.makeText(mActivity, R.string.select_url_copied_to_clipboard, Toast.LENGTH_LONG).show(); - }).setTitle(R.string.select_url_dialog_title).create(); + Toast.makeText(mActivity, R.string.msg_select_url_copied_to_clipboard, Toast.LENGTH_LONG).show(); + }).setTitle(R.string.title_select_url_dialog).create(); // Long press to open URL: dialog.setOnShowListener(di -> { diff --git a/app/src/main/java/com/termux/app/utils/FileUtils.java b/app/src/main/java/com/termux/app/utils/FileUtils.java index f50ea91c..194e37f9 100644 --- a/app/src/main/java/com/termux/app/utils/FileUtils.java +++ b/app/src/main/java/com/termux/app/utils/FileUtils.java @@ -156,14 +156,14 @@ public class FileUtils { * failed, otherwise {@code null}. */ public static String validateRegularFileExistenceAndPermissions(final Context context, final String path, final String parentDirPath, String permissionsToCheck, final boolean setMissingPermissions, final boolean ignoreErrorsIfPathIsUnderParentDirPath) { - if (path == null || path.isEmpty()) return context.getString(R.string.null_or_empty_file); + if (path == null || path.isEmpty()) return context.getString(R.string.error_null_or_empty_file); try { File file = new File(path); // If file exits but not a regular file if (file.exists() && !file.isFile()) { - return context.getString(R.string.non_regular_file_found); + return context.getString(R.string.error_non_regular_file_found); } boolean isPathUnderParentDirPath = false; @@ -183,7 +183,7 @@ public class FileUtils { // If path is not a regular file // Regular files cannot be automatically created so we do not ignore if missing if (!file.isFile()) { - return context.getString(R.string.no_regular_file_found); + return context.getString(R.string.error_no_regular_file_found); } // If there is not parentDirPath restriction or path is not under parentDirPath or @@ -197,7 +197,7 @@ public class FileUtils { } // Some function calls may throw SecurityException, etc catch (Exception e) { - return context.getString(R.string.validate_file_existence_and_permissions_failed_with_exception, path, e.getMessage()); + return context.getString(R.string.error_validate_file_existence_and_permissions_failed_with_exception, path, e.getMessage()); } return null; @@ -230,14 +230,14 @@ public class FileUtils { * failed, otherwise {@code null}. */ public static String validateDirectoryExistenceAndPermissions(final Context context, final String path, final String parentDirPath, String permissionsToCheck, final boolean createDirectoryIfMissing, final boolean setMissingPermissions, final boolean ignoreErrorsIfPathIsInParentDirPath, final boolean ignoreIfNotExecutable) { - if (path == null || path.isEmpty()) return context.getString(R.string.null_or_empty_directory); + if (path == null || path.isEmpty()) return context.getString(R.string.error_null_or_empty_directory); try { File file = new File(path); // If file exits but not a directory file if (file.exists() && !file.isDirectory()) { - return context.getString(R.string.non_directory_file_found); + return context.getString(R.string.error_non_directory_file_found); } boolean isPathInParentDirPath = false; @@ -254,7 +254,7 @@ public class FileUtils { Logger.logVerbose(LOG_TAG, "Creating missing directory at path: \"" + path + "\""); // If failed to create directory if (!file.mkdirs()) { - return context.getString(R.string.creating_missing_directory_failed, path); + return context.getString(R.string.error_creating_missing_directory_failed, path); } } @@ -271,7 +271,7 @@ public class FileUtils { // If path is not a directory // Directories can be automatically created so we can ignore if missing with above check if (!file.isDirectory()) { - return context.getString(R.string.no_directory_found); + return context.getString(R.string.error_no_directory_found); } if (permissionsToCheck != null) { @@ -282,7 +282,7 @@ public class FileUtils { } // Some function calls may throw SecurityException, etc catch (Exception e) { - return context.getString(R.string.validate_directory_existence_and_permissions_failed_with_exception, path, e.getMessage()); + return context.getString(R.string.error_validate_directory_existence_and_permissions_failed_with_exception, path, e.getMessage()); } return null; @@ -332,11 +332,11 @@ public class FileUtils { * @return Returns the {@code errmsg} if validating permissions failed, otherwise {@code null}. */ public static String checkMissingFilePermissions(Context context, String path, String permissionsToCheck, String fileType, boolean ignoreIfNotExecutable) { - if (path == null || path.isEmpty()) return context.getString(R.string.null_or_empty_path); + if (path == null || path.isEmpty()) return context.getString(R.string.error_null_or_empty_path); if (!isValidPermissingString(permissionsToCheck)) { Logger.logError(LOG_TAG, "Invalid permissionsToCheck passed to checkMissingFilePermissions: \"" + permissionsToCheck + "\""); - return context.getString(R.string.invalid_file_permissions_string_to_check); + return context.getString(R.string.error_invalid_file_permissions_string_to_check); } if (fileType == null || fileType.isEmpty()) fileType = "File"; @@ -345,17 +345,17 @@ public class FileUtils { // If file is not readable if (permissionsToCheck.contains("r") && !file.canRead()) { - return context.getString(R.string.file_not_readable, fileType); + return context.getString(R.string.error_file_not_readable, fileType); } // If file is not writable if (permissionsToCheck.contains("w") && !file.canWrite()) { - return context.getString(R.string.file_not_writable, fileType); + return context.getString(R.string.error_file_not_writable, fileType); } // If file is not executable // This canExecute() will give "avc: granted { execute }" warnings for target sdk 29 else if (permissionsToCheck.contains("x") && !file.canExecute() && !ignoreIfNotExecutable) { - return context.getString(R.string.file_not_executable, fileType); + return context.getString(R.string.error_file_not_executable, fileType); } return null; diff --git a/app/src/main/java/com/termux/app/utils/PluginUtils.java b/app/src/main/java/com/termux/app/utils/PluginUtils.java index 0fd2a7e9..387c1560 100644 --- a/app/src/main/java/com/termux/app/utils/PluginUtils.java +++ b/app/src/main/java/com/termux/app/utils/PluginUtils.java @@ -96,7 +96,7 @@ public class PluginUtils { public static String checkIfRunCommandServiceAllowExternalAppsPolicyIsViolated(final Context context) { String errmsg = null; if (!SharedProperties.isPropertyValueTrue(context, TermuxPropertyConstants.getTermuxPropertiesFile(), TermuxConstants.PROP_ALLOW_EXTERNAL_APPS)) { - errmsg = context.getString(R.string.run_command_service_allow_external_apps_ungranted_warning); + errmsg = context.getString(R.string.error_run_command_service_allow_external_apps_ungranted); } return errmsg; diff --git a/app/src/main/java/com/termux/app/utils/ShareUtils.java b/app/src/main/java/com/termux/app/utils/ShareUtils.java index 4f8b628e..07b961cd 100644 --- a/app/src/main/java/com/termux/app/utils/ShareUtils.java +++ b/app/src/main/java/com/termux/app/utils/ShareUtils.java @@ -43,7 +43,7 @@ public class ShareUtils { shareTextIntent.putExtra(Intent.EXTRA_SUBJECT, subject); shareTextIntent.putExtra(Intent.EXTRA_TEXT, text); - openSystemAppChooser(context, shareTextIntent, context.getString(R.string.share_with)); + openSystemAppChooser(context, shareTextIntent, context.getString(R.string.title_share_with)); } /** diff --git a/app/src/main/java/com/termux/filepicker/TermuxDocumentsProvider.java b/app/src/main/java/com/termux/filepicker/TermuxDocumentsProvider.java index 3bb14334..0a4de74f 100644 --- a/app/src/main/java/com/termux/filepicker/TermuxDocumentsProvider.java +++ b/app/src/main/java/com/termux/filepicker/TermuxDocumentsProvider.java @@ -22,7 +22,7 @@ import java.util.LinkedList; /** * A document provider for the Storage Access Framework which exposes the files in the - * $HOME/ folder to other apps. + * $HOME/ directory to other apps. *

* Note that this replaces providing an activity matching the ACTION_GET_CONTENT intent: *

@@ -167,7 +167,7 @@ public class TermuxDocumentsProvider extends DocumentsProvider { final int MAX_SEARCH_RESULTS = 50; while (!pending.isEmpty() && result.getCount() < MAX_SEARCH_RESULTS) { final File file = pending.removeFirst(); - // Avoid folders outside the $HOME folders linked in to symlinks (to avoid e.g. search + // Avoid directories outside the $HOME directory linked with symlinks (to avoid e.g. search // through the whole SD card). boolean isInsideHome; try { diff --git a/app/src/main/java/com/termux/filepicker/TermuxFileReceiverActivity.java b/app/src/main/java/com/termux/filepicker/TermuxFileReceiverActivity.java index 94194f27..8a279fca 100644 --- a/app/src/main/java/com/termux/filepicker/TermuxFileReceiverActivity.java +++ b/app/src/main/java/com/termux/filepicker/TermuxFileReceiverActivity.java @@ -118,7 +118,7 @@ public class TermuxFileReceiverActivity extends Activity { } void promptNameAndSave(final InputStream in, final String attachmentFileName) { - DialogUtils.textInput(this, R.string.file_received_title, attachmentFileName, R.string.file_received_edit_button, text -> { + DialogUtils.textInput(this, R.string.title_file_received, attachmentFileName, R.string.action_file_received_edit, text -> { File outFile = saveStreamWithName(in, text); if (outFile == null) return; @@ -141,7 +141,7 @@ public class TermuxFileReceiverActivity extends Activity { startService(executeIntent); finish(); }, - R.string.file_received_open_folder_button, text -> { + R.string.action_file_received_open_directory, text -> { if (saveStreamWithName(in, text) == null) return; Intent executeIntent = new Intent(TERMUX_SERVICE.ACTION_SERVICE_EXECUTE); diff --git a/app/src/main/res/layout/activity_termux.xml b/app/src/main/res/layout/activity_termux.xml index 2faa7d31..604d17b4 100644 --- a/app/src/main/res/layout/activity_termux.xml +++ b/app/src/main/res/layout/activity_termux.xml @@ -56,7 +56,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" - android:text="@string/toggle_soft_keyboard" /> + android:text="@string/action_toggle_soft_keyboard" />