mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +00:00
Undo buggy refactoring; too much to do in that sense to get it works
This commit is contained in:
parent
afe65bdc3f
commit
06f27a7c79
@ -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,7 +56,35 @@ public class OwnCloudAccount {
|
||||
|
||||
|
||||
/**
|
||||
* Full constructor.
|
||||
* Constructor for already saved OC accounts.
|
||||
*
|
||||
* Do not use for anonymous credentials.
|
||||
*/
|
||||
public OwnCloudAccount(Account savedAccount, Context context) throws AccountNotFoundException {
|
||||
if (savedAccount == null) {
|
||||
throw new IllegalArgumentException("Parameter 'savedAccount' cannot be null");
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructor for non yet 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.
|
||||
@ -76,23 +105,6 @@ public class OwnCloudAccount {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Partial constructor.
|
||||
*
|
||||
* Load of credentials is delayed.
|
||||
* @param baseUri URI to the OC server to get access to.
|
||||
*/
|
||||
public OwnCloudAccount(Uri baseUri) {
|
||||
if (baseUri == null) {
|
||||
throw new IllegalArgumentException("Parameter 'baseUri' cannot be null");
|
||||
}
|
||||
mSavedAccount = null;
|
||||
mSavedAccountName = null;
|
||||
mBaseUri = baseUri;
|
||||
mCredentials = null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Method for deferred load of account attributes from AccountManager
|
||||
*
|
||||
@ -137,7 +149,4 @@ public class OwnCloudAccount {
|
||||
}
|
||||
}
|
||||
|
||||
public void setDisplayName(String displayName) {
|
||||
mDisplayName = displayName;
|
||||
}
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user