Search in sources :

Example 11 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
public RemoteOperationResult<UserInfo> run(NextcloudClient client) {
    // get display name
    RemoteOperationResult<UserInfo> result = new GetUserInfoRemoteOperation().execute(client);
    if (result.isSuccess()) {
        // store display name with account data
        AccountManager accountManager = AccountManager.get(MainApp.getAppContext());
        UserInfo userInfo = result.getResultData();
        Account storedAccount = getStorageManager().getUser().toPlatformAccount();
        accountManager.setUserData(storedAccount, AccountUtils.Constants.KEY_DISPLAY_NAME, userInfo.getDisplayName());
    }
    return result;
}
Also used : Account(android.accounts.Account) GetUserInfoRemoteOperation(com.owncloud.android.lib.resources.users.GetUserInfoRemoteOperation) UserInfo(com.owncloud.android.lib.common.UserInfo) AccountManager(android.accounts.AccountManager)

Example 12 with UserInfo

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

the class RefreshFolderOperation method updateUserProfile.

private void updateUserProfile() {
    try {
        NextcloudClient nextcloudClient = OwnCloudClientFactory.createNextcloudClient(user.toPlatformAccount(), mContext);
        RemoteOperationResult<UserInfo> result = new GetUserProfileOperation(mStorageManager).execute(nextcloudClient);
        if (!result.isSuccess()) {
            Log_OC.w(TAG, "Couldn't update user profile from server");
        } else {
            Log_OC.i(TAG, "Got display name: " + result.getResultData());
        }
    } catch (AccountUtils.AccountNotFoundException | NullPointerException e) {
        Log_OC.e(this, "Error updating profile", e);
    }
}
Also used : NextcloudClient(com.nextcloud.common.NextcloudClient) UserInfo(com.owncloud.android.lib.common.UserInfo)

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