Search in sources :

Example 1 with GetSharesForFileRemoteOperation

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

the class RefreshFolderOperation method refreshSharesForFolder.

/**
 * Syncs the Share resources for the files contained in the folder refreshed (children, not deeper descendants).
 *
 * @param client    Handler of a session with an OC server.
 * @return The result of the remote operation retrieving the Share resources in the folder refreshed by
 *                  the operation.
 */
private RemoteOperationResult refreshSharesForFolder(OwnCloudClient client) {
    RemoteOperationResult result;
    // remote request
    GetSharesForFileRemoteOperation operation = new GetSharesForFileRemoteOperation(mLocalFolder.getRemotePath(), true, true);
    result = operation.execute(client);
    if (result.isSuccess()) {
        // update local database
        ArrayList<OCShare> shares = new ArrayList<>();
        OCShare share;
        for (Object obj : result.getData()) {
            share = (OCShare) obj;
            if (!ShareType.NO_SHARED.equals(share.getShareType())) {
                shares.add(share);
            }
        }
        mStorageManager.saveSharesInFolder(shares, mLocalFolder);
    }
    return result;
}
Also used : RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) OCShare(com.owncloud.android.lib.resources.shares.OCShare) ArrayList(java.util.ArrayList) GetSharesForFileRemoteOperation(com.owncloud.android.lib.resources.shares.GetSharesForFileRemoteOperation)

Example 2 with GetSharesForFileRemoteOperation

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

the class GetSharesForFileOperation method run.

@Override
protected RemoteOperationResult run(OwnCloudClient client) {
    GetSharesForFileRemoteOperation operation = new GetSharesForFileRemoteOperation(path, reshares, subfiles);
    RemoteOperationResult result = operation.execute(client);
    if (result.isSuccess()) {
        // Update DB with the response
        Log_OC.d(TAG, "File = " + path + " Share list size  " + result.getData().size());
        ArrayList<OCShare> shares = new ArrayList<OCShare>();
        for (Object obj : result.getData()) {
            shares.add((OCShare) obj);
        }
        getStorageManager().saveSharesDB(shares);
    } else if (result.getCode() == RemoteOperationResult.ResultCode.SHARE_NOT_FOUND) {
        // no share on the file - remove local shares
        getStorageManager().removeSharesForFile(path);
    }
    return result;
}
Also used : RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) OCShare(com.owncloud.android.lib.resources.shares.OCShare) ArrayList(java.util.ArrayList) GetSharesForFileRemoteOperation(com.owncloud.android.lib.resources.shares.GetSharesForFileRemoteOperation)

Aggregations

RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)2 GetSharesForFileRemoteOperation (com.owncloud.android.lib.resources.shares.GetSharesForFileRemoteOperation)2 OCShare (com.owncloud.android.lib.resources.shares.OCShare)2 ArrayList (java.util.ArrayList)2