Fix. App does not realize that the folder does not exist
authorjabarros <jabarros@solidgear.es>
Wed, 7 Jan 2015 10:22:24 +0000 (11:22 +0100)
committerjabarros <jabarros@solidgear.es>
Wed, 7 Jan 2015 10:22:24 +0000 (11:22 +0100)
res/values/strings.xml
src/com/owncloud/android/operations/SynchronizeFolderOperation.java
src/com/owncloud/android/services/OperationsService.java
src/com/owncloud/android/ui/activity/FileActivity.java
src/com/owncloud/android/utils/ErrorMessageAdapter.java

index 8b82868..c26a31c 100644 (file)
        <string name="prefs_category_security">Security</string>
 
        <string name="prefs_instant_video_upload_path_title">Upload Video Path</string>
+    <string name="download_folder_not_found">The folder is no longer available on the server</string>
+    <string name="downloader_download_folder_failed_content">Download of %1$s folder could not be completed</string>
 
 </resources>
index 0dee54f..088c578 100644 (file)
@@ -542,4 +542,12 @@ public class SynchronizeFolderOperation extends SyncOperation {
     public void cancel() {
         mCancellationRequested.set(true);
     }
+
+    public String getFolderPath() {
+        String path = mLocalFolder.getStoragePath();
+        if (path != null && path.length() > 0) {
+            return path;
+        }
+        return FileStorageUtils.getDefaultSavePathFor(mAccount.name, mLocalFolder);
+    }
 }
index 385306d..ae4988d 100644 (file)
@@ -449,6 +449,7 @@ public class OperationsService extends Service {
             }
 
             if (mCurrentSyncOperation != null) {
+                RemoteOperationResult result = null;
 
                 try {
 
@@ -460,7 +461,7 @@ public class OperationsService extends Service {
                             mService.getContentResolver()
                     );
 
-                    mCurrentSyncOperation.execute(mOwnCloudClient, mStorageManager);
+                    result = mCurrentSyncOperation.execute(mOwnCloudClient, mStorageManager);
 
                 } catch (AccountsException e) {
                     Log_OC.e(TAG, "Error while trying to get autorization", e);
@@ -470,6 +471,8 @@ public class OperationsService extends Service {
                     synchronized(mPendingOperations) {
                         mPendingOperations.remove(syncKey);
                     }
+
+                    mService.dispatchResultToOperationListeners(null, mCurrentSyncOperation, result);
                 }
             }
         }
@@ -830,7 +833,7 @@ public class OperationsService extends Service {
     
     /**
      * Notifies the currently subscribed listeners about the end of an operation.
-     * 
+     *
      * @param target            Account or URL pointing to an OC server.
      * @param operation         Finished operation.
      * @param result            Result of the operation.
index 136bdb5..5ab3eba 100644 (file)
@@ -54,6 +54,7 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
 import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.operations.CreateShareOperation;
+import com.owncloud.android.operations.SynchronizeFolderOperation;
 import com.owncloud.android.operations.UnshareLinkOperation;
 
 import com.owncloud.android.services.OperationsService;
@@ -464,7 +465,10 @@ implements OnRemoteOperationListener, ComponentsGetter {
         } else if (operation instanceof UnshareLinkOperation) {
             onUnshareLinkOperationFinish((UnshareLinkOperation)operation, result);
         
-        } 
+        } else if (operation instanceof SynchronizeFolderOperation) {
+            onSynchronizeFolderOperationFinish((SynchronizeFolderOperation)operation, result);
+
+        }
     }
 
     protected void requestCredentialsUpdate() {
@@ -506,7 +510,14 @@ implements OnRemoteOperationListener, ComponentsGetter {
             t.show();
         } 
     }
-    
+
+    private void onSynchronizeFolderOperationFinish(SynchronizeFolderOperation operation, RemoteOperationResult result) {
+        if (!result.isSuccess()){
+            Toast t = Toast.makeText(this, ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
+                    Toast.LENGTH_LONG);
+            t.show();
+        }
+    }
     
     protected void updateFileFromDB(){
         OCFile file = getFile();
index e56e876..9e077c0 100644 (file)
@@ -36,6 +36,7 @@ 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;
 
@@ -206,6 +207,18 @@ public class ErrorMessageAdapter {
                 // Show a Message, operation finished without success
                 message = res.getString(R.string.move_file_error);
             }
+        } else if (operation instanceof SynchronizeFolderOperation) {
+
+            if (!result.isSuccess()) {
+                if (result.getCode() == ResultCode.FILE_NOT_FOUND) {
+                    message = res.getString(R.string.download_folder_not_found);
+
+                } else {    // Generic error
+                    // Show a Message, operation finished without success
+                    message = String.format(res.getString(R.string.downloader_download_folder_failed_content), new File(
+                            ((SynchronizeFolderOperation) operation).getFolderPath()).getName());
+                }
+            }
         }
         
         return message;