1
0
mirror of https://github.com/owncloud/android-library.git synced 2025-06-08 00:16:09 +00:00

Removed duplication of OwnCloudClientManager#getClientFor methods with different parameter types

This commit is contained in:
David A. Velasco 2014-06-13 12:42:40 +02:00
parent 0c4954928b
commit 9be1323745
6 changed files with 27 additions and 18 deletions

View File

@ -68,7 +68,7 @@ public class OwnCloudAccount {
mBaseUri = baseUri; mBaseUri = baseUri;
mCredentials = credentials != null ? mCredentials = credentials != null ?
credentials : OwnCloudCredentialsFactory.getAnonymousCredentials(); credentials : OwnCloudCredentialsFactory.getAnonymousCredentials();
String username = credentials.getUsername(); String username = mCredentials.getUsername();
if (username != null) { if (username != null) {
mSavedAccountName = AccountUtils.buildAccountName(mBaseUri, username); mSavedAccountName = AccountUtils.buildAccountName(mBaseUri, username);
} }

View File

@ -30,7 +30,6 @@ import android.accounts.Account;
import android.accounts.AuthenticatorException; import android.accounts.AuthenticatorException;
import android.accounts.OperationCanceledException; import android.accounts.OperationCanceledException;
import android.content.Context; import android.content.Context;
import android.net.Uri;
import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException; import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;
@ -44,12 +43,16 @@ import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundExce
public interface OwnCloudClientManager { public interface OwnCloudClientManager {
public OwnCloudClient getClientFor(OwnCloudAccount account, Context context);
/*
public OwnCloudClient getClientFor(Account savedAccount, Context context) public OwnCloudClient getClientFor(Account savedAccount, Context context)
throws AccountNotFoundException, AuthenticatorException, throws AccountNotFoundException, AuthenticatorException,
IOException, OperationCanceledException; IOException, OperationCanceledException;
public OwnCloudClient getClientFor( public OwnCloudClient getClientFor(
Uri serverBaseUri, OwnCloudCredentials credentials, Context context); Uri serverBaseUri, OwnCloudCredentials credentials, Context context);
*/
public void saveAllClients(Context context, String accountType) public void saveAllClients(Context context, String accountType)
throws AccountNotFoundException, AuthenticatorException, throws AccountNotFoundException, AuthenticatorException,
@ -59,6 +62,4 @@ public interface OwnCloudClientManager {
throws AccountNotFoundException, AuthenticatorException, throws AccountNotFoundException, AuthenticatorException,
IOException, OperationCanceledException; IOException, OperationCanceledException;
public OwnCloudClient getClientFor(OwnCloudAccount account, Context context);
} }

View File

@ -1,6 +1,5 @@
package com.owncloud.android.lib.common; package com.owncloud.android.lib.common;
import java.io.IOException;
import android.accounts.Account; import android.accounts.Account;
import android.accounts.AuthenticatorException; import android.accounts.AuthenticatorException;
@ -13,7 +12,7 @@ import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundExce
public class SimpleFactoryManager implements OwnCloudClientManager { public class SimpleFactoryManager implements OwnCloudClientManager {
private static final String TAG = OwnCloudClientManager.class.getSimpleName(); private static final String TAG = SimpleFactoryManager.class.getSimpleName();
@Override @Override
public OwnCloudClient getClientFor(OwnCloudAccount account, Context context) { public OwnCloudClient getClientFor(OwnCloudAccount account, Context context) {
@ -28,7 +27,7 @@ public class SimpleFactoryManager implements OwnCloudClientManager {
return client; return client;
} }
/*
@Override @Override
public OwnCloudClient getClientFor(Account savedAccount, Context context) public OwnCloudClient getClientFor(Account savedAccount, Context context)
throws OperationCanceledException, AuthenticatorException, AccountNotFoundException, throws OperationCanceledException, AuthenticatorException, AccountNotFoundException,
@ -57,6 +56,7 @@ public class SimpleFactoryManager implements OwnCloudClientManager {
Log.d(TAG, " new client " + client.hashCode()); Log.d(TAG, " new client " + client.hashCode());
return client; return client;
} }
*/
@Override @Override
public void saveAllClients(Context context, String accountType) { public void saveAllClients(Context context, String accountType) {
@ -66,7 +66,6 @@ public class SimpleFactoryManager implements OwnCloudClientManager {
@Override @Override
public OwnCloudClient removeClientFor(Account account, Context context) { public OwnCloudClient removeClientFor(Account account, Context context) {
// TODO Auto-generated method stub
return null; return null;
} }

View File

@ -58,8 +58,6 @@ public class SingleSessionManager implements OwnCloudClientManager {
private static final String TAG = SingleSessionManager.class.getSimpleName(); private static final String TAG = SingleSessionManager.class.getSimpleName();
private static OwnCloudClientManager mInstance = null;
private Map<String, Map<OwnCloudCredentials, OwnCloudClient>> mClientsPerServer = private Map<String, Map<OwnCloudCredentials, OwnCloudClient>> mClientsPerServer =
new HashMap<String, Map<OwnCloudCredentials, OwnCloudClient>>(); new HashMap<String, Map<OwnCloudCredentials, OwnCloudClient>>();
@ -86,6 +84,7 @@ public class SingleSessionManager implements OwnCloudClientManager {
if (accountName != null) { if (accountName != null) {
client = mClientsWithKnownUsername.get(accountName); client = mClientsWithKnownUsername.get(accountName);
} }
boolean reusingKnown = false; // just for logs
if (client == null) { if (client == null) {
if (accountName != null) { if (accountName != null) {
client = mClientsWithUnknownUsername.remove(sessionName); client = mClientsWithUnknownUsername.remove(sessionName);
@ -99,6 +98,7 @@ public class SingleSessionManager implements OwnCloudClientManager {
} }
} else { } else {
Log.d(TAG, " reusing client {" + accountName + ", " + client.hashCode() + "}"); Log.d(TAG, " reusing client {" + accountName + ", " + client.hashCode() + "}");
reusingKnown = true;
} }
if (client == null) { if (client == null) {
@ -121,13 +121,15 @@ public class SingleSessionManager implements OwnCloudClientManager {
Log.d(TAG, " new client {" + sessionName + ", " + client.hashCode() + "}"); Log.d(TAG, " new client {" + sessionName + ", " + client.hashCode() + "}");
} }
} else { } else {
Log.d(TAG, " reusing client {" + sessionName + ", " + client.hashCode() + "}"); if (!reusingKnown) {
Log.d(TAG, " reusing client {" + sessionName + ", " + client.hashCode() + "}");
}
} }
return client; return client;
} }
/*
@Override @Override
public synchronized OwnCloudClient getClientFor(Account savedAccount, Context context) public synchronized OwnCloudClient getClientFor(Account savedAccount, Context context)
throws OperationCanceledException, AuthenticatorException, AccountNotFoundException, throws OperationCanceledException, AuthenticatorException, AccountNotFoundException,
@ -147,8 +149,9 @@ public class SingleSessionManager implements OwnCloudClientManager {
return client; return client;
} }
*/
/*
@Override @Override
public synchronized OwnCloudClient getClientFor( public synchronized OwnCloudClient getClientFor(
Uri serverBaseUri, OwnCloudCredentials credentials, Context context) { Uri serverBaseUri, OwnCloudCredentials credentials, Context context) {
@ -186,7 +189,7 @@ public class SingleSessionManager implements OwnCloudClientManager {
return client; return client;
} }
*/
@Override @Override
public synchronized OwnCloudClient removeClientFor(Account savedAccount, Context context) public synchronized OwnCloudClient removeClientFor(Account savedAccount, Context context)

View File

@ -200,6 +200,9 @@ public class AccountUtils {
public static String buildAccountName(Uri serverBaseUrl, String username) { public static String buildAccountName(Uri serverBaseUrl, String username) {
if (serverBaseUrl.getScheme() == null) {
serverBaseUrl = Uri.parse("https://" + serverBaseUrl.toString());
}
String accountName = username + "@" + serverBaseUrl.getHost(); String accountName = username + "@" + serverBaseUrl.getHost();
if (serverBaseUrl.getPort() >= 0) { if (serverBaseUrl.getPort() >= 0) {
accountName += ":" + serverBaseUrl.getPort(); accountName += ":" + serverBaseUrl.getPort();

View File

@ -26,6 +26,7 @@ package com.owncloud.android.lib.common.operations;
import java.io.IOException; import java.io.IOException;
import com.owncloud.android.lib.common.OwnCloudAccount;
import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientFactory; import com.owncloud.android.lib.common.OwnCloudClientFactory;
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory; import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
@ -105,8 +106,9 @@ public abstract class RemoteOperation implements Runnable {
mAccount = account; mAccount = account;
mContext = context.getApplicationContext(); mContext = context.getApplicationContext();
try { try {
OwnCloudAccount ocAccount = new OwnCloudAccount(mAccount, mContext);
mClient = OwnCloudClientManagerFactory.getDefaultSingleton(). mClient = OwnCloudClientManagerFactory.getDefaultSingleton().
getClientFor(mAccount, mContext); getClientFor(ocAccount, mContext);
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, "Error while trying to access to " + mAccount.name, e); Log.e(TAG, "Error while trying to access to " + mAccount.name, e);
return new RemoteOperationResult(e); return new RemoteOperationResult(e);
@ -253,8 +255,9 @@ public abstract class RemoteOperation implements Runnable {
mAccount, mContext, mCallerActivity); mAccount, mContext, mCallerActivity);
} else { } else {
/** EOF DEPRECATED */ /** EOF DEPRECATED */
OwnCloudAccount ocAccount = new OwnCloudAccount(mAccount, mContext);
mClient = OwnCloudClientManagerFactory.getDefaultSingleton(). mClient = OwnCloudClientManagerFactory.getDefaultSingleton().
getClientFor(mAccount, mContext); getClientFor(ocAccount, mContext);
} }
} else { } else {