Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 06f27a7c authored by David A. Velasco's avatar David A. Velasco
Browse files

Undo buggy refactoring; too much to do in that sense to get it works

parent afe65bdc
Loading
Loading
Loading
Loading
+30 −21
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import com.owncloud.android.lib.common.accounts.AccountUtils;
import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.accounts.AuthenticatorException;
import android.accounts.OperationCanceledException;
import android.content.Context;
@@ -55,41 +56,52 @@ public class OwnCloudAccount {


    /**
     * Full constructor.
     * Constructor for already saved OC accounts.
     *
     * @param baseUri           URI to the OC server to get access to.
     * @param credentials       Credentials to authenticate in the server. NULL is valid for anonymous credentials.
     * Do not use for anonymous credentials.
     */
    public OwnCloudAccount(Uri baseUri, OwnCloudCredentials credentials) {
        if (baseUri == null) {
            throw new IllegalArgumentException("Parameter 'baseUri' cannot be null");
    public OwnCloudAccount(Account savedAccount, Context context) throws AccountNotFoundException {
        if (savedAccount == null) {
            throw new IllegalArgumentException("Parameter 'savedAccount' cannot be null");
        }
        mSavedAccount = null;
        mSavedAccountName = null;
        mBaseUri = baseUri;
        mCredentials = credentials != null ?
            credentials : OwnCloudCredentialsFactory.getAnonymousCredentials();
        String username = mCredentials.getUsername();
        if (username != null) {
            mSavedAccountName = AccountUtils.buildAccountName(mBaseUri, username);

        if (context == null) {
            throw new IllegalArgumentException("Parameter 'context' cannot be null");
        }

        mSavedAccount = savedAccount;
        mSavedAccountName = savedAccount.name;
        mCredentials = null;    // load of credentials is delayed

        AccountManager ama = AccountManager.get(context.getApplicationContext());
        String baseUrl = ama.getUserData(mSavedAccount, AccountUtils.Constants.KEY_OC_BASE_URL);
        if (baseUrl == null ) {
            throw new AccountNotFoundException(mSavedAccount, "Account not found", null);
        }
        mBaseUri = Uri.parse(AccountUtils.getBaseUrlForAccount(context, mSavedAccount));
        mDisplayName = ama.getUserData(mSavedAccount, AccountUtils.Constants.KEY_DISPLAY_NAME);
    }


    /**
     * Partial constructor.
     * Constructor for non yet saved OC accounts.
     *
     * Load of credentials is delayed.
     * @param baseUri           URI to the OC server to get access to.
     * @param credentials       Credentials to authenticate in the server. NULL is valid for anonymous credentials.
     */
    public OwnCloudAccount(Uri baseUri) {
    public OwnCloudAccount(Uri baseUri, OwnCloudCredentials credentials) {
        if (baseUri == null) {
            throw new IllegalArgumentException("Parameter 'baseUri' cannot be null");
        }
        mSavedAccount = null;
        mSavedAccountName = null;
        mBaseUri = baseUri;
        mCredentials = null;
        mCredentials = credentials != null ?
            credentials : OwnCloudCredentialsFactory.getAnonymousCredentials();
        String username = mCredentials.getUsername();
        if (username != null) {
            mSavedAccountName = AccountUtils.buildAccountName(mBaseUri, username);
        }
    }


@@ -137,7 +149,4 @@ public class OwnCloudAccount {
        }
    }

    public void setDisplayName(String displayName) {
        mDisplayName = displayName;
    }
}
 No newline at end of file
+0 −48
Original line number Diff line number Diff line
package com.owncloud.android.lib.common;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.content.Context;
import android.net.Uri;

import com.owncloud.android.lib.common.accounts.AccountUtils;

import java.io.IOException;

/**
 * OwnCloud Account
 *
 * @author David A. Velasco
 */
public class OwnCloudAccountStorageManager {

    /**
     * Constructor for already saved OC accounts.
     *
     * Do not use for anonymous credentials.
     */
    public static OwnCloudAccount getOwnCloudAccount(Account savedAccount, Context context)
        throws AccountUtils.AccountNotFoundException {

        if (savedAccount == null) {
            throw new IllegalArgumentException("Parameter 'savedAccount' cannot be null");
        }

        if (context == null) {
            throw new IllegalArgumentException("Parameter 'context' cannot be null");
        }

        OwnCloudAccount account = new OwnCloudAccount(
            Uri.parse(AccountUtils.getBaseUrlForAccount(context, savedAccount))
        );

        AccountManager ama = AccountManager.get(context.getApplicationContext());
        String displayName = ama.getUserData(savedAccount, AccountUtils.Constants.KEY_DISPLAY_NAME);
        if (displayName != null && displayName.length() > 0) {
            account.setDisplayName(displayName);
        }

        return account;
    }

}
+2 −4
Original line number Diff line number Diff line
@@ -32,7 +32,6 @@ import android.content.Context;
import android.os.Handler;

import com.owncloud.android.lib.common.OwnCloudAccount;
import com.owncloud.android.lib.common.OwnCloudAccountStorageManager;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientFactory;
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
@@ -109,7 +108,7 @@ public abstract class RemoteOperation implements Runnable {
        mAccount = account;
        mContext = context.getApplicationContext();
        try {
        	OwnCloudAccount ocAccount = OwnCloudAccountStorageManager.getOwnCloudAccount(mAccount, mContext);
        	OwnCloudAccount ocAccount = new OwnCloudAccount(mAccount, mContext);
            mClient = OwnCloudClientManagerFactory.getDefaultSingleton().
            		getClientFor(ocAccount, mContext);
        } catch (Exception e) {
@@ -278,8 +277,7 @@ public abstract class RemoteOperation implements Runnable {
                            		mAccount, mContext, mCallerActivity);
                        } else {
                        /** EOF DEPRECATED */
                        	OwnCloudAccount ocAccount = OwnCloudAccountStorageManager.
                                    getOwnCloudAccount(mAccount, mContext);
                        	OwnCloudAccount ocAccount = new OwnCloudAccount(mAccount, mContext);
                            mClient = OwnCloudClientManagerFactory.getDefaultSingleton().
                            		getClientFor(ocAccount, mContext);
                        }