Search in sources :

Example 6 with ShareType

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

the class FileContentProvider method updateFilesTableAccordingToShareInsertion.

private void updateFilesTableAccordingToShareInsertion(SQLiteDatabase db, ContentValues newShare) {
    ContentValues fileValues = new ContentValues();
    ShareType newShareType = ShareType.fromValue(newShare.getAsInteger(ProviderTableMeta.OCSHARES_SHARE_TYPE));
    switch(newShareType) {
        case PUBLIC_LINK:
            fileValues.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, 1);
            break;
        case USER:
        case GROUP:
        case EMAIL:
        case FEDERATED:
        case FEDERATED_GROUP:
        case ROOM:
        case CIRCLE:
        case DECK:
        case GUEST:
            fileValues.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, 1);
            break;
        default:
    }
    String where = ProviderTableMeta.FILE_PATH + "=? AND " + ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?";
    String[] whereArgs = new String[] { newShare.getAsString(ProviderTableMeta.OCSHARES_PATH), newShare.getAsString(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER) };
    db.update(ProviderTableMeta.FILE_TABLE_NAME, fileValues, where, whereArgs);
}
Also used : ContentValues(android.content.ContentValues) ShareType(com.owncloud.android.lib.resources.shares.ShareType)

Example 7 with ShareType

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

the class UsersAndGroupsSearchProvider method searchForUsersOrGroups.

private Cursor searchForUsersOrGroups(Uri uri) {
    String lastPathSegment = uri.getLastPathSegment();
    if (lastPathSegment == null) {
        throw new IllegalArgumentException("Wrong URI passed!");
    }
    // need to trust on the AccountUtils to get the current account since the query in the client side is not
    // directly started by our code, but from SearchView implementation
    User user = accountManager.getUser();
    String userQuery = lastPathSegment.toLowerCase(Locale.ROOT);
    // request to the OC server about users and groups matching userQuery
    GetShareesRemoteOperation searchRequest = new GetShareesRemoteOperation(userQuery, REQUESTED_PAGE, RESULTS_PER_PAGE);
    RemoteOperationResult result = searchRequest.execute(user.toPlatformAccount(), getContext());
    List<JSONObject> names = new ArrayList<>();
    if (result.isSuccess()) {
        for (Object o : result.getData()) {
            names.add((JSONObject) o);
        }
    } else {
        showErrorMessage(result);
    }
    MatrixCursor response = null;
    // convert the responses from the OC server to the expected format
    if (names.size() > 0) {
        if (getContext() == null) {
            throw new IllegalArgumentException("Context may not be null!");
        }
        response = new MatrixCursor(COLUMNS);
        Uri userBaseUri = new Uri.Builder().scheme(CONTENT).authority(DATA_USER).build();
        Uri groupBaseUri = new Uri.Builder().scheme(CONTENT).authority(DATA_GROUP).build();
        Uri roomBaseUri = new Uri.Builder().scheme(CONTENT).authority(DATA_ROOM).build();
        Uri remoteBaseUri = new Uri.Builder().scheme(CONTENT).authority(DATA_REMOTE).build();
        Uri emailBaseUri = new Uri.Builder().scheme(CONTENT).authority(DATA_EMAIL).build();
        Uri circleBaseUri = new Uri.Builder().scheme(CONTENT).authority(DATA_CIRCLE).build();
        FileDataStorageManager manager = new FileDataStorageManager(user, getContext().getContentResolver());
        boolean federatedShareAllowed = manager.getCapability(user.getAccountName()).getFilesSharingFederationOutgoing().isTrue();
        try {
            Iterator<JSONObject> namesIt = names.iterator();
            JSONObject item;
            String displayName;
            String subline = null;
            Object icon = 0;
            Uri dataUri;
            int count = 0;
            while (namesIt.hasNext()) {
                item = namesIt.next();
                dataUri = null;
                displayName = null;
                String userName = item.getString(GetShareesRemoteOperation.PROPERTY_LABEL);
                String name = item.isNull("name") ? "" : item.getString("name");
                JSONObject value = item.getJSONObject(GetShareesRemoteOperation.NODE_VALUE);
                ShareType type = ShareType.fromValue(value.getInt(GetShareesRemoteOperation.PROPERTY_SHARE_TYPE));
                String shareWith = value.getString(GetShareesRemoteOperation.PROPERTY_SHARE_WITH);
                Status status;
                JSONObject statusObject = item.optJSONObject(PROPERTY_STATUS);
                if (statusObject != null) {
                    status = new Status(StatusType.valueOf(statusObject.getString(PROPERTY_STATUS).toUpperCase(Locale.US)), statusObject.isNull(PROPERTY_MESSAGE) ? "" : statusObject.getString(PROPERTY_MESSAGE), statusObject.isNull(PROPERTY_ICON) ? "" : statusObject.getString(PROPERTY_ICON), statusObject.isNull(PROPERTY_CLEAR_AT) ? -1 : statusObject.getLong(PROPERTY_CLEAR_AT));
                } else {
                    status = new Status(StatusType.OFFLINE, "", "", -1);
                }
                switch(type) {
                    case GROUP:
                        displayName = userName;
                        icon = R.drawable.ic_group;
                        dataUri = Uri.withAppendedPath(groupBaseUri, shareWith);
                        break;
                    case FEDERATED:
                        if (federatedShareAllowed) {
                            icon = R.drawable.ic_user;
                            dataUri = Uri.withAppendedPath(remoteBaseUri, shareWith);
                            if (userName.equals(shareWith)) {
                                displayName = name;
                                subline = getContext().getString(R.string.remote);
                            } else {
                                String[] uriSplitted = shareWith.split("@");
                                displayName = name;
                                subline = getContext().getString(R.string.share_known_remote_on_clarification, uriSplitted[uriSplitted.length - 1]);
                            }
                        }
                        break;
                    case USER:
                        displayName = userName;
                        subline = (status.getMessage() == null || status.getMessage().isEmpty()) ? null : status.getMessage();
                        Uri.Builder builder = Uri.parse("content://com.nextcloud.android.providers.UsersAndGroupsSearchProvider/icon").buildUpon();
                        builder.appendQueryParameter("shareWith", shareWith);
                        builder.appendQueryParameter("displayName", displayName);
                        builder.appendQueryParameter("status", status.getStatus().toString());
                        if (!TextUtils.isEmpty(status.getIcon()) && !"null".equals(status.getIcon())) {
                            builder.appendQueryParameter("icon", status.getIcon());
                        }
                        icon = builder.build();
                        dataUri = Uri.withAppendedPath(userBaseUri, shareWith);
                        break;
                    case EMAIL:
                        icon = R.drawable.ic_email;
                        displayName = name;
                        subline = shareWith;
                        dataUri = Uri.withAppendedPath(emailBaseUri, shareWith);
                        break;
                    case ROOM:
                        icon = R.drawable.ic_talk;
                        displayName = userName;
                        dataUri = Uri.withAppendedPath(roomBaseUri, shareWith);
                        break;
                    case CIRCLE:
                        icon = R.drawable.ic_circles;
                        displayName = userName;
                        dataUri = Uri.withAppendedPath(circleBaseUri, shareWith);
                        break;
                    default:
                        break;
                }
                if (displayName != null && dataUri != null) {
                    response.newRow().add(// BaseColumns._ID
                    count++).add(// SearchManager.SUGGEST_COLUMN_TEXT_1
                    displayName).add(// SearchManager.SUGGEST_COLUMN_TEXT_2
                    subline).add(// SearchManager.SUGGEST_COLUMN_ICON_1
                    icon).add(dataUri);
                }
            }
        } catch (JSONException e) {
            Log_OC.e(TAG, "Exception while parsing data of users/groups", e);
        }
    }
    return response;
}
Also used : Status(com.owncloud.android.lib.resources.users.Status) User(com.nextcloud.client.account.User) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) GetShareesRemoteOperation(com.owncloud.android.lib.resources.shares.GetShareesRemoteOperation) Uri(android.net.Uri) MatrixCursor(android.database.MatrixCursor) JSONObject(org.json.JSONObject) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) JSONObject(org.json.JSONObject) ShareType(com.owncloud.android.lib.resources.shares.ShareType)

Example 8 with ShareType

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

the class OCFileListAdapter method parseShares.

private void parseShares(List<Object> objects) {
    List<OCShare> shares = new ArrayList<>();
    for (Object shareObject : objects) {
        // check type before cast as of long running data fetch it is possible that old result is filled
        if (shareObject instanceof OCShare) {
            OCShare ocShare = (OCShare) shareObject;
            shares.add(ocShare);
            // get ocFile from Server to have an up-to-date copy
            RemoteOperationResult result = new ReadFileRemoteOperation(ocShare.getPath()).execute(user.toPlatformAccount(), activity);
            if (result.isSuccess()) {
                OCFile file = FileStorageUtils.fillOCFile((RemoteFile) result.getData().get(0));
                FileStorageUtils.searchForLocalFileInDefaultPath(file, user.getAccountName());
                file = mStorageManager.saveFileWithParent(file, activity);
                ShareType newShareType = ocShare.getShareType();
                if (newShareType == ShareType.PUBLIC_LINK) {
                    file.setSharedViaLink(true);
                } else if (newShareType == ShareType.USER || newShareType == ShareType.GROUP || newShareType == ShareType.EMAIL || newShareType == ShareType.FEDERATED || newShareType == ShareType.ROOM || newShareType == ShareType.CIRCLE) {
                    file.setSharedWithSharee(true);
                }
                mStorageManager.saveFile(file);
                if (!mFiles.contains(file)) {
                    mFiles.add(file);
                }
            } else {
                Log_OC.e(TAG, "Error in getting prop for file: " + ocShare.getPath());
            }
        }
    }
    mStorageManager.saveShares(shares);
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) OCShare(com.owncloud.android.lib.resources.shares.OCShare) ArrayList(java.util.ArrayList) ReadFileRemoteOperation(com.owncloud.android.lib.resources.files.ReadFileRemoteOperation) ShareType(com.owncloud.android.lib.resources.shares.ShareType)

Aggregations

ShareType (com.owncloud.android.lib.resources.shares.ShareType)8 ArrayList (java.util.ArrayList)4 OCFile (com.owncloud.android.datamodel.OCFile)3 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)3 OCShare (com.owncloud.android.lib.resources.shares.OCShare)3 Uri (android.net.Uri)2 User (com.nextcloud.client.account.User)2 FileDataStorageManager (com.owncloud.android.datamodel.FileDataStorageManager)2 Account (android.accounts.Account)1 ContentValues (android.content.ContentValues)1 MatrixCursor (android.database.MatrixCursor)1 Pair (android.util.Pair)1 OwnCloudAccount (com.owncloud.android.lib.common.OwnCloudAccount)1 RemoteOperation (com.owncloud.android.lib.common.operations.RemoteOperation)1 ReadFileRemoteOperation (com.owncloud.android.lib.resources.files.ReadFileRemoteOperation)1 ReadRemoteFileOperation (com.owncloud.android.lib.resources.files.ReadRemoteFileOperation)1 RestoreFileVersionRemoteOperation (com.owncloud.android.lib.resources.files.RestoreFileVersionRemoteOperation)1 FileVersion (com.owncloud.android.lib.resources.files.model.FileVersion)1 GetShareesRemoteOperation (com.owncloud.android.lib.resources.shares.GetShareesRemoteOperation)1 GetUserInfoRemoteOperation (com.owncloud.android.lib.resources.users.GetUserInfoRemoteOperation)1