X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/bcab40c5351fdb50230cfbebfd110b889f32e141..6b84d83b3544f8de4e56186f6ecbccd3d612702b:/src/com/owncloud/android/utils/ErrorMessageAdapter.java diff --git a/src/com/owncloud/android/utils/ErrorMessageAdapter.java b/src/com/owncloud/android/utils/ErrorMessageAdapter.java index c5bda8ce..75736e53 100644 --- a/src/com/owncloud/android/utils/ErrorMessageAdapter.java +++ b/src/com/owncloud/android/utils/ErrorMessageAdapter.java @@ -1,4 +1,7 @@ -/* ownCloud Android client application +/** + * ownCloud Android client application + * + * @author masensio * Copyright (C) 2014 ownCloud Inc. * * This program is free software: you can redistribute it and/or modify @@ -20,7 +23,9 @@ package com.owncloud.android.utils; import java.io.File; import java.net.SocketTimeoutException; + import org.apache.commons.httpclient.ConnectTimeoutException; + import android.content.res.Resources; import com.owncloud.android.R; @@ -30,17 +35,17 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCo import com.owncloud.android.operations.CreateFolderOperation; import com.owncloud.android.operations.CreateShareOperation; import com.owncloud.android.operations.DownloadFileOperation; +import com.owncloud.android.operations.MoveFileOperation; import com.owncloud.android.operations.RemoveFileOperation; import com.owncloud.android.operations.RenameFileOperation; import com.owncloud.android.operations.SynchronizeFileOperation; +import com.owncloud.android.operations.SynchronizeFolderOperation; import com.owncloud.android.operations.UnshareLinkOperation; import com.owncloud.android.operations.UploadFileOperation; /** - * Class to choose proper error messages to show to the user depending on the results of operations, always following the same policy - * - * @author masensio - * + * Class to choose proper error messages to show to the user depending on the results of operations, + * always following the same policy */ public class ErrorMessageAdapter { @@ -49,26 +54,39 @@ public class ErrorMessageAdapter { } - public static String getErrorCauseMessage(RemoteOperationResult result, RemoteOperation operation, Resources res) { + public static String getErrorCauseMessage(RemoteOperationResult result, + RemoteOperation operation, Resources res) { String message = null; if (operation instanceof UploadFileOperation) { if (result.isSuccess()) { - message = String.format(res.getString(R.string.uploader_upload_succeeded_content_single), + message = String.format( + res.getString(R.string.uploader_upload_succeeded_content_single), ((UploadFileOperation) operation).getFileName()); } else { if (result.getCode() == ResultCode.LOCAL_STORAGE_FULL || result.getCode() == ResultCode.LOCAL_STORAGE_NOT_COPIED) { - message = String.format(res.getString(R.string.error__upload__local_file_not_copied), - ((UploadFileOperation) operation).getFileName()); - + message = String.format( + res.getString(R.string.error__upload__local_file_not_copied), + ((UploadFileOperation) operation).getFileName(), + res.getString(R.string.app_name)); + /* } else if (result.getCode() == ResultCode.QUOTA_EXCEEDED) { message = res.getString(R.string.failed_upload_quota_exceeded_text); + */ + } else if (result.getCode() == ResultCode.FORBIDDEN) { + message = String.format(res.getString(R.string.forbidden_permissions), + res.getString(R.string.uploader_upload_forbidden_permissions)); + + } else if (result.getCode() == ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER) { + message = res.getString(R.string.filename_forbidden_charaters_from_server); + } else { - message = String.format(res.getString(R.string.uploader_upload_failed_content_single), + message = String.format( + res.getString(R.string.uploader_upload_failed_content_single), ((UploadFileOperation) operation).getFileName()); } } @@ -76,12 +94,19 @@ public class ErrorMessageAdapter { } else if (operation instanceof DownloadFileOperation) { if (result.isSuccess()) { - message = String.format(res.getString(R.string.downloader_download_succeeded_content), + 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()); + if (result.getCode() == ResultCode.FILE_NOT_FOUND) { + message = res.getString(R.string.downloader_download_file_not_found); + + } else { + message = String.format( + res.getString(R.string.downloader_download_failed_content), new File( + ((DownloadFileOperation) operation).getSavePath()).getName()); + } } } else if (operation instanceof RemoveFileOperation) { @@ -89,7 +114,11 @@ public class ErrorMessageAdapter { message = res.getString(R.string.remove_success_msg); } else { - if (isNetworkError(result.getCode())) { + if (result.getCode().equals(ResultCode.FORBIDDEN)) { + // Error --> No permissions + message = String.format(res.getString(R.string.forbidden_permissions), + res.getString(R.string.forbidden_permissions_delete)); + } else if (isNetworkError(result.getCode())) { message = getErrorMessage(result, res); } else { @@ -100,13 +129,21 @@ public class ErrorMessageAdapter { } 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)) { + + } else if (result.getCode().equals(ResultCode.FORBIDDEN)) { + // Error --> No permissions + message = String.format(res.getString(R.string.forbidden_permissions), + res.getString(R.string.forbidden_permissions_rename)); + + } else 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 if (result.getCode() == ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER) { + message = res.getString(R.string.filename_forbidden_charaters_from_server); + } else { message = res.getString(R.string.rename_server_fail_msg); } @@ -119,17 +156,28 @@ public class ErrorMessageAdapter { } else if (operation instanceof CreateFolderOperation) { if (result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME) { message = res.getString(R.string.filename_forbidden_characters); - + + } else if (result.getCode().equals(ResultCode.FORBIDDEN)) { + message = String.format(res.getString(R.string.forbidden_permissions), + res.getString(R.string.forbidden_permissions_create)); + } else if (isNetworkError(result.getCode())) { message = getErrorMessage(result, res); + } else if (result.getCode() == ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER) { + message = res.getString(R.string.filename_forbidden_charaters_from_server); } 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 + if (result.getCode() == ResultCode.SHARE_NOT_FOUND) { // Error --> SHARE_NOT_FOUND message = res.getString(R.string.share_link_file_no_exist); + } else if (result.getCode() == ResultCode.SHARE_FORBIDDEN) { + // Error --> No permissions + message = String.format(res.getString(R.string.forbidden_permissions), + res.getString(R.string.share_link_forbidden_permissions)); + } else if (isNetworkError(result.getCode())) { message = getErrorMessage(result, res); @@ -140,9 +188,14 @@ public class ErrorMessageAdapter { } else if (operation instanceof UnshareLinkOperation) { - if (result.getCode() == ResultCode.SHARE_NOT_FOUND) { // Error --> SHARE_NOT_FOUND + if (result.getCode() == ResultCode.SHARE_NOT_FOUND) { // Error --> SHARE_NOT_FOUND message = res.getString(R.string.unshare_link_file_no_exist); + } else if (result.getCode() == ResultCode.SHARE_FORBIDDEN) { + // Error --> No permissions + message = String.format(res.getString(R.string.forbidden_permissions), + res.getString(R.string.unshare_link_forbidden_permissions)); + } else if (isNetworkError(result.getCode())) { message = getErrorMessage(result, res); @@ -150,6 +203,43 @@ public class ErrorMessageAdapter { // Show a Message, operation finished without success message = res.getString(R.string.unshare_link_file_error); } + } else if (operation instanceof MoveFileOperation) { + + if (result.getCode() == ResultCode.FILE_NOT_FOUND) { + message = res.getString(R.string.move_file_not_found); + + } else if (result.getCode() == ResultCode.INVALID_MOVE_INTO_DESCENDANT) { + message = res.getString(R.string.move_file_invalid_into_descendent); + + } else if (result.getCode() == ResultCode.INVALID_OVERWRITE) { + message = res.getString(R.string.move_file_invalid_overwrite); + + } else if (result.getCode() == ResultCode.FORBIDDEN) { + message = String.format(res.getString(R.string.forbidden_permissions), + res.getString(R.string.forbidden_permissions_move)); + + } else if (result.getCode() == ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER) { + message = res.getString(R.string.filename_forbidden_charaters_from_server); + + } else { // Generic error + // Show a Message, operation finished without success + message = res.getString(R.string.move_file_error); + } + } else if (operation instanceof SynchronizeFolderOperation) { + + if (!result.isSuccess()) { + String folderPathName = new File( + ((SynchronizeFolderOperation) operation).getFolderPath()).getName(); + if (result.getCode() == ResultCode.FILE_NOT_FOUND) { + message = String.format(res.getString(R.string.sync_current_folder_was_removed), + folderPathName); + + } else { // Generic error + // Show a Message, operation finished without success + message = String.format(res.getString(R.string.download_folder_failed_content), + folderPathName); + } + } } return message;