1 /* ownCloud Android client application
2 * Copyright (C) 2014 ownCloud Inc.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2,
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 package com
.owncloud
.android
.utils
;
23 import android
.content
.res
.Resources
;
25 import com
.owncloud
.android
.R
;
26 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperation
;
27 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperationResult
;
28 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperationResult
.ResultCode
;
29 import com
.owncloud
.android
.operations
.DownloadFileOperation
;
30 import com
.owncloud
.android
.operations
.UploadFileOperation
;
33 * Class to choose proper error messages to show to the user depending on the results of operations, always following the same policy
39 public class ErrorMessageAdapter
{
41 public ErrorMessageAdapter() {
45 public static String
getErrorCauseMessage(RemoteOperationResult result
, RemoteOperation operation
, Resources res
) {
47 String message
= null
;
49 if (operation
instanceof UploadFileOperation
) {
51 if (result
.isSuccess()) {
52 message
= String
.format(res
.getString(R
.string
.uploader_upload_succeeded_content_single
),
53 ((UploadFileOperation
) operation
).getFileName());
55 if (result
.getCode() == ResultCode
.LOCAL_STORAGE_FULL
56 || result
.getCode() == ResultCode
.LOCAL_STORAGE_NOT_COPIED
) {
57 message
= String
.format(res
.getString(R
.string
.error__upload__local_file_not_copied
),
58 ((UploadFileOperation
) operation
).getFileName());
59 } else if (result
.getCode() == ResultCode
.QUOTA_EXCEEDED
) {
60 message
= res
.getString(R
.string
.failed_upload_quota_exceeded_text
);
62 message
= String
.format(res
.getString(R
.string
.uploader_upload_failed_content_single
),
63 ((UploadFileOperation
) operation
).getFileName());
67 } else if (operation
instanceof DownloadFileOperation
) {
69 if (result
.isSuccess()) {
70 message
= String
.format(res
.getString(R
.string
.downloader_download_succeeded_content
),
71 new File(((DownloadFileOperation
) operation
).getSavePath()).getName());
73 message
= String
.format(res
.getString(R
.string
.downloader_download_failed_content
),
74 new File(((DownloadFileOperation
) operation
).getSavePath()).getName());