Using default singleton OwnCloudClientManager instead of holding a reference in application context

This commit is contained in:
David A. Velasco 2014-06-13 13:44:36 +02:00
parent 37236f0faa
commit 8b3c9f14dc
7 changed files with 21 additions and 23 deletions

@ -1 +1 @@
Subproject commit 9be1323745d8b6cf519315ce2641ab41e808a04b
Subproject commit 7e2ec10442a435b097b7cee48a7529e30b364277

View file

@ -16,7 +16,6 @@
*/
package com.owncloud.android;
import com.owncloud.android.lib.common.OwnCloudClientManager;
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory.Policy;
@ -25,7 +24,8 @@ import android.content.Context;
/**
* Main Application of the project
*
* Contains methods to build the "static" strings. These strings were before constants in different classes
* Contains methods to build the "static" strings. These strings were before constants in different
* classes
*
* @author masensio
* @author David A. Velasco
@ -38,8 +38,6 @@ public class MainApp extends Application {
private static Context mContext;
private OwnCloudClientManager mOwnCloudClientManager;
public void onCreate(){
super.onCreate();
MainApp.mContext = getApplicationContext();
@ -48,12 +46,10 @@ public class MainApp extends Application {
if (clientPolicy != null &&
POLICY_SINGLE_SESSION_PER_ACCOUNT.equals(clientPolicy.toLowerCase())) {
mOwnCloudClientManager = OwnCloudClientManagerFactory.newOwnCloudClientManager(
Policy.SINGLE_SESSION_PER_ACCOUNT);
OwnCloudClientManagerFactory.setDefaultPolicy(Policy.SINGLE_SESSION_PER_ACCOUNT);
} else {
mOwnCloudClientManager = OwnCloudClientManagerFactory.newOwnCloudClientManager(
Policy.ALWAYS_NEW_CLIENT);
OwnCloudClientManagerFactory.setDefaultPolicy(Policy.ALWAYS_NEW_CLIENT);
}
}
@ -103,7 +99,4 @@ public class MainApp extends Application {
return getAppContext().getResources().getString(R.string.log_name);
}
public OwnCloudClientManager getOwnCloudClientManager() {
return mOwnCloudClientManager;
}
}

View file

@ -37,6 +37,7 @@ import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
import com.owncloud.android.lib.common.OwnCloudAccount;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
import com.owncloud.android.notifications.NotificationBuilderWithProgressBar;
import com.owncloud.android.notifications.NotificationDelayer;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
@ -351,7 +352,7 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis
mStorageManager =
new FileDataStorageManager(mLastAccount, getContentResolver());
OwnCloudAccount ocAccount = new OwnCloudAccount(mLastAccount, this);
mDownloadClient = ((MainApp)getApplicationContext()).getOwnCloudClientManager().
mDownloadClient = OwnCloudClientManagerFactory.getDefaultSingleton().
getClientFor(ocAccount, this);
}

View file

@ -51,6 +51,7 @@ import com.owncloud.android.lib.common.accounts.AccountUtils.Constants;
import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
import com.owncloud.android.lib.common.OwnCloudAccount;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
import com.owncloud.android.ui.activity.FailedUploadActivity;
import com.owncloud.android.ui.activity.FileActivity;
import com.owncloud.android.ui.activity.FileDisplayActivity;
@ -490,7 +491,7 @@ public class FileUploader extends Service implements OnDatatransferProgressListe
mStorageManager =
new FileDataStorageManager(mLastAccount, getContentResolver());
OwnCloudAccount ocAccount = new OwnCloudAccount(mLastAccount, this);
mUploadClient = ((MainApp)getApplicationContext()).getOwnCloudClientManager().
mUploadClient = OwnCloudClientManagerFactory.getDefaultSingleton().
getClientFor(ocAccount, this);
}

View file

@ -28,6 +28,7 @@ import com.owncloud.android.R;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.lib.common.OwnCloudAccount;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
import com.owncloud.android.lib.common.OwnCloudCredentials;
import com.owncloud.android.lib.common.OwnCloudCredentialsFactory;
import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;
@ -177,7 +178,7 @@ public class OperationsService extends Service {
//Log_OC.wtf(TAG, "onDestroy init" );
// Saving cookies
try {
((MainApp)getApplicationContext()).getOwnCloudClientManager().
OwnCloudClientManagerFactory.getDefaultSingleton().
saveAllClients(this, MainApp.getAccountType());
// TODO - get rid of these exceptions
@ -471,8 +472,8 @@ public class OperationsService extends Service {
mLastTarget = next.first;
if (mLastTarget.mAccount != null) {
OwnCloudAccount ocAccount = new OwnCloudAccount(mLastTarget.mAccount, this);
mOwnCloudClient = ((MainApp)getApplicationContext()).
getOwnCloudClientManager().getClientFor(ocAccount, this);
mOwnCloudClient = OwnCloudClientManagerFactory.getDefaultSingleton().
getClientFor(ocAccount, this);
mStorageManager =
new FileDataStorageManager(
mLastTarget.mAccount,
@ -494,8 +495,8 @@ public class OperationsService extends Service {
}
OwnCloudAccount ocAccount = new OwnCloudAccount(
mLastTarget.mServerUrl, credentials);
mOwnCloudClient = ((MainApp)getApplicationContext()).
getOwnCloudClientManager().getClientFor(ocAccount, this);
mOwnCloudClient = OwnCloudClientManagerFactory.getDefaultSingleton().
getClientFor(ocAccount, this);
mOwnCloudClient.setFollowRedirects(mLastTarget.mFollowRedirects);
mStorageManager = null;
}

View file

@ -30,6 +30,7 @@ import com.owncloud.android.lib.common.accounts.AccountUtils;
import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;
import com.owncloud.android.lib.common.OwnCloudAccount;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
import android.accounts.Account;
import android.accounts.AccountManager;
@ -103,7 +104,7 @@ public abstract class AbstractOwnCloudSyncAdapter extends
protected void initClientForCurrentAccount() throws OperationCanceledException, AuthenticatorException, IOException, AccountNotFoundException {
AccountUtils.constructFullURLForAccount(getContext(), account);
OwnCloudAccount ocAccount = new OwnCloudAccount(account, getContext());
mClient = ((MainApp)(getContext().getApplicationContext())).getOwnCloudClientManager().
mClient = OwnCloudClientManagerFactory.getDefaultSingleton().
getClientFor(ocAccount, getContext());
}

View file

@ -73,6 +73,7 @@ import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
import com.owncloud.android.operations.CreateFolderOperation;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
import com.owncloud.android.lib.common.OwnCloudCredentials;
import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;
import com.owncloud.android.lib.common.network.CertificateCombinedException;
@ -936,10 +937,10 @@ FileFragment.ContainerActivity, OnNavigationListener, OnSslUntrustedCertListener
OwnCloudClient client = null;
try {
client = ((MainApp)getApplicationContext()).
getOwnCloudClientManager().removeClientFor(
client = (OwnCloudClientManagerFactory.getDefaultSingleton().
removeClientFor(
getAccount(),
context);
context));
// TODO get rid of these exceptions
} catch (AccountNotFoundException e) {
e.printStackTrace();