Kaynağa Gözat

OC-2895: Move execution of UnshareOperation to OperationsService

masensio 11 yıl önce
ebeveyn
işleme
b599f945e6

+ 6 - 11
src/com/owncloud/android/files/FileOperationsHelper.java

@@ -22,7 +22,6 @@ import org.apache.http.protocol.HTTP;
 import android.accounts.AccountManager;
 import android.content.Intent;
 import android.net.Uri;
-import android.sax.StartElementListener;
 import android.support.v4.app.DialogFragment;
 import android.webkit.MimeTypeMap;
 import android.widget.Toast;
@@ -31,9 +30,6 @@ import com.owncloud.android.R;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.lib.accounts.OwnCloudAccount;
 import com.owncloud.android.lib.network.webdav.WebdavUtils;
-import com.owncloud.android.lib.operations.common.ShareType;
-import com.owncloud.android.operations.CreateShareOperation;
-import com.owncloud.android.operations.UnshareLinkOperation;
 import com.owncloud.android.services.OperationsService;
 import com.owncloud.android.ui.activity.FileActivity;
 import com.owncloud.android.ui.dialog.ActivityChooserDialog;
@@ -149,13 +145,12 @@ public class FileOperationsHelper {
         
         if (isSharedSupported(callerActivity)) {
             // Unshare the file
-            UnshareLinkOperation unshare = new UnshareLinkOperation(file, callerActivity);
-            unshare.execute(callerActivity.getStorageManager(), 
-                    callerActivity, 
-                    callerActivity.getRemoteOperationListener(), 
-                    callerActivity.getHandler(), 
-                    callerActivity);
-         
+            Intent service = new Intent(callerActivity, OperationsService.class);
+            service.setAction(OperationsService.ACTION_UNSHARE);
+            service.putExtra(OperationsService.EXTRA_ACCOUNT, callerActivity.getAccount());
+            service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath());
+            callerActivity.startService(service);
+            
             callerActivity.showLoadingDialog();
             
         } else {

+ 13 - 11
src/com/owncloud/android/operations/UnshareLinkOperation.java

@@ -26,6 +26,7 @@ import com.owncloud.android.lib.operations.common.RemoteOperationResult;
 import com.owncloud.android.lib.operations.common.RemoteOperationResult.ResultCode;
 import com.owncloud.android.lib.operations.remote.ExistenceCheckRemoteOperation;
 import com.owncloud.android.lib.operations.remote.RemoveRemoteShareOperation;
+import com.owncloud.android.lib.utils.FileUtils;
 import com.owncloud.android.operations.common.SyncOperation;
 import com.owncloud.android.utils.Log_OC;
 
@@ -39,12 +40,12 @@ public class UnshareLinkOperation extends SyncOperation {
 
     private static final String TAG = UnshareLinkOperation.class.getSimpleName();
     
-    private OCFile mFile;
+    private String mRemotePath;
     private Context mContext;
     
     
-    public UnshareLinkOperation(OCFile file, Context context) {
-        mFile = file;
+    public UnshareLinkOperation(String remotePath, Context context) {
+        mRemotePath = remotePath;
         mContext = context;
     }
 
@@ -53,9 +54,9 @@ public class UnshareLinkOperation extends SyncOperation {
         RemoteOperationResult result  = null;
         
         // Get Share for a file
-        String path = mFile.getRemotePath();
-        if (mFile.isFolder()) {
-            path = path.substring(0, path.length()-1); // Remove last /
+        String path = mRemotePath;
+        if (path.endsWith(FileUtils.PATH_SEPARATOR)) {
+           path = path.substring(0, path.length()-1); // Remove last /
         }
         OCShare share = getStorageManager().getShareByPath(path);
         
@@ -66,16 +67,17 @@ public class UnshareLinkOperation extends SyncOperation {
             if (result.isSuccess() || result.getCode() == ResultCode.SHARE_NOT_FOUND) {
                 Log_OC.d(TAG, "Share id = " + share.getIdRemoteShared() + " deleted");
 
-                mFile.setShareByLink(false);
-                mFile.setPublicLink("");
-                getStorageManager().saveFile(mFile);
+                OCFile file = getStorageManager().getFileByPath(mRemotePath);
+                file.setShareByLink(false);
+                file.setPublicLink("");
+                getStorageManager().saveFile(file);
                 getStorageManager().removeShare(share);
                 
                 if (result.getCode() == ResultCode.SHARE_NOT_FOUND) {
-                    if (existsFile(client, mFile.getRemotePath())) {
+                    if (existsFile(client, file.getRemotePath())) {
                         result = new RemoteOperationResult(ResultCode.OK);
                     } else {
-                        getStorageManager().removeFile(mFile, true, true);
+                        getStorageManager().removeFile(file, true, true);
                     }
                 }
             } 

+ 7 - 3
src/com/owncloud/android/services/OperationsService.java

@@ -26,6 +26,7 @@ import com.owncloud.android.lib.network.OwnCloudClientFactory;
 import com.owncloud.android.lib.network.OwnCloudClient;
 import com.owncloud.android.operations.CreateShareOperation;
 import com.owncloud.android.operations.GetSharesOperation;
+import com.owncloud.android.operations.UnshareLinkOperation;
 import com.owncloud.android.operations.common.SyncOperation;
 import com.owncloud.android.lib.operations.common.RemoteOperation;
 import com.owncloud.android.lib.operations.common.RemoteOperationResult;
@@ -119,15 +120,18 @@ public class OperationsService extends Service {
             RemoteOperation operation = null;
             
             String action = intent.getAction();
-            if (action == ACTION_CREATE_SHARE) {
+            if (action == ACTION_CREATE_SHARE) {  // Create Share
                 String remotePath = intent.getStringExtra(EXTRA_REMOTE_PATH);
                 Intent sendIntent = intent.getParcelableExtra(EXTRA_SEND_INTENT);
                 if (remotePath.length() > 0) {
                     operation = new CreateShareOperation(remotePath, ShareType.PUBLIC_LINK, 
                             "", false, "", 1, sendIntent);
                 }
-            } else if (action == ACTION_UNSHARE) {
-                
+            } else if (action == ACTION_UNSHARE) {  // Unshare file
+                String remotePath = intent.getStringExtra(EXTRA_REMOTE_PATH);
+                if (remotePath.length() > 0) {
+                    operation = new UnshareLinkOperation(remotePath, this.getApplicationContext());
+                }
             } else {
                 operation = new GetSharesOperation();
             }