OC-2734: Update Database for UnshareLink operation
authormasensio <masensio@solidgear.es>
Mon, 3 Feb 2014 13:24:36 +0000 (14:24 +0100)
committermasensio <masensio@solidgear.es>
Mon, 3 Feb 2014 13:24:36 +0000 (14:24 +0100)
res/values/strings.xml
src/com/owncloud/android/datamodel/FileDataStorageManager.java
src/com/owncloud/android/operations/UnshareLinkOperation.java
src/com/owncloud/android/ui/activity/FileDisplayActivity.java
src/com/owncloud/android/ui/fragment/OCFileListFragment.java

index 854a53b..2c4dd7c 100644 (file)
     <string name="failed_upload_retry_do_nothing_text">do nothing you are not online for instant upload</string>
        <string name="failed_upload_failure_text">Failure Message: </string>
        <string name="failed_upload_quota_exceeded_text">Please check your server configuration,maybe your quota is exceeded.</string>
+       
+       <string name="share_link_no_support_share_api">Sorry, sharing is not enabled on your server. Please contact your administrator.</string>
+       <string name="share_link_file_no_exist">Unable to share this file or folder. Please, make sure it exists</string>
 </resources>
index 76e3e5c..7b5380f 100644 (file)
@@ -1099,4 +1099,19 @@ public class FileDataStorageManager {
         }
         
     } 
+    
+    public void removeShare(OCShare share){
+        Uri share_uri = ProviderTableMeta.CONTENT_URI_SHARE;
+        String where = ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?" + " AND " + ProviderTableMeta.FILE_PATH + "=?";
+        String [] whereArgs = new String[]{mAccount.name, share.getPath()};
+        if (getContentProviderClient() != null) {
+            try {
+                getContentProviderClient().delete(share_uri, where, whereArgs);
+            } catch (RemoteException e) {
+                e.printStackTrace();
+            }
+        } else {
+            getContentResolver().delete(share_uri, where, whereArgs); 
+        }
+    }
 }
index b1ec9cc..c588ec1 100644 (file)
 
 package com.owncloud.android.operations;
 
-import java.util.ArrayList;
-
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.lib.network.OwnCloudClient;
 import com.owncloud.android.lib.operations.common.OCShare;
 import com.owncloud.android.lib.operations.common.RemoteOperationResult;
 import com.owncloud.android.lib.operations.common.RemoteOperationResult.ResultCode;
-import com.owncloud.android.lib.operations.remote.GetRemoteSharesOperation;
+import com.owncloud.android.lib.operations.remote.UnshareLinkRemoteOperation;
 import com.owncloud.android.operations.common.SyncOperation;
 import com.owncloud.android.utils.Log_OC;
 
@@ -52,13 +50,16 @@ public class UnshareLinkOperation extends SyncOperation {
         OCShare share = getStorageManager().getShareByPath(mFile.getRemotePath());
         
         if (share != null) {
-            GetRemoteSharesOperation operation = new GetRemoteSharesOperation();
+            UnshareLinkRemoteOperation operation = new UnshareLinkRemoteOperation((int) share.getIdRemoteShared());
             result = operation.execute(client);
 
             if (result.isSuccess()) {
                 Log_OC.d(TAG, "Share id = " + share.getIdRemoteShared() + " deleted");
 
-                // TODO Update DB
+                mFile.setShareByLink(false);
+                mFile.setPublicLink("");
+                getStorageManager().saveFile(mFile);
+                getStorageManager().removeShare(share);
                 
             }
         } else {
index 5cae78d..e4236a5 100644 (file)
@@ -79,6 +79,7 @@ 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.services.OperationsService;
 import com.owncloud.android.syncadapter.FileSyncAdapter;
 import com.owncloud.android.ui.dialog.EditNameDialog;
@@ -1352,10 +1353,24 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
 
         } else if (operation instanceof CreateFolderOperation) {
             onCreateFolderOperationFinish((CreateFolderOperation)operation, result);
+            
+        } else if (operation instanceof UnshareLinkOperation) {
+            onUnshareLinkOperationFinish((UnshareLinkOperation)operation, result);
         }
     }
 
 
+    private void onUnshareLinkOperationFinish(UnshareLinkOperation operation, RemoteOperationResult result) {
+        if (result.getCode() == ResultCode.FILE_NOT_FOUND) {
+            // Show a Message
+            Toast t = Toast.makeText(this, getString(R.string.share_link_file_no_exist), Toast.LENGTH_LONG);
+            t.show();
+        }
+
+        refeshListOfFilesFragment();
+
+    }
+
     /**
      * Updates the view associated to the activity after the finish of an operation trying to remove a 
      * file. 
@@ -1574,4 +1589,20 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
         mRefreshSharesInProgress = true;
     }
     
+    
+    public void unshareFileWithLink(OCFile file) {
+        
+        if (isSharedSupported()) {
+            // Unshare the file
+            UnshareLinkOperation unshare = new UnshareLinkOperation(file);
+            unshare.execute(getStorageManager(), this, this, mHandler, this);
+            
+        } else {
+            // Show a Message
+            Toast t = Toast.makeText(this, getString(R.string.share_link_no_support_share_api), Toast.LENGTH_LONG);
+            t.show();
+            
+        }
+    }
+
 }
index 5cd4a15..7691d77 100644 (file)
@@ -285,6 +285,10 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
         AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();        
         mTargetFile = (OCFile) mAdapter.getItem(info.position);
         switch (item.getItemId()) {
+            case R.id.action_unshare_file: {
+                mContainerActivity.unshareFileWithLink(mTargetFile);
+                return true;
+            }
             case R.id.action_rename_file: {
                 String fileName = mTargetFile.getFileName();
                 int extensionStart = mTargetFile.isFolder() ? -1 : fileName.lastIndexOf(".");
@@ -439,6 +443,8 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
          */
         public void onBrowsedDownTo(OCFile folder);
         
+        public void unshareFileWithLink(OCFile mTargetFile);
+
         public void startDownloadForPreview(OCFile file);
 
         public void startMediaPreview(OCFile file, int i, boolean b);