Search in sources :

Example 11 with OCShare

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

the class FileDataStorageManager method saveSharesDB.

public void saveSharesDB(ArrayList<OCShare> shares) {
    ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>();
    // Reset flags & Remove shares for this files
    String filePath = "";
    for (OCShare share : shares) {
        if (filePath != share.getPath()) {
            filePath = share.getPath();
            resetShareFlagInAFile(filePath);
            operations = prepareRemoveSharesInFile(filePath, operations);
        }
    }
    // Add operations to insert shares
    operations = prepareInsertShares(shares, operations);
    // apply operations in batch
    if (operations.size() > 0) {
        Log_OC.d(TAG, "Sending " + operations.size() + " operations to FileContentProvider");
        try {
            if (getContentResolver() != null) {
                getContentResolver().applyBatch(MainApp.getAuthority(), operations);
            } else {
                getContentProviderClient().applyBatch(operations);
            }
        } catch (OperationApplicationException e) {
            Log_OC.e(TAG, "Exception in batch of operations " + e.getMessage());
        } catch (RemoteException e) {
            Log_OC.e(TAG, "Exception in batch of operations  " + e.getMessage());
        }
    }
//        // TODO: review if it is needed
//        // Update shared files
//        ArrayList<OCFile> sharedFiles = new ArrayList<OCFile>();
//
//        for (OCShare share : shares) {
//            // Get the path
//            String path = share.getPath();
//            if (share.isFolder()) {
//                path = path + FileUtils.PATH_SEPARATOR;
//            }
//
//            // Update OCFile with data from share: ShareByLink, publicLink and
//            OCFile file = getFileByPath(path);
//            if (file != null) {
//                if (share.getShareType().equals(ShareType.PUBLIC_LINK)) {
//                    file.setShareViaLink(true);
//                    sharedFiles.add(file);
//                }
//            }
//        }
//
//        // TODO: Review
//        updateSharedFiles(sharedFiles);
}
Also used : ContentProviderOperation(android.content.ContentProviderOperation) ArrayList(java.util.ArrayList) OCShare(com.owncloud.android.lib.resources.shares.OCShare) RemoteException(android.os.RemoteException) OperationApplicationException(android.content.OperationApplicationException)

Example 12 with OCShare

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

the class UpdateShareViaLinkOperation method run.

@Override
protected RemoteOperationResult run(OwnCloudClient client) {
    OCShare publicShare = getStorageManager().getFirstShareByPathAndType(mPath, ShareType.PUBLIC_LINK, "");
    if (publicShare == null) {
        // TODO try to get remote share before failing?
        return new RemoteOperationResult(RemoteOperationResult.ResultCode.SHARE_NOT_FOUND);
    }
    // Update remote share with password
    UpdateRemoteShareOperation updateOp = new UpdateRemoteShareOperation(publicShare.getRemoteId());
    updateOp.setPassword(mPassword);
    updateOp.setExpirationDate(mExpirationDateInMillis);
    updateOp.setPublicUpload(mPublicUpload);
    RemoteOperationResult result = updateOp.execute(client);
    if (result.isSuccess()) {
        // Retrieve updated share / save directly with password? -> no; the password is not to be saved
        RemoteOperation getShareOp = new GetRemoteShareOperation(publicShare.getRemoteId());
        result = getShareOp.execute(client);
        if (result.isSuccess()) {
            OCShare share = (OCShare) result.getData().get(0);
            updateData(share);
        }
    }
    return result;
}
Also used : RemoteOperation(com.owncloud.android.lib.common.operations.RemoteOperation) GetRemoteShareOperation(com.owncloud.android.lib.resources.shares.GetRemoteShareOperation) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) UpdateRemoteShareOperation(com.owncloud.android.lib.resources.shares.UpdateRemoteShareOperation) OCShare(com.owncloud.android.lib.resources.shares.OCShare)

Example 13 with OCShare

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

the class FileDataStorageManager method getSharesWithForAFile.

public ArrayList<OCShare> getSharesWithForAFile(String filePath, String accountName) {
    // Condition
    String where = ProviderTableMeta.OCSHARES_PATH + "=?" + " AND " + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?" + "AND" + " (" + ProviderTableMeta.OCSHARES_SHARE_TYPE + "=? OR " + ProviderTableMeta.OCSHARES_SHARE_TYPE + "=? OR " + ProviderTableMeta.OCSHARES_SHARE_TYPE + "=? ) ";
    String[] whereArgs = new String[] { filePath, accountName, Integer.toString(ShareType.USER.getValue()), Integer.toString(ShareType.GROUP.getValue()), Integer.toString(ShareType.FEDERATED.getValue()) };
    Cursor c = null;
    if (getContentResolver() != null) {
        c = getContentResolver().query(ProviderTableMeta.CONTENT_URI_SHARE, null, where, whereArgs, null);
    } else {
        try {
            c = getContentProviderClient().query(ProviderTableMeta.CONTENT_URI_SHARE, null, where, whereArgs, null);
        } catch (RemoteException e) {
            Log_OC.e(TAG, "Could not get list of shares with: " + e.getMessage());
            c = null;
        }
    }
    ArrayList<OCShare> shares = new ArrayList<OCShare>();
    OCShare share = null;
    if (c != null) {
        if (c.moveToFirst()) {
            do {
                share = createShareInstance(c);
                shares.add(share);
            // }
            } while (c.moveToNext());
        }
        c.close();
    }
    return shares;
}
Also used : ArrayList(java.util.ArrayList) OCShare(com.owncloud.android.lib.resources.shares.OCShare) Cursor(android.database.Cursor) RemoteException(android.os.RemoteException)

Example 14 with OCShare

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

the class GetSharesForFileOperation method run.

@Override
protected RemoteOperationResult run(OwnCloudClient client) {
    GetRemoteSharesForFileOperation operation = new GetRemoteSharesForFileOperation(mPath, mReshares, mSubfiles);
    RemoteOperationResult result = operation.execute(client);
    if (result.isSuccess()) {
        // Update DB with the response
        Log_OC.d(TAG, "File = " + mPath + " 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(mPath);
    }
    return result;
}
Also used : RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) ArrayList(java.util.ArrayList) OCShare(com.owncloud.android.lib.resources.shares.OCShare) GetRemoteSharesForFileOperation(com.owncloud.android.lib.resources.shares.GetRemoteSharesForFileOperation)

Example 15 with OCShare

use of com.owncloud.android.lib.resources.shares.OCShare 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

OCShare (com.owncloud.android.lib.resources.shares.OCShare)16 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)7 ArrayList (java.util.ArrayList)6 RemoteException (android.os.RemoteException)4 Cursor (android.database.Cursor)3 RemoteOperation (com.owncloud.android.lib.common.operations.RemoteOperation)3 GetRemoteSharesForFileOperation (com.owncloud.android.lib.resources.shares.GetRemoteSharesForFileOperation)3 ContentProviderOperation (android.content.ContentProviderOperation)2 ContentValues (android.content.ContentValues)2 OperationApplicationException (android.content.OperationApplicationException)2 CreateRemoteShareOperation (com.owncloud.android.lib.resources.shares.CreateRemoteShareOperation)2 GetRemoteShareOperation (com.owncloud.android.lib.resources.shares.GetRemoteShareOperation)2 UpdateRemoteShareOperation (com.owncloud.android.lib.resources.shares.UpdateRemoteShareOperation)2 ContentProviderResult (android.content.ContentProviderResult)1 Intent (android.content.Intent)1 Drawable (android.graphics.drawable.Drawable)1 Snackbar (android.support.design.widget.Snackbar)1 DialogFragment (android.support.v4.app.DialogFragment)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1