Search in sources :

Example 1 with Status

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");
}
Also used : Status(com.owncloud.android.lib.resources.users.Status) Account(android.accounts.Account) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) User(com.nextcloud.client.account.User) RegisteredUser(com.nextcloud.client.account.RegisteredUser) OCCapability(com.owncloud.android.lib.resources.status.OCCapability) Server(com.nextcloud.client.account.Server) ChooseAccountDialogFragment(com.nextcloud.ui.ChooseAccountDialogFragment) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) RegisteredUser(com.nextcloud.client.account.RegisteredUser) UserAccountManager(com.nextcloud.client.account.UserAccountManager) FileDisplayActivity(com.owncloud.android.ui.activity.FileDisplayActivity) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) UserAccountManager(com.nextcloud.client.account.UserAccountManager) AccountManager(android.accounts.AccountManager) ScreenshotTest(com.owncloud.android.utils.ScreenshotTest) Test(org.junit.Test) ScreenshotTest(com.owncloud.android.utils.ScreenshotTest)

Example 2 with Status

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;
}
Also used : Status(com.owncloud.android.lib.resources.users.Status) Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) StatusDrawable(com.owncloud.android.ui.StatusDrawable) Paint(android.graphics.Paint)

Example 3 with Status

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

Aggregations

Status (com.owncloud.android.lib.resources.users.Status)3 User (com.nextcloud.client.account.User)2 FileDataStorageManager (com.owncloud.android.datamodel.FileDataStorageManager)2 Account (android.accounts.Account)1 AccountManager (android.accounts.AccountManager)1 MatrixCursor (android.database.MatrixCursor)1 Bitmap (android.graphics.Bitmap)1 Canvas (android.graphics.Canvas)1 Paint (android.graphics.Paint)1 Uri (android.net.Uri)1 RegisteredUser (com.nextcloud.client.account.RegisteredUser)1 Server (com.nextcloud.client.account.Server)1 UserAccountManager (com.nextcloud.client.account.UserAccountManager)1 ChooseAccountDialogFragment (com.nextcloud.ui.ChooseAccountDialogFragment)1 OwnCloudAccount (com.owncloud.android.lib.common.OwnCloudAccount)1 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)1 GetShareesRemoteOperation (com.owncloud.android.lib.resources.shares.GetShareesRemoteOperation)1 ShareType (com.owncloud.android.lib.resources.shares.ShareType)1 OCCapability (com.owncloud.android.lib.resources.status.OCCapability)1 StatusDrawable (com.owncloud.android.ui.StatusDrawable)1