Skip to content

Commit 8309d0b

Browse files
surinder-tsystobiasKaminsky
authored andcommitted
Localization added for remote operation.
Signed-off-by: A117870935 <surinder.kumar@t-systems.com>
1 parent fe2c9ff commit 8309d0b

4 files changed

Lines changed: 132 additions & 2 deletions

File tree

library/src/androidTest/java/com/owncloud/android/AbstractIT.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*
44
* SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors
55
* SPDX-FileCopyrightText: 2018-2023 Tobias Kaminsky <tobias@kaminsky.me>
6+
* SPDX-FileCopyrightText: 2025 TSI-mc <surinder.kumar@t-systems.com>
67
* SPDX-License-Identifier: MIT
78
*/
89
package com.owncloud.android;
@@ -265,7 +266,7 @@ public void after() {
265266

266267
private void removeOnClient(OwnCloudClient client) {
267268
RemoteOperationResult result = new ReadFolderRemoteOperation("/").execute(client);
268-
assertTrue(result.getLogMessage(), result.isSuccess());
269+
assertTrue(result.getLogMessage(context), result.isSuccess());
269270

270271
for (Object object : result.getData()) {
271272
RemoteFile remoteFile = (RemoteFile) object;

library/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationResult.java

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,22 @@
1111
* SPDX-FileCopyrightText: 2014 Jorge Antonio Diaz-Benito Soriano <jorge.diazbenitosoriano@gmail.com>
1212
* SPDX-FileCopyrightText: 2014-2016 Juan Carlos González Cabrero <malkomich@gmail.com>
1313
* SPDX-FileCopyrightText: 2014 jabarros <jabarros@solidgear.es>
14+
* SPDX-FileCopyrightText: 2025 TSI-mc <surinder.kumar@t-systems.com>
1415
* SPDX-License-Identifier: MIT
1516
*/
1617
package com.owncloud.android.lib.common.operations;
1718

1819
import android.accounts.Account;
1920
import android.accounts.AccountsException;
21+
import android.content.Context;
2022
import android.os.Build;
2123
import android.system.ErrnoException;
2224
import android.system.OsConstants;
2325

26+
import androidx.annotation.NonNull;
27+
2428
import com.nextcloud.common.OkHttpMethodBase;
29+
import com.owncloud.android.lib.R;
2530
import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;
2631
import com.owncloud.android.lib.common.network.CertificateCombinedException;
2732
import com.owncloud.android.lib.common.utils.Log_OC;
@@ -576,6 +581,8 @@ private CertificateCombinedException getCertificateCombinedException(Exception e
576581
return result;
577582
}
578583

584+
// use getLogMessage(Context)
585+
@Deprecated
579586
public String getLogMessage() {
580587

581588
if (mException != null) {
@@ -670,6 +677,100 @@ public String getLogMessage() {
670677

671678
}
672679

680+
public String getLogMessage(@NonNull Context context) {
681+
682+
if (mException != null) {
683+
if (mException instanceof OperationCancelledException) {
684+
return context.getString(R.string.operation_cancelled);
685+
686+
} else if (mException instanceof SocketException) {
687+
return context.getString(R.string.socket_exception);
688+
689+
} else if (mException instanceof SocketTimeoutException) {
690+
return context.getString(R.string.socket_timeout_exception);
691+
692+
} else if (mException instanceof ConnectTimeoutException) {
693+
return context.getString(R.string.connect_timeout_exception);
694+
695+
} else if (mException instanceof MalformedURLException) {
696+
return context.getString(R.string.malformed_url_exception);
697+
698+
} else if (mException instanceof UnknownHostException) {
699+
return context.getString(R.string.unknown_host_exception);
700+
701+
} else if (mException instanceof CertificateCombinedException) {
702+
if (((CertificateCombinedException) mException).isRecoverable()) {
703+
return context.getString(R.string.ssl_recoverable_exception);
704+
} else {
705+
return context.getString(R.string.ssl_exception);
706+
}
707+
708+
} else if (mException instanceof SSLException) {
709+
return context.getString(R.string.ssl_exception);
710+
711+
} else if (mException instanceof DavException) {
712+
return context.getString(R.string.unexpected_webdav_exception);
713+
714+
} else if (mException instanceof HttpException) {
715+
return context.getString(R.string.http_violation);
716+
717+
} else if (mException instanceof IOException) {
718+
return context.getString(R.string.unrecovered_transport_exception);
719+
720+
} else if (mException instanceof AccountNotFoundException) {
721+
Account failedAccount = ((AccountNotFoundException) mException).getFailedAccount();
722+
return mException.getMessage() + " (" +
723+
(failedAccount != null ? failedAccount.name : "NULL") + ")";
724+
725+
} else if (mException instanceof AccountsException) {
726+
return context.getString(R.string.exception_using_account);
727+
728+
} else if (mException instanceof JSONException) {
729+
return context.getString(R.string.json_exception);
730+
731+
} else {
732+
return context.getString(R.string.unexpected_exception);
733+
}
734+
}
735+
736+
if (mCode == ResultCode.INSTANCE_NOT_CONFIGURED) {
737+
return context.getString(R.string.instance_not_configured);
738+
739+
} else if (mCode == ResultCode.NO_NETWORK_CONNECTION) {
740+
return context.getString(R.string.no_network_connection);
741+
742+
} else if (mCode == ResultCode.BAD_OC_VERSION) {
743+
return context.getString(R.string.bad_oc_version);
744+
745+
} else if (mCode == ResultCode.LOCAL_STORAGE_FULL) {
746+
return context.getString(R.string.local_storage_full);
747+
748+
} else if (mCode == ResultCode.LOCAL_STORAGE_NOT_MOVED) {
749+
return context.getString(R.string.local_storage_not_moved);
750+
751+
} else if (mCode == ResultCode.ACCOUNT_NOT_NEW) {
752+
return context.getString(R.string.account_not_new);
753+
754+
} else if (mCode == ResultCode.ACCOUNT_NOT_THE_SAME) {
755+
return context.getString(R.string.account_not_the_same);
756+
757+
} else if (mCode == ResultCode.INVALID_CHARACTER_IN_NAME) {
758+
return context.getString(R.string.invalid_character_in_name);
759+
760+
} else if (mCode == ResultCode.FILE_NOT_FOUND) {
761+
return context.getString(R.string.file_not_found);
762+
763+
} else if (mCode == ResultCode.SYNC_CONFLICT) {
764+
return context.getString(R.string.sync_conflict);
765+
766+
} else if (mCode == ResultCode.LOCKED) {
767+
return context.getString(R.string.file_locked);
768+
}
769+
770+
return context.getString(R.string.operation_finished_http_code, mHttpCode, isSuccess() ? "success" : "fail");
771+
}
772+
773+
673774
public boolean isServerFail() {
674775
return (mHttpCode >= HttpStatus.SC_INTERNAL_SERVER_ERROR);
675776
}

library/src/main/res/values/strings.xml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
~
55
~ SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
66
~ SPDX-FileCopyrightText: 2015 ownCloud Inc.
7+
~ SPDX-FileCopyrightText: 2025 TSI-mc <surinder.kumar@t-systems.com>
78
~ SPDX-License-Identifier: MIT
89
-->
910
<resources>
@@ -13,4 +14,30 @@
1314
<string name="notification_title_select_client_cert">Select client certificate</string>
1415
<string name="notification_message_select_client_cert">Select client certificate for %1$s:%2$d</string>
1516
<string name="operation_cancelled_by_the_caller">Operation cancelled by the caller</string>
17+
<string name="operation_cancelled">Operation cancelled by the caller</string>
18+
<string name="socket_exception">Socket exception</string>
19+
<string name="socket_timeout_exception">Socket timeout exception</string>
20+
<string name="connect_timeout_exception">Connect timeout exception</string>
21+
<string name="malformed_url_exception">Malformed URL exception</string>
22+
<string name="unknown_host_exception">Unknown host exception</string>
23+
<string name="ssl_recoverable_exception">SSL recoverable exception</string>
24+
<string name="ssl_exception">SSL exception</string>
25+
<string name="unexpected_webdav_exception">Unexpected WebDAV exception</string>
26+
<string name="http_violation">HTTP violation</string>
27+
<string name="unrecovered_transport_exception">Unrecovered transport exception</string>
28+
<string name="exception_using_account">Exception while using account</string>
29+
<string name="json_exception">JSON exception</string>
30+
<string name="unexpected_exception">Unexpected exception</string>
31+
<string name="instance_not_configured">The Nextcloud server is not configured!</string>
32+
<string name="no_network_connection">No network connection</string>
33+
<string name="bad_oc_version">No valid Nextcloud version was found at the server</string>
34+
<string name="local_storage_full">Local storage full</string>
35+
<string name="local_storage_not_moved">Error while moving file to final directory</string>
36+
<string name="account_not_new">Account already existing when creating a new one</string>
37+
<string name="account_not_the_same">Authenticated with a different account than the one updating</string>
38+
<string name="invalid_character_in_name">The file name contains a forbidden character</string>
39+
<string name="file_not_found">Local file does not exist</string>
40+
<string name="sync_conflict">Synchronization conflict</string>
41+
<string name="file_locked">File is currently locked by another user or process</string>
42+
<string name="operation_finished_http_code">Operation finished with HTTP status code %1$d (%2$s)</string>
1643
</resources>

sample_client/src/main/java/com/owncloud/android/lib/sampleclient/MainActivity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* SPDX-FileCopyrightText: 2023 Tobias Kaminsky <tobias@kaminsky.me>
66
* SPDX-FileCopyrightText: 2015 ownCloud Inc.
77
* SPDX-FileCopyrightText: 2015 David A. Velasco <dvelasco@solidgear.es>
8+
* SPDX-FileCopyrightText: 2025 TSI-mc <surinder.kumar@t-systems.com>
89
* SPDX-License-Identifier: MIT
910
*/
1011
package com.owncloud.android.lib.sampleclient;
@@ -195,7 +196,7 @@ private void startLocalDeletion() {
195196
public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {
196197
if (!result.isSuccess()) {
197198
Toast.makeText(this, R.string.todo_operation_finished_in_fail, Toast.LENGTH_SHORT).show();
198-
Log.e(TAG, result.getLogMessage(), result.getException());
199+
Log.e(TAG, result.getLogMessage(this), result.getException());
199200

200201
} else if (operation instanceof ReadFolderRemoteOperation) {
201202
onSuccessfulRefresh((ReadFolderRemoteOperation) operation, result);

0 commit comments

Comments
 (0)