1
0
mirror of https://github.com/owncloud/android-library.git synced 2025-06-28 18:26:58 +00:00

Fixed issue fully breaking the refresh of current folder (fixed only for SimpleFactoryManager for the moment)

This commit is contained in:
David A. Velasco 2014-06-12 17:36:59 +02:00
parent 17d810fe2b
commit e6c23205eb
4 changed files with 37 additions and 15 deletions

@ -8,6 +8,8 @@ public class OwnCloudClientManagerFactory {
}
public final static Policy DEFAULT_POLICY = Policy.ALWAYS_NEW_CLIENT;
private static OwnCloudClientManager mDefaultSingleton;
public static OwnCloudClientManager newDefaultOwnCloudClientManager() {
return newOwnCloudClientManager(DEFAULT_POLICY);
@ -26,5 +28,11 @@ public class OwnCloudClientManagerFactory {
}
}
public static OwnCloudClientManager getDefaultSingleton() {
if (mDefaultSingleton == null) {
mDefaultSingleton = newDefaultOwnCloudClientManager();
}
return mDefaultSingleton;
}
}

@ -7,19 +7,23 @@ import android.accounts.AuthenticatorException;
import android.accounts.OperationCanceledException;
import android.content.Context;
import android.net.Uri;
import android.util.Log;
import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;
public class SimpleFactoryManager implements OwnCloudClientManager {
private static final String TAG = OwnCloudClientManager.class.getSimpleName();
@Override
public OwnCloudClient getClientFor(OwnCloudAccount account, Context context) {
Log.d(TAG, "getClientFor(OwnCloudAccount ... : ");
OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(
account.getBaseUri(),
context.getApplicationContext(),
true);
Log.d(TAG, " new client " + client.hashCode());
client.setCredentials(account.getCredentials());
return client;
}
@ -29,15 +33,20 @@ public class SimpleFactoryManager implements OwnCloudClientManager {
public OwnCloudClient getClientFor(Account savedAccount, Context context)
throws OperationCanceledException, AuthenticatorException, AccountNotFoundException,
IOException {
return OwnCloudClientFactory.createOwnCloudClient(
Log.d(TAG, "getClientFor(Account ... : ");
OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(
savedAccount,
context.getApplicationContext());
Log.d(TAG, " new client " + client.hashCode());
return client;
}
@Override
public OwnCloudClient getClientFor(Uri serverBaseUri, OwnCloudCredentials credentials,
Context context) {
Log.d(TAG, "getClientFor(Uri ... : ");
OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(
serverBaseUri,
@ -45,6 +54,7 @@ public class SimpleFactoryManager implements OwnCloudClientManager {
true);
client.setCredentials(credentials);
Log.d(TAG, " new client " + client.hashCode());
return client;
}

@ -71,16 +71,9 @@ public class SingleSessionManager implements OwnCloudClientManager {
new HashMap<String, OwnCloudClient>();
public static OwnCloudClientManager getInstance() {
if (mInstance == null) {
mInstance = new SingleSessionManager();
}
return mInstance;
}
@Override
public synchronized OwnCloudClient getClientFor(OwnCloudAccount account, Context context) {
Log.d(TAG, "getClientFor(OwnCloudAccount ... : ");
if (account == null) {
throw new IllegalArgumentException("Cannot get an OwnCloudClient for a null account");
}
@ -92,17 +85,21 @@ public class SingleSessionManager implements OwnCloudClientManager {
account.getCredentials().getAuthToken());
if (accountName != null) {
client = mClientsWithKnownUsername.get(account.getName());
client = mClientsWithKnownUsername.get(accountName);
}
if (client == null) {
if (accountName != null) {
client = mClientsWithUnknownUsername.remove(sessionName);
if (client != null) {
Log.d(TAG, " reusing client {" + sessionName + ", " + client.hashCode() + "}");
mClientsWithKnownUsername.put(accountName, client);
Log.d(TAG, " moved client to {" + accountName + ", " + client.hashCode() + "}");
}
} else {
client = mClientsWithUnknownUsername.get(sessionName);
}
} else {
Log.d(TAG, " reusing client {" + accountName + ", " + client.hashCode() + "}");
}
if (client == null) {
@ -114,9 +111,14 @@ public class SingleSessionManager implements OwnCloudClientManager {
client.setCredentials(account.getCredentials());
if (accountName != null) {
mClientsWithKnownUsername.put(accountName, client);
Log.d(TAG, " new client {" + accountName + ", " + client.hashCode() + "}");
} else {
mClientsWithUnknownUsername.put(sessionName, client);
Log.d(TAG, " new client {" + sessionName + ", " + client.hashCode() + "}");
}
} else {
Log.d(TAG, " reusing client {" + sessionName + ", " + client.hashCode() + "}");
}
return client;

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