use of com.owncloud.android.lib.resources.users.Status in project android by nextcloud.
the class DialogFragmentIT method testAccountChooserDialog.
@Test
@ScreenshotTest
public void testAccountChooserDialog() throws AccountUtils.AccountNotFoundException {
FileDisplayActivity activity = getFileDisplayActivity();
UserAccountManager userAccountManager = activity.getUserAccountManager();
AccountManager accountManager = AccountManager.get(targetContext);
for (Account account : accountManager.getAccountsByType(MainApp.getAccountType(targetContext))) {
accountManager.removeAccountExplicitly(account);
}
Account newAccount = new Account("test@https://nextcloud.localhost", MainApp.getAccountType(targetContext));
accountManager.addAccountExplicitly(newAccount, "password", null);
accountManager.setUserData(newAccount, AccountUtils.Constants.KEY_OC_BASE_URL, SERVER_URL);
accountManager.setUserData(newAccount, AccountUtils.Constants.KEY_USER_ID, "test");
accountManager.setAuthToken(newAccount, AccountTypeUtils.getAuthTokenTypePass(newAccount.type), "password");
User newUser = userAccountManager.getUser(newAccount.name).orElseThrow(RuntimeException::new);
Account newAccount2 = new Account("user1@nextcloud.localhost", MainApp.getAccountType(targetContext));
accountManager.addAccountExplicitly(newAccount2, "password", null);
accountManager.setUserData(newAccount2, AccountUtils.Constants.KEY_OC_BASE_URL, SERVER_URL);
accountManager.setUserData(newAccount2, AccountUtils.Constants.KEY_USER_ID, "user1");
accountManager.setUserData(newAccount2, AccountUtils.Constants.KEY_OC_VERSION, "20.0.0");
accountManager.setAuthToken(newAccount2, AccountTypeUtils.getAuthTokenTypePass(newAccount.type), "password");
FileDataStorageManager fileDataStorageManager = new FileDataStorageManager(newUser, targetContext.getContentResolver());
OCCapability capability = new OCCapability();
capability.setUserStatus(CapabilityBooleanType.TRUE);
capability.setUserStatusSupportsEmoji(CapabilityBooleanType.TRUE);
fileDataStorageManager.saveCapabilities(capability);
ChooseAccountDialogFragment sut = ChooseAccountDialogFragment.newInstance(new RegisteredUser(newAccount, new OwnCloudAccount(newAccount, targetContext), new Server(URI.create(SERVER_URL), OwnCloudVersion.nextcloud_20)));
showDialog(activity, sut);
activity.runOnUiThread(() -> sut.setStatus(new Status(StatusType.DND, "Busy fixing 🐛…", "", -1), targetContext));
waitForIdleSync();
shortSleep();
screenshot(sut, "dnd");
activity.runOnUiThread(() -> sut.setStatus(new Status(StatusType.ONLINE, "", "", -1), targetContext));
waitForIdleSync();
shortSleep();
screenshot(sut, "online");
activity.runOnUiThread(() -> sut.setStatus(new Status(StatusType.ONLINE, "Let's have some fun", "🎉", -1), targetContext));
waitForIdleSync();
shortSleep();
screenshot(sut, "fun");
activity.runOnUiThread(() -> sut.setStatus(new Status(StatusType.OFFLINE, "", "", -1), targetContext));
waitForIdleSync();
shortSleep();
screenshot(sut, "offline");
activity.runOnUiThread(() -> sut.setStatus(new Status(StatusType.AWAY, "Vacation", "🌴", -1), targetContext));
waitForIdleSync();
shortSleep();
screenshot(sut, "away");
}
use of com.owncloud.android.lib.resources.users.Status in project android by nextcloud.
the class BitmapUtils method createAvatarWithStatus.
public static Bitmap createAvatarWithStatus(Bitmap avatar, StatusType statusType, String icon, Context context) {
float avatarRadius = getResources().getDimension(R.dimen.list_item_avatar_icon_radius);
int width = DisplayUtils.convertDpToPixel(2 * avatarRadius, context);
Bitmap output = Bitmap.createBitmap(width, width, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);
// avatar
Bitmap croppedBitmap = getCroppedBitmap(avatar, width);
canvas.drawBitmap(croppedBitmap, 0f, 0f, null);
// status
int statusSize = width / 4;
Status status = new Status(statusType, "", icon, -1);
StatusDrawable statusDrawable = new StatusDrawable(status, statusSize, context);
canvas.translate(width / 2f, width / 2f);
statusDrawable.draw(canvas);
return output;
}
use of com.owncloud.android.lib.resources.users.Status 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;
}
Aggregations