Search in sources :

Example 6 with UserInfo

use of com.owncloud.android.lib.common.UserInfo in project android by nextcloud.

the class UserInfoActivity method fetchAndSetData.

private void fetchAndSetData() {
    Thread t = new Thread(() -> {
        NextcloudClient nextcloudClient;
        try {
            nextcloudClient = OwnCloudClientFactory.createNextcloudClient(user.toPlatformAccount(), this);
        } catch (AccountUtils.AccountNotFoundException e) {
            Log_OC.e(this, "Error retrieving user info", e);
            return;
        }
        RemoteOperationResult<UserInfo> result = new GetUserInfoRemoteOperation().execute(nextcloudClient);
        if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) {
            if (result.isSuccess() && result.getResultData() != null) {
                userInfo = result.getResultData();
                runOnUiThread(() -> populateUserInfoUi(userInfo));
            } else {
                // show error
                runOnUiThread(() -> setErrorMessageForMultiList(getString(R.string.user_information_retrieval_error), result.getLogMessage(), R.drawable.ic_list_empty_error));
                Log_OC.d(TAG, result.getLogMessage());
            }
        }
    });
    t.start();
}
Also used : NextcloudClient(com.nextcloud.common.NextcloudClient) GetUserInfoRemoteOperation(com.owncloud.android.lib.resources.users.GetUserInfoRemoteOperation) AccountUtils(com.owncloud.android.lib.common.accounts.AccountUtils) UserInfo(com.owncloud.android.lib.common.UserInfo)

Example 7 with UserInfo

use of com.owncloud.android.lib.common.UserInfo in project android by nextcloud.

the class UserInfoActivityIT method fullUserInfoDetail.

@Test
@ScreenshotTest
public void fullUserInfoDetail() {
    final Intent intent = new Intent(targetContext, UserInfoActivity.class);
    intent.putExtra(UserInfoActivity.KEY_ACCOUNT, user);
    UserInfo userInfo = new UserInfo("test", true, "Firstname Familyname", "oss@rocks.com", "+49 7613 672 255", "Awesome Place Av.", "https://www.nextcloud.com", "nextclouders", null, null);
    intent.putExtra(UserInfoActivity.KEY_USER_DATA, userInfo);
    UserInfoActivity sut = activityRule.launchActivity(intent);
    shortSleep();
    shortSleep();
    screenshot(sut);
}
Also used : Intent(android.content.Intent) UserInfo(com.owncloud.android.lib.common.UserInfo) ScreenshotTest(com.owncloud.android.utils.ScreenshotTest) Test(org.junit.Test) ScreenshotTest(com.owncloud.android.utils.ScreenshotTest)

Example 8 with UserInfo

use of com.owncloud.android.lib.common.UserInfo in project android by nextcloud.

the class ManageAccountsActivityIT method userInfoDetail.

@Test
@ScreenshotTest
public void userInfoDetail() {
    ManageAccountsActivity sut = activityRule.launchActivity(null);
    User user = sut.accountManager.getUser();
    UserInfo userInfo = new UserInfo("test", true, "Test User", "test@nextcloud.com", "+49 123 456", "Address 123, Berlin", "https://www.nextcloud.com", "https://twitter.com/Nextclouders", new Quota(), new ArrayList<>());
    sut.showUser(user, userInfo);
    shortSleep();
    shortSleep();
    screenshot(getCurrentActivity());
}
Also used : User(com.nextcloud.client.account.User) Quota(com.owncloud.android.lib.common.Quota) UserInfo(com.owncloud.android.lib.common.UserInfo) ScreenshotTest(com.owncloud.android.utils.ScreenshotTest) Test(org.junit.Test) ScreenshotTest(com.owncloud.android.utils.ScreenshotTest)

Example 9 with UserInfo

use of com.owncloud.android.lib.common.UserInfo in project android by nextcloud.

the class GetUserProfileOperation method run.

/**
 * Performs the operation.
 *
 * Target user account is implicit in 'client'.
 *
 * Stored account is implicit in {@link #getStorageManager()}.
 *
 * @return      Result of the operation. If successful, includes an instance of
 *              {@link String} with the display name retrieved from the server.
 *              Call {@link RemoteOperationResult#getData()}.get(0) to get it.
 */
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
    // get display name
    GetRemoteUserInfoOperation getDisplayName = new GetRemoteUserInfoOperation();
    RemoteOperationResult result = getDisplayName.execute(client);
    if (result.isSuccess()) {
        // store display name with account data
        AccountManager accountManager = AccountManager.get(MainApp.getAppContext());
        UserInfo userInfo = (UserInfo) result.getData().get(0);
        Account storedAccount = getStorageManager().getAccount();
        accountManager.setUserData(storedAccount, AccountUtils.Constants.KEY_DISPLAY_NAME, userInfo.getDisplayName());
        accountManager.setUserData(storedAccount, AccountUtils.Constants.KEY_USER_ID, userInfo.getId());
    }
    return result;
}
Also used : Account(android.accounts.Account) GetRemoteUserInfoOperation(com.owncloud.android.lib.resources.users.GetRemoteUserInfoOperation) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) AccountManager(android.accounts.AccountManager) UserInfo(com.owncloud.android.lib.common.UserInfo)

Example 10 with UserInfo

use of com.owncloud.android.lib.common.UserInfo in project android by nextcloud.

the class UserAccountManagerImpl method migrateUserId.

public boolean migrateUserId() {
    Account[] ocAccounts = accountManager.getAccountsByType(MainApp.getAccountType(context));
    String userId;
    String displayName;
    GetUserInfoRemoteOperation remoteUserNameOperation = new GetUserInfoRemoteOperation();
    int failed = 0;
    for (Account account : ocAccounts) {
        String storedUserId = accountManager.getUserData(account, com.owncloud.android.lib.common.accounts.AccountUtils.Constants.KEY_USER_ID);
        if (!TextUtils.isEmpty(storedUserId)) {
            continue;
        }
        // add userId
        try {
            OwnCloudAccount ocAccount = new OwnCloudAccount(account, context);
            NextcloudClient nextcloudClient = OwnCloudClientManagerFactory.getDefaultSingleton().getNextcloudClientFor(ocAccount, context);
            RemoteOperationResult<UserInfo> result = remoteUserNameOperation.execute(nextcloudClient);
            if (result.isSuccess()) {
                UserInfo userInfo = result.getResultData();
                userId = userInfo.getId();
                displayName = userInfo.getDisplayName();
            } else {
                // skip account, try it next time
                Log_OC.e(TAG, "Error while getting username for account: " + account.name);
                failed++;
                continue;
            }
        } catch (Exception e) {
            Log_OC.e(TAG, "Error while getting username: " + e.getMessage());
            failed++;
            continue;
        }
        accountManager.setUserData(account, com.owncloud.android.lib.common.accounts.AccountUtils.Constants.KEY_DISPLAY_NAME, displayName);
        accountManager.setUserData(account, com.owncloud.android.lib.common.accounts.AccountUtils.Constants.KEY_USER_ID, userId);
    }
    return failed == 0;
}
Also used : Account(android.accounts.Account) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) GetUserInfoRemoteOperation(com.owncloud.android.lib.resources.users.GetUserInfoRemoteOperation) NextcloudClient(com.nextcloud.common.NextcloudClient) UserInfo(com.owncloud.android.lib.common.UserInfo) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) AuthenticatorException(android.accounts.AuthenticatorException) OperationCanceledException(android.accounts.OperationCanceledException) IOException(java.io.IOException)

Aggregations

UserInfo (com.owncloud.android.lib.common.UserInfo)12 Account (android.accounts.Account)5 NextcloudClient (com.nextcloud.common.NextcloudClient)5 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)5 GetUserInfoRemoteOperation (com.owncloud.android.lib.resources.users.GetUserInfoRemoteOperation)5 Intent (android.content.Intent)3 Uri (android.net.Uri)3 User (com.nextcloud.client.account.User)3 OwnCloudAccount (com.owncloud.android.lib.common.OwnCloudAccount)3 AccountManager (android.accounts.AccountManager)2 AuthenticatorException (android.accounts.AuthenticatorException)2 OperationCanceledException (android.accounts.OperationCanceledException)2 Context (android.content.Context)2 SharedPreferences (android.content.SharedPreferences)2 Quota (com.owncloud.android.lib.common.Quota)2 ScreenshotTest (com.owncloud.android.utils.ScreenshotTest)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 IOException (java.io.IOException)2 Test (org.junit.Test)2 SuppressLint (android.annotation.SuppressLint)1