Browse Source

Customized error message for uploads when the local file cannot by copied to the ownCloud local directory

David A. Velasco 12 năm trước cách đây
mục cha
commit
a7535406d4

+ 3 - 0
res/values/strings.xml

@@ -241,4 +241,7 @@
     <string name="conflict_overwrite">Overwrite</string>
     <string name="conflict_dont_upload">Don\'t upload</string>
     
+    <!-- we need to improve the communication of errors to the user -->
+    <string name="error__upload__local_file_not_copied">%1$s could not be copied to %2$s local directory</string>
+    
 </resources>

+ 11 - 1
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);

+ 2 - 1
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;

+ 10 - 3
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;
                     }
                 } 
             }