Search in sources :

Example 1 with CreateRemoteShareOperation

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

the class CreateShareViaLinkOperation method run.

@Override
protected RemoteOperationResult run(OwnCloudClient client) {
    // Check if the share link already exists
    RemoteOperation operation = new GetRemoteSharesForFileOperation(mPath, false, false);
    RemoteOperationResult result = operation.execute(client);
    // Create public link if doesn't exist yet
    boolean publicShareExists = false;
    if (result.isSuccess()) {
        OCShare share = null;
        for (int i = 0; i < result.getData().size(); i++) {
            share = (OCShare) result.getData().get(i);
            if (ShareType.PUBLIC_LINK.equals(share.getShareType())) {
                publicShareExists = true;
                break;
            }
        }
    }
    if (!publicShareExists) {
        CreateRemoteShareOperation createOp = new CreateRemoteShareOperation(mPath, ShareType.PUBLIC_LINK, "", false, mPassword, OCShare.DEFAULT_PERMISSION);
        createOp.setGetShareDetails(true);
        result = createOp.execute(client);
    }
    if (result.isSuccess()) {
        if (result.getData().size() > 0) {
            Object item = result.getData().get(0);
            if (item instanceof OCShare) {
                updateData((OCShare) item);
            } else {
                ArrayList<Object> data = result.getData();
                result = new RemoteOperationResult(RemoteOperationResult.ResultCode.SHARE_NOT_FOUND);
                result.setData(data);
            }
        } else {
            result = new RemoteOperationResult(RemoteOperationResult.ResultCode.SHARE_NOT_FOUND);
        }
    }
    return result;
}
Also used : CreateRemoteShareOperation(com.owncloud.android.lib.resources.shares.CreateRemoteShareOperation) RemoteOperation(com.owncloud.android.lib.common.operations.RemoteOperation) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) OCShare(com.owncloud.android.lib.resources.shares.OCShare) GetRemoteSharesForFileOperation(com.owncloud.android.lib.resources.shares.GetRemoteSharesForFileOperation)

Example 2 with CreateRemoteShareOperation

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

the class CreateShareWithShareeOperation method run.

@Override
protected RemoteOperationResult run(OwnCloudClient client) {
    CreateRemoteShareOperation operation = new CreateRemoteShareOperation(mPath, mShareType, mShareeName, false, "", mPermissions);
    operation.setGetShareDetails(true);
    RemoteOperationResult result = operation.execute(client);
    if (result.isSuccess()) {
        if (result.getData().size() > 0) {
            OCShare share = (OCShare) result.getData().get(0);
            updateData(share);
        }
    }
    return result;
}
Also used : CreateRemoteShareOperation(com.owncloud.android.lib.resources.shares.CreateRemoteShareOperation) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) OCShare(com.owncloud.android.lib.resources.shares.OCShare)

Aggregations

RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)2 CreateRemoteShareOperation (com.owncloud.android.lib.resources.shares.CreateRemoteShareOperation)2 OCShare (com.owncloud.android.lib.resources.shares.OCShare)2 RemoteOperation (com.owncloud.android.lib.common.operations.RemoteOperation)1 GetRemoteSharesForFileOperation (com.owncloud.android.lib.resources.shares.GetRemoteSharesForFileOperation)1