Skip to content

Commit

Permalink
Fix string resources naming convention
Browse files Browse the repository at this point in the history
  • Loading branch information
agnostic-apollo committed Mar 24, 2021
1 parent 4eced52 commit eeb8554
Show file tree
Hide file tree
Showing 15 changed files with 152 additions and 117 deletions.
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

<permission
android:name="${TERMUX_PACKAGE_NAME}.permission.RUN_COMMAND"
android:description="@string/run_command_permission_description"
android:description="@string/permission_run_command_description"
android:icon="@mipmap/ic_launcher"
android:label="@string/run_command_permission_label"
android:label="@string/permission_run_command_label"
android:protectionLevel="dangerous" />

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/com/termux/app/RunCommandService.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,13 @@ public int onStartCommand(Intent intent, int flags, int startId) {
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;
Expand Down Expand Up @@ -227,7 +227,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
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;
Expand All @@ -248,7 +248,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
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;
Expand Down
30 changes: 15 additions & 15 deletions app/src/main/java/com/termux/app/TermuxActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,8 @@ private void setNewSessionButtonView() {
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;
});
Expand Down Expand Up @@ -489,15 +489,15 @@ public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuIn
}
}

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. */
Expand Down Expand Up @@ -552,7 +552,7 @@ private void showKillSessionDialog(TerminalSession session) {

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();
Expand All @@ -564,7 +564,7 @@ private void showKillSessionDialog(TerminalSession session) {
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);
}
}

Expand All @@ -576,8 +576,8 @@ private void showStylingDialog() {
} 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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public boolean onOptionsItemSelected(final MenuItem item) {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,15 @@ public void switchToSession(boolean forward) {
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);
}

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();
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/com/termux/app/terminal/TermuxViewClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,8 @@ public void shareSessionTranscript() {
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);
}
Expand All @@ -361,7 +361,7 @@ public void showUrlSelection() {

LinkedHashSet<CharSequence> 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;
}

Expand All @@ -373,8 +373,8 @@ public void showUrlSelection() {
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 -> {
Expand Down
28 changes: 14 additions & 14 deletions app/src/main/java/com/termux/app/utils/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,14 @@ public static boolean isPathInDirPath(String path, String dirPath, boolean ensur
* 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;
Expand All @@ -183,7 +183,7 @@ public static String validateRegularFileExistenceAndPermissions(final Context co
// 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
Expand All @@ -197,7 +197,7 @@ public static String validateRegularFileExistenceAndPermissions(final Context co
}
// 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;
Expand Down Expand Up @@ -230,14 +230,14 @@ public static String validateRegularFileExistenceAndPermissions(final Context co
* 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;
Expand All @@ -254,7 +254,7 @@ public static String validateDirectoryExistenceAndPermissions(final Context cont
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);
}
}

Expand All @@ -271,7 +271,7 @@ public static String validateDirectoryExistenceAndPermissions(final Context cont
// 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) {
Expand All @@ -282,7 +282,7 @@ public static String validateDirectoryExistenceAndPermissions(final Context cont
}
// 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;
Expand Down Expand Up @@ -332,11 +332,11 @@ public static void setMissingFilePermissions(String path, String permissionsToSe
* @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";
Expand All @@ -345,17 +345,17 @@ public static String checkMissingFilePermissions(Context context, String path, S

// 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;
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/termux/app/utils/PluginUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public static void sendExecuteResultToResultsService(final Context context, fina
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;
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/termux/app/utils/ShareUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static void shareText(final Context context, final String subject, final
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));
}

/**
Expand Down
Loading

0 comments on commit eeb8554

Please sign in to comment.