<string name="network_error_socket_exception">An error occurred while connecting with the server.</string>
<string name="network_error_socket_timeout_exception">An error occurred while waiting for the server, the operation couldn\'t have been done</string>
<string name="network_error_connect_timeout_exception">An error occurred while waiting for the server, the operation couldn\'t have been done</string>
- <string name="unexpected_exception">Unexpected exception</string>
+ <string name="network_host_not_available">The operation couldn\'t be completed, server is unavaliable</string>
</resources>
import com.owncloud.android.services.OperationsService;
import com.owncloud.android.services.OperationsService.OperationsServiceBinder;
import com.owncloud.android.ui.dialog.LoadingDialog;
+import com.owncloud.android.utils.ErrorMessageAdapter;
import com.owncloud.android.utils.Log_OC;
Intent sendIntent = operation.getSendIntent();
startActivity(sendIntent);
- } else if (result.getCode() == ResultCode.SHARE_NOT_FOUND) { // Error --> SHARE_NOT_FOUND
- Toast t = Toast.makeText(this, getString(R.string.share_link_file_no_exist), Toast.LENGTH_LONG);
- t.show();
- } else { // Generic error
- // Show a Message, operation finished without success
- Toast t = Toast.makeText(this, getString(R.string.share_link_file_error), Toast.LENGTH_LONG);
+ } else {
+ Toast t = Toast.makeText(this, ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
+ Toast.LENGTH_LONG);
t.show();
- }
+ }
}
if (result.isSuccess()){
updateFileFromDB();
- } else if (result.getCode() == ResultCode.SHARE_NOT_FOUND) { // Error --> SHARE_NOT_FOUND
- Toast t = Toast.makeText(this, getString(R.string.unshare_link_file_no_exist), Toast.LENGTH_LONG);
- t.show();
- } else { // Generic error
- // Show a Message, operation finished without success
- Toast t = Toast.makeText(this, getString(R.string.unshare_link_file_error), Toast.LENGTH_LONG);
+ } else {
+ Toast t = Toast.makeText(this, ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
+ Toast.LENGTH_LONG);
t.show();
- }
-
+ }
}
import com.owncloud.android.ui.preview.PreviewMediaFragment;
import com.owncloud.android.ui.preview.PreviewVideoActivity;
import com.owncloud.android.utils.DisplayUtils;
+import com.owncloud.android.utils.ErrorMessageAdapter;
import com.owncloud.android.utils.Log_OC;
*/
private void onRemoveFileOperationFinish(RemoveFileOperation operation, RemoteOperationResult result) {
dismissLoadingDialog();
+
+ Toast msg = Toast.makeText(this, ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
+ Toast.LENGTH_LONG);
+ msg.show();
+
if (result.isSuccess()) {
- Toast msg = Toast.makeText(this, R.string.remove_success_msg, Toast.LENGTH_LONG);
- msg.show();
OCFile removedFile = operation.getFile();
FileFragment second = getSecondFragment();
if (second != null && removedFile.equals(second.getFile())) {
}
invalidateOptionsMenu();
} else {
- Toast msg = Toast.makeText(this, R.string.remove_fail_msg, Toast.LENGTH_LONG);
- msg.show();
if (result.isSslRecoverableException()) {
mLastSslUntrustedServerResult = result;
showUntrustedCertDialog(mLastSslUntrustedServerResult);
refreshListOfFilesFragment();
} else {
dismissLoadingDialog();
- if (result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME) {
- Toast.makeText(FileDisplayActivity.this, R.string.filename_forbidden_characters, Toast.LENGTH_LONG).show();
- } else {
try {
- Toast msg = Toast.makeText(FileDisplayActivity.this, R.string.create_dir_fail_msg, Toast.LENGTH_LONG);
+ Toast msg = Toast.makeText(FileDisplayActivity.this,
+ ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
+ Toast.LENGTH_LONG);
msg.show();
} catch (NotFoundException e) {
Log_OC.e(TAG, "Error while trying to show fail message " , e);
}
- }
}
}
}
} else {
- if (result.getCode().equals(ResultCode.INVALID_LOCAL_FILE_NAME)) {
- Toast msg = Toast.makeText(this, R.string.rename_local_fail_msg, Toast.LENGTH_LONG);
- msg.show();
- // TODO throw again the new rename dialog
- } if (result.getCode().equals(ResultCode.INVALID_CHARACTER_IN_NAME)) {
- Toast msg = Toast.makeText(this, R.string.filename_forbidden_characters, Toast.LENGTH_LONG);
- msg.show();
- } else {
- Toast msg = Toast.makeText(this, R.string.rename_server_fail_msg, Toast.LENGTH_LONG);
- msg.show();
- if (result.isSslRecoverableException()) {
- mLastSslUntrustedServerResult = result;
- showUntrustedCertDialog(mLastSslUntrustedServerResult);
- }
+ Toast msg = Toast.makeText(this, ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
+ Toast.LENGTH_LONG);
+ msg.show();
+
+ if (result.isSslRecoverableException()) {
+ mLastSslUntrustedServerResult = result;
+ showUntrustedCertDialog(mLastSslUntrustedServerResult);
}
}
}
onTransferStateChanged(syncedFile, true, true);
} else {
- Toast msg = Toast.makeText(this, R.string.sync_file_nothing_to_do_msg, Toast.LENGTH_LONG);
+ Toast msg = Toast.makeText(this, ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
+ Toast.LENGTH_LONG);
msg.show();
}
}
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
+import com.owncloud.android.operations.CreateFolderOperation;
+import com.owncloud.android.operations.CreateShareOperation;
import com.owncloud.android.operations.DownloadFileOperation;
+import com.owncloud.android.operations.RemoveFileOperation;
+import com.owncloud.android.operations.RenameFileOperation;
+import com.owncloud.android.operations.SynchronizeFileOperation;
+import com.owncloud.android.operations.UnshareLinkOperation;
import com.owncloud.android.operations.UploadFileOperation;
/**
|| result.getCode() == ResultCode.LOCAL_STORAGE_NOT_COPIED) {
message = String.format(res.getString(R.string.error__upload__local_file_not_copied),
((UploadFileOperation) operation).getFileName());
+
} else if (result.getCode() == ResultCode.QUOTA_EXCEEDED) {
message = res.getString(R.string.failed_upload_quota_exceeded_text);
+
} else {
message = String.format(res.getString(R.string.uploader_upload_failed_content_single),
((UploadFileOperation) operation).getFileName());
if (result.isSuccess()) {
message = String.format(res.getString(R.string.downloader_download_succeeded_content),
new File(((DownloadFileOperation) operation).getSavePath()).getName());
+
} else {
message = String.format(res.getString(R.string.downloader_download_failed_content),
new File(((DownloadFileOperation) operation).getSavePath()).getName());
}
- }
+
+ } else if (operation instanceof RemoveFileOperation) {
+ if (result.isSuccess()) {
+ message = res.getString(R.string.remove_success_msg);
+
+ } else {
+ if (isNetworkError(result.getCode())) {
+ message = getErrorMessage(result, res);
+
+ } else {
+ message = res.getString(R.string.remove_fail_msg);
+ }
+ }
+
+ } else if (operation instanceof RenameFileOperation) {
+ if (result.getCode().equals(ResultCode.INVALID_LOCAL_FILE_NAME)) {
+ message = res.getString(R.string.rename_local_fail_msg);
+
+ } if (result.getCode().equals(ResultCode.INVALID_CHARACTER_IN_NAME)) {
+ message = res.getString(R.string.filename_forbidden_characters);
+
+ } else if (isNetworkError(result.getCode())) {
+ message = getErrorMessage(result, res);
+
+ } else {
+ message = res.getString(R.string.rename_server_fail_msg);
+ }
+
+ } else if (operation instanceof SynchronizeFileOperation) {
+ if (!((SynchronizeFileOperation) operation).transferWasRequested()) {
+ message = res.getString(R.string.sync_file_nothing_to_do_msg);
+ }
+
+ } else if (operation instanceof CreateFolderOperation) {
+ if (result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME) {
+ message = res.getString(R.string.filename_forbidden_characters);
+
+ } else if (isNetworkError(result.getCode())) {
+ message = getErrorMessage(result, res);
+
+ } else {
+ message = res.getString(R.string.create_dir_fail_msg);
+ }
+ } else if (operation instanceof CreateShareOperation) {
+ if (result.getCode() == ResultCode.SHARE_NOT_FOUND) { // Error --> SHARE_NOT_FOUND
+ message = res.getString(R.string.share_link_file_no_exist);
+
+ } else if (isNetworkError(result.getCode())) {
+ message = getErrorMessage(result, res);
+
+ } else { // Generic error
+ // Show a Message, operation finished without success
+ message = res.getString(R.string.share_link_file_error);
+ }
+
+ } else if (operation instanceof UnshareLinkOperation) {
+ if (result.getCode() == ResultCode.SHARE_NOT_FOUND) { // Error --> SHARE_NOT_FOUND
+ message = res.getString(R.string.unshare_link_file_no_exist);
+
+ } else if (isNetworkError(result.getCode())) {
+ message = getErrorMessage(result, res);
+
+ } else { // Generic error
+ // Show a Message, operation finished without success
+ message = res.getString(R.string.unshare_link_file_error);
+ }
+ }
return message;
}
- public static String getErrorMessage(RemoteOperationResult result , Resources res) {
+ private static String getErrorMessage(RemoteOperationResult result , Resources res) {
String message = null;
if (!result.isSuccess()) {
- switch (result.getCode()) {
- case WRONG_CONNECTION:
+ if (result.getCode() == ResultCode.WRONG_CONNECTION) {
+ message = res.getString(R.string.network_error_socket_exception);
+
+ } else if (result.getCode() == ResultCode.TIMEOUT) {
message = res.getString(R.string.network_error_socket_exception);
- break;
- case TIMEOUT:
if (result.getException() instanceof SocketTimeoutException) {
message = res.getString(R.string.network_error_socket_timeout_exception);
} else if(result.getException() instanceof ConnectTimeoutException) {
message = res.getString(R.string.network_error_connect_timeout_exception);
}
- break;
- default:
- message = res.getString(R.string.unexpected_exception);
- break;
+ } else if (result.getCode() == ResultCode.HOST_NOT_AVAILABLE) {
+ message = res.getString(R.string.network_host_not_available);
}
}
return message;
}
+
+ private static boolean isNetworkError(RemoteOperationResult.ResultCode code) {
+ if (code == ResultCode.WRONG_CONNECTION ||
+ code == ResultCode.TIMEOUT ||
+ code == ResultCode.HOST_NOT_AVAILABLE) {
+ return true;
+ }
+ else
+ return false;
+ }
}