ソースを参照

add ability to set expiration date for user shares

AndyScherzinger 6 年 前
コミット
42a0e28ee7

+ 21 - 12
src/main/java/com/owncloud/android/operations/UpdateSharePermissionsOperation.java

@@ -1,8 +1,10 @@
-/**
+/*
  *   ownCloud Android client application
  *
  *   @author David A. Velasco
+ *   @author Andy Scherzinger
  *   Copyright (C) 2015 ownCloud Inc.
+ *   Copyright (C) 2018 Andy Scherzinger
  *
  *   This program is free software: you can redistribute it and/or modify
  *   it under the terms of the GNU General Public License version 2,
@@ -15,7 +17,6 @@
  *
  *   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;
@@ -31,26 +32,26 @@ import com.owncloud.android.operations.common.SyncOperation;
 
 
 /**
- * Updates an existing private share for a given file
+ * Updates an existing private share for a given file.
  */
-
 public class UpdateSharePermissionsOperation extends SyncOperation {
 
     private long mShareId;
     private int mPermissions;
+    private long mExpirationDateInMillis;
     private String mPath;
 
     /**
      * Constructor
      *
-     * @param shareId       Private {@link OCShare} to update. Mandatory argument
+     * @param shareId Private {@link OCShare} to update. Mandatory argument
      */
     public UpdateSharePermissionsOperation(long shareId) {
         mShareId = shareId;
         mPermissions = -1;
+        mExpirationDateInMillis = 0L;
     }
 
-
     /**
      * Set permissions to update in private share.
      *
@@ -61,6 +62,17 @@ public class UpdateSharePermissionsOperation extends SyncOperation {
         mPermissions = permissions;
     }
 
+    /**
+     * Set expiration date to update private share.
+     *
+     * @param expirationDateInMillis    Expiration date to set to the public link.
+     *                                  A negative value clears the current expiration date.
+     *                                  Zero value (start-of-epoch) results in no update done on
+     *                                  the expiration date.
+     */
+    public void setExpirationDate(long expirationDateInMillis) {
+        mExpirationDateInMillis = expirationDateInMillis;
+    }
 
     @Override
     protected RemoteOperationResult run(OwnCloudClient client) {
@@ -69,18 +81,15 @@ public class UpdateSharePermissionsOperation extends SyncOperation {
 
         if (share == null) {
             // TODO try to get remote share before failing?
-            return new RemoteOperationResult(
-                    RemoteOperationResult.ResultCode.SHARE_NOT_FOUND
-            );
+            return new RemoteOperationResult(RemoteOperationResult.ResultCode.SHARE_NOT_FOUND);
         }
 
         mPath = share.getPath();
 
         // Update remote share with password
-        UpdateRemoteShareOperation updateOp = new UpdateRemoteShareOperation(
-            share.getRemoteId()
-        );
+        UpdateRemoteShareOperation updateOp = new UpdateRemoteShareOperation(share.getRemoteId());
         updateOp.setPermissions(mPermissions);
+        updateOp.setExpirationDate(mExpirationDateInMillis);
         RemoteOperationResult result = updateOp.execute(client);
 
         if (result.isSuccess()) {

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

@@ -1,7 +1,11 @@
-/**
+/*
  *   ownCloud Android client application
  *
+ *   @author masensio
+ *   @author David A. Velasco
+ *   @author Andy Scherzinger
  *   Copyright (C) 2015 ownCloud Inc.
+ *   Copyright (C) 2018 Andy Scherzinger
  *
  *   This program is free software: you can redistribute it and/or modify
  *   it under the terms of the GNU General Public License version 2,
@@ -14,7 +18,6 @@
  *
  *   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.services;
@@ -583,8 +586,10 @@ public class OperationsService extends Service {
 
                     } else if (shareId > 0) {
                         operation = new UpdateSharePermissionsOperation(shareId);
-                        int permissions = operationIntent.getIntExtra(EXTRA_SHARE_PERMISSIONS, 1);
+                        int permissions = operationIntent.getIntExtra(EXTRA_SHARE_PERMISSIONS, -1);
                         ((UpdateSharePermissionsOperation)operation).setPermissions(permissions);
+                        long expirationDateInMillis = operationIntent.getLongExtra(EXTRA_SHARE_EXPIRATION_DATE_IN_MILLIS, 0L);
+                        ((UpdateSharePermissionsOperation)operation).setExpirationDate(expirationDateInMillis);
                     }
 
                 } else if (action.equals(ACTION_CREATE_SHARE_WITH_SHAREE)) {

+ 5 - 2
src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java

@@ -3,8 +3,10 @@
  *
  * @author Bartek Przybylski
  * @author David A. Velasco
+ * @author Andy Scherzinger
  * Copyright (C) 2011  Bartek Przybylski
  * Copyright (C) 2016 ownCloud Inc.
+ * Copyright (C) 2018 Andy Scherzinger
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2,
@@ -1718,8 +1720,9 @@ public class FileDisplayActivity extends HookActivity
             onCreateShareViaLinkOperationFinish((CreateShareViaLinkOperation) operation, result);
         } else if (operation instanceof CreateShareWithShareeOperation) {
             onUpdateShareInformation(result, R.string.sharee_add_failed);
-        } else if (operation instanceof UpdateSharePermissionsOperation
-                || operation instanceof UpdateShareViaLinkOperation) {
+        } else if (operation instanceof UpdateShareViaLinkOperation) {
+            onUpdateShareInformation(result, R.string.updating_share_failed);
+        } else if (operation instanceof UpdateSharePermissionsOperation) {
             onUpdateShareInformation(result, R.string.updating_share_failed);
         } else if (operation instanceof UnshareOperation) {
             onUpdateShareInformation(result, R.string.unsharing_failed);

+ 4 - 0
src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java

@@ -556,6 +556,10 @@ public class FileOperationsHelper {
                 OperationsService.EXTRA_SHARE_EXPIRATION_DATE_IN_MILLIS,
                 expirationTimeInMillis
         );
+        updateShareIntent.putExtra(
+                OperationsService.EXTRA_SHARE_PERMISSIONS,
+                0
+        );
         queueShareIntent(updateShareIntent);
     }