From 8309d0b6b70d2c08f07eca1d888ff8c4a59e021d Mon Sep 17 00:00:00 2001 From: A117870935 Date: Tue, 7 Jan 2025 20:43:43 +0530 Subject: [PATCH] Localization added for remote operation. Signed-off-by: A117870935 --- .../java/com/owncloud/android/AbstractIT.java | 3 +- .../operations/RemoteOperationResult.java | 101 ++++++++++++++++++ library/src/main/res/values/strings.xml | 27 +++++ .../lib/sampleclient/MainActivity.java | 3 +- 4 files changed, 132 insertions(+), 2 deletions(-) diff --git a/library/src/androidTest/java/com/owncloud/android/AbstractIT.java b/library/src/androidTest/java/com/owncloud/android/AbstractIT.java index 629747cce3..8e91093a2b 100644 --- a/library/src/androidTest/java/com/owncloud/android/AbstractIT.java +++ b/library/src/androidTest/java/com/owncloud/android/AbstractIT.java @@ -3,6 +3,7 @@ * * SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2018-2023 Tobias Kaminsky + * SPDX-FileCopyrightText: 2025 TSI-mc * SPDX-License-Identifier: MIT */ package com.owncloud.android; @@ -265,7 +266,7 @@ public void after() { private void removeOnClient(OwnCloudClient client) { RemoteOperationResult result = new ReadFolderRemoteOperation("/").execute(client); - assertTrue(result.getLogMessage(), result.isSuccess()); + assertTrue(result.getLogMessage(context), result.isSuccess()); for (Object object : result.getData()) { RemoteFile remoteFile = (RemoteFile) object; diff --git a/library/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationResult.java b/library/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationResult.java index 48453ee4f6..55014c1762 100644 --- a/library/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationResult.java +++ b/library/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationResult.java @@ -11,17 +11,22 @@ * SPDX-FileCopyrightText: 2014 Jorge Antonio Diaz-Benito Soriano * SPDX-FileCopyrightText: 2014-2016 Juan Carlos González Cabrero * SPDX-FileCopyrightText: 2014 jabarros + * SPDX-FileCopyrightText: 2025 TSI-mc * SPDX-License-Identifier: MIT */ package com.owncloud.android.lib.common.operations; import android.accounts.Account; import android.accounts.AccountsException; +import android.content.Context; import android.os.Build; import android.system.ErrnoException; import android.system.OsConstants; +import androidx.annotation.NonNull; + import com.nextcloud.common.OkHttpMethodBase; +import com.owncloud.android.lib.R; import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException; import com.owncloud.android.lib.common.network.CertificateCombinedException; import com.owncloud.android.lib.common.utils.Log_OC; @@ -576,6 +581,8 @@ private CertificateCombinedException getCertificateCombinedException(Exception e return result; } + // use getLogMessage(Context) + @Deprecated public String getLogMessage() { if (mException != null) { @@ -670,6 +677,100 @@ public String getLogMessage() { } + public String getLogMessage(@NonNull Context context) { + + if (mException != null) { + if (mException instanceof OperationCancelledException) { + return context.getString(R.string.operation_cancelled); + + } else if (mException instanceof SocketException) { + return context.getString(R.string.socket_exception); + + } else if (mException instanceof SocketTimeoutException) { + return context.getString(R.string.socket_timeout_exception); + + } else if (mException instanceof ConnectTimeoutException) { + return context.getString(R.string.connect_timeout_exception); + + } else if (mException instanceof MalformedURLException) { + return context.getString(R.string.malformed_url_exception); + + } else if (mException instanceof UnknownHostException) { + return context.getString(R.string.unknown_host_exception); + + } else if (mException instanceof CertificateCombinedException) { + if (((CertificateCombinedException) mException).isRecoverable()) { + return context.getString(R.string.ssl_recoverable_exception); + } else { + return context.getString(R.string.ssl_exception); + } + + } else if (mException instanceof SSLException) { + return context.getString(R.string.ssl_exception); + + } else if (mException instanceof DavException) { + return context.getString(R.string.unexpected_webdav_exception); + + } else if (mException instanceof HttpException) { + return context.getString(R.string.http_violation); + + } else if (mException instanceof IOException) { + return context.getString(R.string.unrecovered_transport_exception); + + } else if (mException instanceof AccountNotFoundException) { + Account failedAccount = ((AccountNotFoundException) mException).getFailedAccount(); + return mException.getMessage() + " (" + + (failedAccount != null ? failedAccount.name : "NULL") + ")"; + + } else if (mException instanceof AccountsException) { + return context.getString(R.string.exception_using_account); + + } else if (mException instanceof JSONException) { + return context.getString(R.string.json_exception); + + } else { + return context.getString(R.string.unexpected_exception); + } + } + + if (mCode == ResultCode.INSTANCE_NOT_CONFIGURED) { + return context.getString(R.string.instance_not_configured); + + } else if (mCode == ResultCode.NO_NETWORK_CONNECTION) { + return context.getString(R.string.no_network_connection); + + } else if (mCode == ResultCode.BAD_OC_VERSION) { + return context.getString(R.string.bad_oc_version); + + } else if (mCode == ResultCode.LOCAL_STORAGE_FULL) { + return context.getString(R.string.local_storage_full); + + } else if (mCode == ResultCode.LOCAL_STORAGE_NOT_MOVED) { + return context.getString(R.string.local_storage_not_moved); + + } else if (mCode == ResultCode.ACCOUNT_NOT_NEW) { + return context.getString(R.string.account_not_new); + + } else if (mCode == ResultCode.ACCOUNT_NOT_THE_SAME) { + return context.getString(R.string.account_not_the_same); + + } else if (mCode == ResultCode.INVALID_CHARACTER_IN_NAME) { + return context.getString(R.string.invalid_character_in_name); + + } else if (mCode == ResultCode.FILE_NOT_FOUND) { + return context.getString(R.string.file_not_found); + + } else if (mCode == ResultCode.SYNC_CONFLICT) { + return context.getString(R.string.sync_conflict); + + } else if (mCode == ResultCode.LOCKED) { + return context.getString(R.string.file_locked); + } + + return context.getString(R.string.operation_finished_http_code, mHttpCode, isSuccess() ? "success" : "fail"); + } + + public boolean isServerFail() { return (mHttpCode >= HttpStatus.SC_INTERNAL_SERVER_ERROR); } diff --git a/library/src/main/res/values/strings.xml b/library/src/main/res/values/strings.xml index a1f2ffdb82..932d699aba 100644 --- a/library/src/main/res/values/strings.xml +++ b/library/src/main/res/values/strings.xml @@ -4,6 +4,7 @@ ~ ~ SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors ~ SPDX-FileCopyrightText: 2015 ownCloud Inc. + ~ SPDX-FileCopyrightText: 2025 TSI-mc ~ SPDX-License-Identifier: MIT --> @@ -13,4 +14,30 @@ Select client certificate Select client certificate for %1$s:%2$d Operation cancelled by the caller + Operation cancelled by the caller + Socket exception + Socket timeout exception + Connect timeout exception + Malformed URL exception + Unknown host exception + SSL recoverable exception + SSL exception + Unexpected WebDAV exception + HTTP violation + Unrecovered transport exception + Exception while using account + JSON exception + Unexpected exception + The Nextcloud server is not configured! + No network connection + No valid Nextcloud version was found at the server + Local storage full + Error while moving file to final directory + Account already existing when creating a new one + Authenticated with a different account than the one updating + The file name contains a forbidden character + Local file does not exist + Synchronization conflict + File is currently locked by another user or process + Operation finished with HTTP status code %1$d (%2$s) diff --git a/sample_client/src/main/java/com/owncloud/android/lib/sampleclient/MainActivity.java b/sample_client/src/main/java/com/owncloud/android/lib/sampleclient/MainActivity.java index 6f2d367095..b5532b7965 100644 --- a/sample_client/src/main/java/com/owncloud/android/lib/sampleclient/MainActivity.java +++ b/sample_client/src/main/java/com/owncloud/android/lib/sampleclient/MainActivity.java @@ -5,6 +5,7 @@ * SPDX-FileCopyrightText: 2023 Tobias Kaminsky * SPDX-FileCopyrightText: 2015 ownCloud Inc. * SPDX-FileCopyrightText: 2015 David A. Velasco + * SPDX-FileCopyrightText: 2025 TSI-mc * SPDX-License-Identifier: MIT */ package com.owncloud.android.lib.sampleclient; @@ -195,7 +196,7 @@ private void startLocalDeletion() { public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) { if (!result.isSuccess()) { Toast.makeText(this, R.string.todo_operation_finished_in_fail, Toast.LENGTH_SHORT).show(); - Log.e(TAG, result.getLogMessage(), result.getException()); + Log.e(TAG, result.getLogMessage(this), result.getException()); } else if (operation instanceof ReadFolderRemoteOperation) { onSuccessfulRefresh((ReadFolderRemoteOperation) operation, result);