mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +00:00
Removed duplication of OwnCloudClientManager#getClientFor methods with different parameter types
This commit is contained in:
parent
0c4954928b
commit
9be1323745
@ -68,7 +68,7 @@ public class OwnCloudAccount {
|
||||
mBaseUri = baseUri;
|
||||
mCredentials = credentials != null ?
|
||||
credentials : OwnCloudCredentialsFactory.getAnonymousCredentials();
|
||||
String username = credentials.getUsername();
|
||||
String username = mCredentials.getUsername();
|
||||
if (username != null) {
|
||||
mSavedAccountName = AccountUtils.buildAccountName(mBaseUri, username);
|
||||
}
|
||||
|
@ -30,7 +30,6 @@ import android.accounts.Account;
|
||||
import android.accounts.AuthenticatorException;
|
||||
import android.accounts.OperationCanceledException;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
|
||||
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 OwnCloudClient getClientFor(OwnCloudAccount account, Context context);
|
||||
|
||||
/*
|
||||
public OwnCloudClient getClientFor(Account savedAccount, Context context)
|
||||
throws AccountNotFoundException, AuthenticatorException,
|
||||
IOException, OperationCanceledException;
|
||||
|
||||
public OwnCloudClient getClientFor(
|
||||
Uri serverBaseUri, OwnCloudCredentials credentials, Context context);
|
||||
*/
|
||||
|
||||
public void saveAllClients(Context context, String accountType)
|
||||
throws AccountNotFoundException, AuthenticatorException,
|
||||
@ -59,6 +62,4 @@ public interface OwnCloudClientManager {
|
||||
throws AccountNotFoundException, AuthenticatorException,
|
||||
IOException, OperationCanceledException;
|
||||
|
||||
public OwnCloudClient getClientFor(OwnCloudAccount account, Context context);
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.owncloud.android.lib.common;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AuthenticatorException;
|
||||
@ -13,7 +12,7 @@ import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundExce
|
||||
|
||||
public class SimpleFactoryManager implements OwnCloudClientManager {
|
||||
|
||||
private static final String TAG = OwnCloudClientManager.class.getSimpleName();
|
||||
private static final String TAG = SimpleFactoryManager.class.getSimpleName();
|
||||
|
||||
@Override
|
||||
public OwnCloudClient getClientFor(OwnCloudAccount account, Context context) {
|
||||
@ -28,7 +27,7 @@ public class SimpleFactoryManager implements OwnCloudClientManager {
|
||||
return client;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
@Override
|
||||
public OwnCloudClient getClientFor(Account savedAccount, Context context)
|
||||
throws OperationCanceledException, AuthenticatorException, AccountNotFoundException,
|
||||
@ -57,6 +56,7 @@ public class SimpleFactoryManager implements OwnCloudClientManager {
|
||||
Log.d(TAG, " new client " + client.hashCode());
|
||||
return client;
|
||||
}
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void saveAllClients(Context context, String accountType) {
|
||||
@ -66,7 +66,6 @@ public class SimpleFactoryManager implements OwnCloudClientManager {
|
||||
|
||||
@Override
|
||||
public OwnCloudClient removeClientFor(Account account, Context context) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -58,8 +58,6 @@ public class SingleSessionManager implements OwnCloudClientManager {
|
||||
|
||||
private static final String TAG = SingleSessionManager.class.getSimpleName();
|
||||
|
||||
private static OwnCloudClientManager mInstance = null;
|
||||
|
||||
private Map<String, Map<OwnCloudCredentials, OwnCloudClient>> mClientsPerServer =
|
||||
new HashMap<String, Map<OwnCloudCredentials, OwnCloudClient>>();
|
||||
|
||||
@ -86,6 +84,7 @@ public class SingleSessionManager implements OwnCloudClientManager {
|
||||
if (accountName != null) {
|
||||
client = mClientsWithKnownUsername.get(accountName);
|
||||
}
|
||||
boolean reusingKnown = false; // just for logs
|
||||
if (client == null) {
|
||||
if (accountName != null) {
|
||||
client = mClientsWithUnknownUsername.remove(sessionName);
|
||||
@ -99,6 +98,7 @@ public class SingleSessionManager implements OwnCloudClientManager {
|
||||
}
|
||||
} else {
|
||||
Log.d(TAG, " reusing client {" + accountName + ", " + client.hashCode() + "}");
|
||||
reusingKnown = true;
|
||||
}
|
||||
|
||||
if (client == null) {
|
||||
@ -121,13 +121,15 @@ public class SingleSessionManager implements OwnCloudClientManager {
|
||||
Log.d(TAG, " new client {" + sessionName + ", " + client.hashCode() + "}");
|
||||
}
|
||||
} else {
|
||||
if (!reusingKnown) {
|
||||
Log.d(TAG, " reusing client {" + sessionName + ", " + client.hashCode() + "}");
|
||||
}
|
||||
}
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
@Override
|
||||
public synchronized OwnCloudClient getClientFor(Account savedAccount, Context context)
|
||||
throws OperationCanceledException, AuthenticatorException, AccountNotFoundException,
|
||||
@ -147,8 +149,9 @@ public class SingleSessionManager implements OwnCloudClientManager {
|
||||
return client;
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
@Override
|
||||
public synchronized OwnCloudClient getClientFor(
|
||||
Uri serverBaseUri, OwnCloudCredentials credentials, Context context) {
|
||||
@ -186,7 +189,7 @@ public class SingleSessionManager implements OwnCloudClientManager {
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
@Override
|
||||
public synchronized OwnCloudClient removeClientFor(Account savedAccount, Context context)
|
||||
|
@ -200,6 +200,9 @@ public class AccountUtils {
|
||||
|
||||
|
||||
public static String buildAccountName(Uri serverBaseUrl, String username) {
|
||||
if (serverBaseUrl.getScheme() == null) {
|
||||
serverBaseUrl = Uri.parse("https://" + serverBaseUrl.toString());
|
||||
}
|
||||
String accountName = username + "@" + serverBaseUrl.getHost();
|
||||
if (serverBaseUrl.getPort() >= 0) {
|
||||
accountName += ":" + serverBaseUrl.getPort();
|
||||
|
@ -26,6 +26,7 @@ package com.owncloud.android.lib.common.operations;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.owncloud.android.lib.common.OwnCloudAccount;
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.owncloud.android.lib.common.OwnCloudClientFactory;
|
||||
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
|
||||
@ -105,8 +106,9 @@ public abstract class RemoteOperation implements Runnable {
|
||||
mAccount = account;
|
||||
mContext = context.getApplicationContext();
|
||||
try {
|
||||
OwnCloudAccount ocAccount = new OwnCloudAccount(mAccount, mContext);
|
||||
mClient = OwnCloudClientManagerFactory.getDefaultSingleton().
|
||||
getClientFor(mAccount, mContext);
|
||||
getClientFor(ocAccount, mContext);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Error while trying to access to " + mAccount.name, e);
|
||||
return new RemoteOperationResult(e);
|
||||
@ -253,8 +255,9 @@ public abstract class RemoteOperation implements Runnable {
|
||||
mAccount, mContext, mCallerActivity);
|
||||
} else {
|
||||
/** EOF DEPRECATED */
|
||||
OwnCloudAccount ocAccount = new OwnCloudAccount(mAccount, mContext);
|
||||
mClient = OwnCloudClientManagerFactory.getDefaultSingleton().
|
||||
getClientFor(mAccount, mContext);
|
||||
getClientFor(ocAccount, mContext);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user