Search in sources :

Example 1 with RemoveRemoteShareOperation

use of com.owncloud.android.lib.resources.shares.RemoveRemoteShareOperation in project android by owncloud.

the class UnshareOperation method run.

@Override
protected RemoteOperationResult run(OwnCloudClient client) {
    RemoteOperationResult result = null;
    // Get Share for a file
    OCShare share = getStorageManager().getFirstShareByPathAndType(mRemotePath, mShareType, mShareWith);
    if (share != null) {
        OCFile file = getStorageManager().getFileByPath(mRemotePath);
        RemoveRemoteShareOperation operation = new RemoveRemoteShareOperation((int) share.getRemoteId());
        result = operation.execute(client);
        if (result.isSuccess()) {
            Log_OC.d(TAG, "Share id = " + share.getRemoteId() + " deleted");
            if (ShareType.PUBLIC_LINK.equals(mShareType)) {
                file.setShareViaLink(false);
                file.setPublicLink("");
            } else if (ShareType.USER.equals(mShareType) || ShareType.GROUP.equals(mShareType) || ShareType.FEDERATED.equals(mShareType)) {
                // Check if it is the last share
                ArrayList<OCShare> sharesWith = getStorageManager().getSharesWithForAFile(mRemotePath, getStorageManager().getAccount().name);
                if (sharesWith.size() == 1) {
                    file.setShareWithSharee(false);
                }
            }
            getStorageManager().saveFile(file);
            getStorageManager().removeShare(share);
        } else if (result.getCode() != ResultCode.SERVICE_UNAVAILABLE && !existsFile(client, file.getRemotePath())) {
            // unshare failed because file was deleted before
            getStorageManager().removeFile(file, true, true);
        }
    } else {
        result = new RemoteOperationResult(ResultCode.SHARE_NOT_FOUND);
    }
    return result;
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) RemoveRemoteShareOperation(com.owncloud.android.lib.resources.shares.RemoveRemoteShareOperation) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) OCShare(com.owncloud.android.lib.resources.shares.OCShare) ArrayList(java.util.ArrayList)

Aggregations

OCFile (com.owncloud.android.datamodel.OCFile)1 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)1 OCShare (com.owncloud.android.lib.resources.shares.OCShare)1 RemoveRemoteShareOperation (com.owncloud.android.lib.resources.shares.RemoveRemoteShareOperation)1 ArrayList (java.util.ArrayList)1