}
- public OCShare getFirstShareByPathAndType(String path, ShareType type) {
+ public OCShare getFirstShareByPathAndType(String path, ShareType type, String shareWith) {
Cursor c = null;
+
+ String selection = ProviderTableMeta.OCSHARES_PATH + "=? AND "
+ + ProviderTableMeta.OCSHARES_SHARE_TYPE + "=? AND "
+ + ProviderTableMeta.OCSHARES_SHARE_WITH + "=? AND "
+ + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?" ;
+
+ String [] selectionArgs = new String[]{path, Integer.toString(type.getValue()),
+ shareWith, mAccount.name};
+
if (getContentResolver() != null) {
c = getContentResolver().query(
ProviderTableMeta.CONTENT_URI_SHARE,
null,
- ProviderTableMeta.OCSHARES_PATH + "=? AND "
- + ProviderTableMeta.OCSHARES_SHARE_TYPE + "=? AND "
- + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?",
- new String[]{path, Integer.toString(type.getValue()), mAccount.name},
+ selection, selectionArgs,
null);
} else {
try {
c = getContentProviderClient().query(
ProviderTableMeta.CONTENT_URI_SHARE,
null,
- ProviderTableMeta.OCSHARES_PATH + "=? AND "
- + ProviderTableMeta.OCSHARES_SHARE_TYPE + "=? AND "
- + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?",
- new String[]{path, Integer.toString(type.getValue()), mAccount.name},
+ selection, selectionArgs,
null);
} catch (RemoteException e) {
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
import com.owncloud.android.lib.common.network.WebdavUtils;
import com.owncloud.android.lib.common.utils.Log_OC;
+import com.owncloud.android.lib.resources.shares.ShareType;
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
import com.owncloud.android.services.OperationsService;
import com.owncloud.android.services.observer.FileObserverService;
service.setAction(OperationsService.ACTION_UNSHARE);
service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath());
+ service.putExtra(OperationsService.EXTRA_SHARE_TYPE, ShareType.PUBLIC_LINK);
+ service.putExtra(OperationsService.EXTRA_SHARE_WITH, "");
mWaitingForOpId = mFileActivity.getOperationsServiceBinder().queueNewOperation(service);
mFileActivity.showLoadingDialog(mFileActivity.getApplicationContext().
+++ /dev/null
-/**
- * ownCloud Android client application
- *
- * @author masensio
- * Copyright (C) 2015 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;
-
-import android.content.Context;
-
-import com.owncloud.android.datamodel.OCFile;
-
-import com.owncloud.android.lib.common.OwnCloudClient;
-import com.owncloud.android.lib.common.operations.RemoteOperationResult;
-import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
-import com.owncloud.android.lib.common.utils.Log_OC;
-import com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation;
-import com.owncloud.android.lib.resources.shares.OCShare;
-import com.owncloud.android.lib.resources.shares.RemoveRemoteShareOperation;
-import com.owncloud.android.lib.resources.shares.ShareType;
-
-import com.owncloud.android.operations.common.SyncOperation;
-
-/**
- * Unshare file/folder
- * Save the data in Database
- */
-public class UnshareLinkOperation extends SyncOperation {
-
- private static final String TAG = UnshareLinkOperation.class.getSimpleName();
-
- private String mRemotePath;
- private Context mContext;
-
-
- public UnshareLinkOperation(String remotePath, Context context) {
- mRemotePath = remotePath;
- mContext = context;
- }
-
- @Override
- protected RemoteOperationResult run(OwnCloudClient client) {
- RemoteOperationResult result = null;
-
- // Get Share for a file
- OCShare share = getStorageManager().getFirstShareByPathAndType(mRemotePath,
- ShareType.PUBLIC_LINK);
-
- if (share != null) {
- RemoveRemoteShareOperation operation =
- new RemoveRemoteShareOperation((int) share.getIdRemoteShared());
- result = operation.execute(client);
-
- if (result.isSuccess() || result.getCode() == ResultCode.SHARE_NOT_FOUND) {
- Log_OC.d(TAG, "Share id = " + share.getIdRemoteShared() + " deleted");
-
- OCFile file = getStorageManager().getFileByPath(mRemotePath);
- file.setShareViaLink(false);
- file.setPublicLink("");
- getStorageManager().saveFile(file);
- 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 {
- result = new RemoteOperationResult(ResultCode.SHARE_NOT_FOUND);
- }
-
- return result;
- }
-
- private boolean existsFile(OwnCloudClient client, String remotePath){
- ExistenceCheckRemoteOperation existsOperation =
- new ExistenceCheckRemoteOperation(remotePath, mContext, false);
- RemoteOperationResult result = existsOperation.execute(client);
- return result.isSuccess();
- }
-
-}
--- /dev/null
+/**
+ * ownCloud Android client application
+ *
+ * @author masensio
+ * Copyright (C) 2015 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;
+
+import android.content.Context;
+
+import com.owncloud.android.datamodel.OCFile;
+
+import com.owncloud.android.lib.common.OwnCloudClient;
+import com.owncloud.android.lib.common.operations.RemoteOperationResult;
+import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
+import com.owncloud.android.lib.common.utils.Log_OC;
+import com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation;
+import com.owncloud.android.lib.resources.shares.OCShare;
+import com.owncloud.android.lib.resources.shares.RemoveRemoteShareOperation;
+import com.owncloud.android.lib.resources.shares.ShareType;
+
+import com.owncloud.android.operations.common.SyncOperation;
+
+import java.util.ArrayList;
+
+/**
+ * Unshare file/folder
+ * Save the data in Database
+ */
+public class UnshareOperation extends SyncOperation {
+
+ private static final String TAG = UnshareOperation.class.getSimpleName();
+
+ private String mRemotePath;
+ private ShareType mShareType;
+ private String mShareWith;
+ private Context mContext;
+
+ public UnshareOperation(String remotePath, ShareType shareType, String shareWith,
+ Context context) {
+ mRemotePath = remotePath;
+ mShareType = shareType;
+ mShareWith = shareWith;
+ mContext = context;
+ }
+
+ @Override
+ protected RemoteOperationResult run(OwnCloudClient client) {
+ RemoteOperationResult result = null;
+
+ // Get Share for a file
+ OCShare share = getStorageManager().getFirstShareByPathAndType(mRemotePath,
+ mShareType, mShareWith);
+
+ if (share != null) {
+ RemoveRemoteShareOperation operation =
+ new RemoveRemoteShareOperation((int) share.getIdRemoteShared());
+ result = operation.execute(client);
+
+ if (result.isSuccess() || result.getCode() == ResultCode.SHARE_NOT_FOUND) {
+ Log_OC.d(TAG, "Share id = " + share.getIdRemoteShared() + " deleted");
+
+ OCFile file = getStorageManager().getFileByPath(mRemotePath);
+ if (mShareType == ShareType.PUBLIC_LINK) {
+ file.setShareViaLink(false);
+ file.setPublicLink("");
+ } else if (mShareType == ShareType.USER || mShareType == ShareType.GROUP){
+ // Check if it is the last share
+ ArrayList <OCShare> sharesWith = getStorageManager().
+ getSharesWithForAFile(mRemotePath,
+ getStorageManager().getAccount().name);
+ if (sharesWith.size() == 1) {
+ file.setShareViaUsers(false);
+ }
+ }
+
+ getStorageManager().saveFile(file);
+ 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 {
+ result = new RemoteOperationResult(ResultCode.SHARE_NOT_FOUND);
+ }
+
+ return result;
+ }
+
+ private boolean existsFile(OwnCloudClient client, String remotePath){
+ ExistenceCheckRemoteOperation existsOperation =
+ new ExistenceCheckRemoteOperation(remotePath, mContext, false);
+ RemoteOperationResult result = existsOperation.execute(client);
+ return result.isSuccess();
+ }
+
+}
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.operations.UnshareOperation;
import com.owncloud.android.operations.common.SyncOperation;
import java.io.IOException;
public static final String EXTRA_NEW_PARENT_PATH = "NEW_PARENT_PATH";
public static final String EXTRA_FILE = "FILE";
public static final String EXTRA_PASSWORD_SHARE = "PASSWORD_SHARE";
+ public static final String EXTRA_SHARE_TYPE = "SHARE_TYPE";
+ public static final String EXTRA_SHARE_WITH = "SHARE_WITH";
public static final String EXTRA_COOKIE = "COOKIE";
} else if (action.equals(ACTION_UNSHARE)) { // Unshare file
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
+ ShareType shareType = (ShareType) operationIntent.
+ getSerializableExtra(EXTRA_SHARE_TYPE);
+ String shareWith = operationIntent.getStringExtra(EXTRA_SHARE_WITH);
if (remotePath.length() > 0) {
- operation = new UnshareLinkOperation(
- remotePath,
+ operation = new UnshareOperation(
+ remotePath,
+ shareType,
+ shareWith,
OperationsService.this);
}
import com.owncloud.android.operations.CreateShareOperation;
import com.owncloud.android.operations.SynchronizeFileOperation;
import com.owncloud.android.operations.SynchronizeFolderOperation;
-import com.owncloud.android.operations.UnshareLinkOperation;
+import com.owncloud.android.operations.UnshareOperation;
import com.owncloud.android.services.OperationsService;
import com.owncloud.android.services.OperationsService.OperationsServiceBinder;
import com.owncloud.android.ui.NavigationDrawerItem;
} else if (operation instanceof CreateShareOperation) {
onCreateShareOperationFinish((CreateShareOperation) operation, result);
- } else if (operation instanceof UnshareLinkOperation) {
- onUnshareLinkOperationFinish((UnshareLinkOperation)operation, result);
+ } else if (operation instanceof UnshareOperation) {
+ onUnshareLinkOperationFinish((UnshareOperation)operation, result);
} else if (operation instanceof SynchronizeFolderOperation) {
onSynchronizeFolderOperationFinish((SynchronizeFolderOperation)operation, result);
}
- private void onUnshareLinkOperationFinish(UnshareLinkOperation operation,
+ private void onUnshareLinkOperationFinish(UnshareOperation operation,
RemoteOperationResult result) {
dismissLoadingDialog();
import com.owncloud.android.operations.RemoveFileOperation;
import com.owncloud.android.operations.RenameFileOperation;
import com.owncloud.android.operations.SynchronizeFileOperation;
-import com.owncloud.android.operations.UnshareLinkOperation;
+import com.owncloud.android.operations.UnshareOperation;
import com.owncloud.android.services.observer.FileObserverService;
import com.owncloud.android.syncadapter.FileSyncAdapter;
import com.owncloud.android.ui.dialog.ConfirmationDialogFragment;
} else if (operation instanceof CreateShareOperation) {
onCreateShareOperationFinish((CreateShareOperation) operation, result);
- } else if (operation instanceof UnshareLinkOperation) {
- onUnshareLinkOperationFinish((UnshareLinkOperation) operation, result);
+ } else if (operation instanceof UnshareOperation) {
+ onUnshareLinkOperationFinish((UnshareOperation) operation, result);
} else if (operation instanceof MoveFileOperation) {
onMoveFileOperationFinish((MoveFileOperation) operation, result);
}
}
- private void onUnshareLinkOperationFinish(UnshareLinkOperation operation,
+ private void onUnshareLinkOperationFinish(UnshareOperation operation,
RemoteOperationResult result) {
if (result.isSuccess()) {
refreshShowDetails();
import com.owncloud.android.operations.CreateShareOperation;
import com.owncloud.android.operations.RemoveFileOperation;
import com.owncloud.android.operations.SynchronizeFileOperation;
-import com.owncloud.android.operations.UnshareLinkOperation;
+import com.owncloud.android.operations.UnshareOperation;
import com.owncloud.android.ui.activity.FileActivity;
import com.owncloud.android.ui.activity.FileDisplayActivity;
import com.owncloud.android.ui.activity.ShareActivity;
if (operation instanceof CreateShareOperation) {
onCreateShareOperationFinish((CreateShareOperation) operation, result);
- } else if (operation instanceof UnshareLinkOperation) {
- onUnshareLinkOperationFinish((UnshareLinkOperation) operation, result);
+ } else if (operation instanceof UnshareOperation) {
+ onUnshareLinkOperationFinish((UnshareOperation) operation, result);
} else if (operation instanceof RemoveFileOperation) {
finish();
}
- private void onUnshareLinkOperationFinish(UnshareLinkOperation operation,
+ private void onUnshareLinkOperationFinish(UnshareOperation operation,
RemoteOperationResult result) {
if (result.isSuccess()) {
OCFile file = getStorageManager().getFileByPath(getFile().getRemotePath());
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.operations.UnshareOperation;
import com.owncloud.android.operations.UploadFileOperation;
import org.apache.commons.httpclient.ConnectTimeoutException;
message = res.getString(R.string.share_link_file_error);
}
- } else if (operation instanceof UnshareLinkOperation) {
+ } else if (operation instanceof UnshareOperation) {
if (result.getCode() == ResultCode.SHARE_NOT_FOUND) { // Error --> SHARE_NOT_FOUND
message = res.getString(R.string.unshare_link_file_no_exist);