From: David A. Velasco Date: Fri, 30 Nov 2012 13:39:31 +0000 (+0100) Subject: Customized error message for uploads when the local file cannot by copied to the... X-Git-Tag: oc-android-1.4.3~80^2~7 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/a7535406d4299dc208b6a8add871b7ed258ecf11?ds=inline;hp=--cc Customized error message for uploads when the local file cannot by copied to the ownCloud local directory --- a7535406d4299dc208b6a8add871b7ed258ecf11 diff --git a/res/values/strings.xml b/res/values/strings.xml index b6fe74fc..270b952a 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -241,4 +241,7 @@ Overwrite Don\'t upload + + %1$s could not be copied to %2$s local directory + diff --git a/src/com/owncloud/android/files/services/FileUploader.java b/src/com/owncloud/android/files/services/FileUploader.java index 31c9d675..6d443a9c 100644 --- a/src/com/owncloud/android/files/services/FileUploader.java +++ b/src/com/owncloud/android/files/services/FileUploader.java @@ -36,6 +36,7 @@ import com.owncloud.android.files.InstantUploadBroadcastReceiver; import com.owncloud.android.operations.ChunkedUploadFileOperation; import com.owncloud.android.operations.RemoteOperationResult; import com.owncloud.android.operations.UploadFileOperation; +import com.owncloud.android.operations.RemoteOperationResult.ResultCode; import com.owncloud.android.ui.activity.FileDetailActivity; import com.owncloud.android.ui.fragment.FileDetailFragment; import com.owncloud.android.utils.OwnCloudVersion; @@ -645,9 +646,18 @@ public class FileUploader extends Service implements OnDatatransferProgressListe finalNotification.flags |= Notification.FLAG_AUTO_CANCEL; // TODO put something smart in the contentIntent below finalNotification.contentIntent = PendingIntent.getActivity(getApplicationContext(), (int)System.currentTimeMillis(), new Intent(), 0); + + String content = null; + if (uploadResult.getCode() == ResultCode.LOCAL_STORAGE_FULL || + uploadResult.getCode() == ResultCode.LOCAL_STORAGE_NOT_COPIED) { + // TODO we need a class to provide error messages for the users from a RemoteOperationResult and a RemoteOperation + content = String.format(getString(R.string.error__upload__local_file_not_copied), (new File(upload.getStoragePath())).getName(), getString(R.string.app_name)); + } else { + content = String.format(getString(R.string.uploader_upload_failed_content_single), (new File(upload.getStoragePath())).getName()); + } finalNotification.setLatestEventInfo( getApplicationContext(), getString(R.string.uploader_upload_failed_ticker), - String.format(getString(R.string.uploader_upload_failed_content_single), (new File(upload.getStoragePath())).getName()), + content, finalNotification.contentIntent); mNotificationManager.notify(R.string.uploader_upload_failed_ticker, finalNotification); diff --git a/src/com/owncloud/android/operations/RemoteOperationResult.java b/src/com/owncloud/android/operations/RemoteOperationResult.java index 973c8a6b..cae45699 100644 --- a/src/com/owncloud/android/operations/RemoteOperationResult.java +++ b/src/com/owncloud/android/operations/RemoteOperationResult.java @@ -71,7 +71,8 @@ public class RemoteOperationResult implements Serializable { CONFLICT, SYNC_CONFLICT, LOCAL_STORAGE_FULL, - LOCAL_STORAGE_NOT_MOVED + LOCAL_STORAGE_NOT_MOVED, + LOCAL_STORAGE_NOT_COPIED } private boolean mSuccess = false; diff --git a/src/com/owncloud/android/operations/UploadFileOperation.java b/src/com/owncloud/android/operations/UploadFileOperation.java index 2ced4bfc..fc9da4b8 100644 --- a/src/com/owncloud/android/operations/UploadFileOperation.java +++ b/src/com/owncloud/android/operations/UploadFileOperation.java @@ -143,7 +143,6 @@ public class UploadFileOperation extends RemoteOperation { mDataTransferListeners.add(listener); } - @Override protected RemoteOperationResult run(WebdavClient client) { RemoteOperationResult result = null; @@ -187,6 +186,11 @@ public class UploadFileOperation extends RemoteOperation { while ((len = in.read(buf)) > 0){ out.write(buf, 0, len); } + + } catch (Exception e) { + result = new RemoteOperationResult(ResultCode.LOCAL_STORAGE_NOT_COPIED); + return result; + } finally { try { if (in != null) in.close(); @@ -230,8 +234,11 @@ public class UploadFileOperation extends RemoteOperation { } expectedFile = new File(mFile.getStoragePath()); if (!expectedFile.equals(fileToMove) && !fileToMove.renameTo(expectedFile)) { - result = new RemoteOperationResult(ResultCode.LOCAL_STORAGE_NOT_MOVED); - return result; + mFile.setStoragePath(null); // forget the local file + // by now, treat this as a success; the file was uploaded; the user won't like that the local file is not linked, but this should be a veeery rare fail; + // the best option could be show a warning message (but not a fail) + //result = new RemoteOperationResult(ResultCode.LOCAL_STORAGE_NOT_MOVED); + //return result; } } }