瀏覽代碼

Show error messages from server when share-specific errors occur while sharing or unsharing

David A. Velasco 9 年之前
父節點
當前提交
cc0fb41554

+ 7 - 11
src/com/owncloud/android/operations/UnshareOperation.java

@@ -67,14 +67,14 @@ public class UnshareOperation extends SyncOperation {
                 mShareType, mShareWith);
                 mShareType, mShareWith);
         
         
         if (share != null) {
         if (share != null) {
+            OCFile file = getStorageManager().getFileByPath(mRemotePath);
             RemoveRemoteShareOperation operation =
             RemoveRemoteShareOperation operation =
                     new RemoveRemoteShareOperation((int) share.getIdRemoteShared());
                     new RemoveRemoteShareOperation((int) share.getIdRemoteShared());
             result = operation.execute(client);
             result = operation.execute(client);
 
 
-            if (result.isSuccess() || result.getCode() == ResultCode.SHARE_NOT_FOUND) {
+            if (result.isSuccess()) {
                 Log_OC.d(TAG, "Share id = " + share.getIdRemoteShared() + " deleted");
                 Log_OC.d(TAG, "Share id = " + share.getIdRemoteShared() + " deleted");
 
 
-                OCFile file = getStorageManager().getFileByPath(mRemotePath);
                 if (mShareType == ShareType.PUBLIC_LINK) {
                 if (mShareType == ShareType.PUBLIC_LINK) {
                     file.setShareViaLink(false);
                     file.setShareViaLink(false);
                     file.setPublicLink("");
                     file.setPublicLink("");
@@ -91,15 +91,11 @@ public class UnshareOperation extends SyncOperation {
                 getStorageManager().saveFile(file);
                 getStorageManager().saveFile(file);
                 getStorageManager().removeShare(share);
                 getStorageManager().removeShare(share);
                 
                 
-                if (result.getCode() == ResultCode.SHARE_NOT_FOUND) {
-                    if (existsFile(client, file.getRemotePath())) {
-                        result = new RemoteOperationResult(ResultCode.OK);
-                    } else {
-                        getStorageManager().removeFile(file, true, true);
-                    }
-                }
-            } 
-                
+            } else if (!existsFile(client, file.getRemotePath())) {
+                // unshare failed because file was deleted before
+                getStorageManager().removeFile(file, true, true);
+            }
+
         } else {
         } else {
             result = new RemoteOperationResult(ResultCode.SHARE_NOT_FOUND);
             result = new RemoteOperationResult(ResultCode.SHARE_NOT_FOUND);
         }
         }

+ 20 - 11
src/com/owncloud/android/ui/activity/ShareActivity.java

@@ -41,6 +41,7 @@ import com.owncloud.android.operations.CreateShareWithShareeOperation;
 import com.owncloud.android.operations.UnshareOperation;
 import com.owncloud.android.operations.UnshareOperation;
 import com.owncloud.android.ui.fragment.SearchFragment;
 import com.owncloud.android.ui.fragment.SearchFragment;
 import com.owncloud.android.ui.fragment.ShareFileFragment;
 import com.owncloud.android.ui.fragment.ShareFileFragment;
+import com.owncloud.android.utils.ErrorMessageAdapter;
 import com.owncloud.android.utils.GetShareWithUsersAsyncTask;
 import com.owncloud.android.utils.GetShareWithUsersAsyncTask;
 
 
 import java.util.ArrayList;
 import java.util.ArrayList;
@@ -131,11 +132,6 @@ public class ShareActivity extends FileActivity
     }
     }
 
 
     private void doShareWith(String shareeName, boolean isGroup) {
     private void doShareWith(String shareeName, boolean isGroup) {
-        if (isGroup) {
-           Log_OC.d(TAG, "You want to SHARE with GROUP [" + shareeName + "]");
-        } else {
-           Log_OC.d(TAG, "You want to SHARE with USER [" + shareeName + "]");
-        }
         getFileOperationsHelper().shareFileWithSharee(
         getFileOperationsHelper().shareFileWithSharee(
                 getFile(),
                 getFile(),
                 shareeName,
                 shareeName,
@@ -204,12 +200,25 @@ public class ShareActivity extends FileActivity
     @Override
     @Override
     public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {
     public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {
         super.onRemoteOperationFinish(operation, result);
         super.onRemoteOperationFinish(operation, result);
-        if (operation instanceof UnshareOperation) {
-            refreshUsersInLists();
-        } else if(operation instanceof CreateShareWithShareeOperation){
-            refreshUsersInLists();
-            // Clean action
-            getIntent().setAction(null);
+        if (operation instanceof UnshareOperation ||
+                operation instanceof CreateShareWithShareeOperation) {
+
+            if (result.isSuccess()) {
+                refreshUsersInLists();
+                if (operation instanceof  CreateShareWithShareeOperation) {
+                    // Clean action
+                    getIntent().setAction(null);
+                }
+            } else {
+                Toast.makeText(
+                        this,
+                        ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
+                        Toast.LENGTH_LONG
+                ).show();
+            }
+
+        /*} else if (operation instanceof GetSharesForFileOperation) {
+            onGetSharesForFileOperationFinish((GetSharesForFileOperation) operation, result);*/
         }
         }
     }
     }
 
 

+ 9 - 2
src/com/owncloud/android/utils/ErrorMessageAdapter.java

@@ -173,7 +173,11 @@ public class ErrorMessageAdapter {
             }
             }
         } else if (operation instanceof CreateShareViaLinkOperation ||
         } else if (operation instanceof CreateShareViaLinkOperation ||
                     operation instanceof CreateShareWithShareeOperation) {
                     operation instanceof CreateShareWithShareeOperation) {
-            if (result.getCode() == ResultCode.SHARE_NOT_FOUND)  {      // Error --> SHARE_NOT_FOUND
+
+            if (result.getData() != null && result.getData().size() > 0) {
+                message = (String) result.getData().get(0);     // share API sends its own error messages
+
+            } else if (result.getCode() == ResultCode.SHARE_NOT_FOUND)  {
                 message = res.getString(R.string.share_link_file_no_exist);
                 message = res.getString(R.string.share_link_file_no_exist);
 
 
             } else if (result.getCode() == ResultCode.SHARE_FORBIDDEN) {
             } else if (result.getCode() == ResultCode.SHARE_FORBIDDEN) {
@@ -191,7 +195,10 @@ public class ErrorMessageAdapter {
 
 
         } else if (operation instanceof UnshareOperation) {
         } else if (operation instanceof UnshareOperation) {
 
 
-            if (result.getCode() == ResultCode.SHARE_NOT_FOUND)  {      // Error --> SHARE_NOT_FOUND
+            if (result.getData() != null && result.getData().size() > 0) {
+                message = (String) result.getData().get(0);     // share API sends its own error messages
+
+            } else  if (result.getCode() == ResultCode.SHARE_NOT_FOUND)  {
                 message = res.getString(R.string.unshare_link_file_no_exist);
                 message = res.getString(R.string.unshare_link_file_no_exist);
 
 
             } else if (result.getCode() == ResultCode.SHARE_FORBIDDEN) {
             } else if (result.getCode() == ResultCode.SHARE_FORBIDDEN) {