Эх сурвалжийг харах

OC-2675: CreateShareRemoteOperation in Library

masensio 11 жил өмнө
parent
commit
426d7a3f88

+ 90 - 0
src/com/owncloud/android/operations/CreateShareOperation.java

@@ -0,0 +1,90 @@
+/* ownCloud Android client application
+ *   Copyright (C) 2014 ownCloud Inc.
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License version 2,
+ *   as published by the Free Software Foundation.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.owncloud.android.operations;
+
+/**
+ * Creates a new share from a given file
+ * 
+ * @author masensio
+ *
+ */
+
+import com.owncloud.android.datamodel.FileDataStorageManager;
+import com.owncloud.android.lib.network.OwnCloudClient;
+import com.owncloud.android.lib.operations.common.RemoteOperation;
+import com.owncloud.android.lib.operations.common.RemoteOperationResult;
+import com.owncloud.android.lib.operations.common.ShareType;
+import com.owncloud.android.lib.operations.remote.CreateShareRemoteOperation;
+
+public class CreateShareOperation extends RemoteOperation {
+    
+    private static final String TAG = CreateShareOperation.class.getSimpleName();
+
+    protected FileDataStorageManager mStorageManager;
+
+    private String mPath;
+    private ShareType mShareType;
+    private String mShareWith;
+    private boolean mPublicUpload;
+    private String mPassword;
+    private int mPermissions;
+    
+    /**
+     * Constructor
+     * @param path          Full path of the file/folder being shared. Mandatory argument
+     * @param shareType     ‘0’ = user, ‘1’ = group, ‘3’ = Public link. Mandatory argument
+     * @param shareWith     User/group ID with who the file should be shared.  This is mandatory for shareType of 0 or 1
+     * @param publicUpload  If ‘false’ (default) public cannot upload to a public shared folder. 
+     *                      If ‘true’ public can upload to a shared folder. Only available for public link shares
+     * @param password      Password to protect a public link share. Only available for public link shares
+     * @param permissions   1 - Read only – Default for “public” shares
+     *                      2 - Update
+     *                      4 - Create
+     *                      8 - Delete
+     *                      16- Re-share
+     *                      31- All above – Default for “private” shares
+     *                      For user or group shares.
+     *                      To obtain combinations, add the desired values together.  
+     *                      For instance, for “Re-Share”, “delete”, “read”, “update”, add 16+8+2+1 = 27.
+     */
+    public CreateShareOperation(String path, ShareType shareType, String shareWith, boolean publicUpload, 
+            String password, int permissions) {
+
+        mPath = path;
+        mShareType = shareType;
+        mShareWith = shareWith;
+        mPublicUpload = publicUpload;
+        mPassword = password;
+        mPermissions = permissions;
+    }
+
+    @Override
+    protected RemoteOperationResult run(OwnCloudClient client) {
+        CreateShareRemoteOperation operation = new CreateShareRemoteOperation(mPath, mShareType, mShareWith, mPublicUpload, mPassword, mPermissions);
+        RemoteOperationResult result = operation.execute(client);
+
+        if (result.isSuccess()) {
+            // TODO
+            // Update DB with the response
+
+        }
+
+        return result;
+    }
+
+}

+ 9 - 0
src/com/owncloud/android/ui/activity/FileDisplayActivity.java

@@ -74,8 +74,10 @@ import com.owncloud.android.operations.GetSharesOperation;
 import com.owncloud.android.lib.operations.common.OnRemoteOperationListener;
 import com.owncloud.android.lib.operations.common.RemoteOperation;
 import com.owncloud.android.lib.operations.common.RemoteOperationResult;
+import com.owncloud.android.lib.operations.common.ShareType;
 import com.owncloud.android.lib.operations.common.RemoteOperationResult.ResultCode;
 
+import com.owncloud.android.operations.CreateShareOperation;
 import com.owncloud.android.operations.RemoveFileOperation;
 import com.owncloud.android.operations.RenameFileOperation;
 import com.owncloud.android.operations.SynchronizeFileOperation;
@@ -1536,6 +1538,13 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
         setSupportProgressBarIndeterminateVisibility(true);
         
     }
+
+    @Override
+    public void shareFileWithLink(OCFile file) {
+            CreateShareOperation createShare = new CreateShareOperation(file.getRemotePath(), ShareType.PUBLIC_LINK, "", false, "", 1);
+            createShare.execute(getAccount(), this, this, mHandler, this);
+        
+    }
     
 //    public void enableDisableViewGroup(ViewGroup viewGroup, boolean enabled) {
 //        int childCount = viewGroup.getChildCount();

+ 8 - 2
src/com/owncloud/android/ui/fragment/FileDetailFragment.java

@@ -55,6 +55,9 @@ import com.owncloud.android.lib.operations.common.OnRemoteOperationListener;
 import com.owncloud.android.lib.operations.common.RemoteOperation;
 import com.owncloud.android.lib.operations.common.RemoteOperationResult;
 import com.owncloud.android.lib.operations.common.RemoteOperationResult.ResultCode;
+import com.owncloud.android.lib.operations.common.ShareType;
+import com.owncloud.android.lib.operations.remote.CreateShareRemoteOperation;
+import com.owncloud.android.operations.CreateShareOperation;
 import com.owncloud.android.operations.RemoveFileOperation;
 import com.owncloud.android.operations.RenameFileOperation;
 import com.owncloud.android.operations.SynchronizeFileOperation;
@@ -335,6 +338,10 @@ public class FileDetailFragment extends FileFragment implements
     @Override
     public boolean onOptionsItemSelected(MenuItem item) {
         switch (item.getItemId()) {
+            case R.id.action_share_file: {
+                    mContainerActivity.shareFileWithLink(getFile());
+                return true;
+            }
             case R.id.action_open_file_with: {
                 mContainerActivity.openFile(getFile());
                 return true;
@@ -358,7 +365,7 @@ public class FileDetailFragment extends FileFragment implements
                 return false;
         }
     }
-    
+
     @Override
     public void onClick(View v) {
         switch (v.getId()) {
@@ -399,7 +406,6 @@ public class FileDetailFragment extends FileFragment implements
         }
     }
 
-
     private void removeFile() {
         OCFile file = getFile();
         ConfirmationDialogFragment confDialog = ConfirmationDialogFragment.newInstance(

+ 2 - 0
src/com/owncloud/android/ui/fragment/FileFragment.java

@@ -95,6 +95,8 @@ public class FileFragment extends SherlockFragment {
          * @param file      File to show details
          */
         public void showDetails(OCFile file);
+
+        public void shareFileWithLink(OCFile file);
         
         
     }

+ 6 - 0
src/com/owncloud/android/ui/fragment/OCFileListFragment.java

@@ -284,6 +284,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_share_file: {
+                    mContainerActivity.shareFileWithLink(getCurrentFile());
+                return true;
+            }
             case R.id.action_rename_file: {
                 String fileName = mTargetFile.getFileName();
                 int extensionStart = mTargetFile.isFolder() ? -1 : fileName.lastIndexOf(".");
@@ -419,6 +423,8 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
          */
         public void onBrowsedDownTo(OCFile folder);
         
+        public void shareFileWithLink(OCFile currentFile);
+
         public void startDownloadForPreview(OCFile file);
 
         public void startMediaPreview(OCFile file, int i, boolean b);

+ 5 - 0
src/com/owncloud/android/ui/preview/PreviewImageActivity.java

@@ -480,5 +480,10 @@ public class PreviewImageActivity extends FileActivity implements FileFragment.C
             startActivity(i);
         }
     }
+
+    @Override
+    public void shareFileWithLink(OCFile file) {
+        
+    }
     
 }