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);
}
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;
}
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);
}
Aggregations