X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/981bf05434e8b5aa81691b5a0b91fa573ab48d18..bcc972d63d3ed1d76b51a8a03a27e809983dc756:/src/com/owncloud/android/syncadapter/AbstractOwnCloudSyncAdapter.java?ds=inline diff --git a/src/com/owncloud/android/syncadapter/AbstractOwnCloudSyncAdapter.java b/src/com/owncloud/android/syncadapter/AbstractOwnCloudSyncAdapter.java index 878c6961..74d26868 100644 --- a/src/com/owncloud/android/syncadapter/AbstractOwnCloudSyncAdapter.java +++ b/src/com/owncloud/android/syncadapter/AbstractOwnCloudSyncAdapter.java @@ -1,10 +1,10 @@ /* ownCloud Android client application * Copyright (C) 2011 Bartek Przybylski + * Copyright (C) 2012-2013 ownCloud Inc. * * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -19,18 +19,17 @@ package com.owncloud.android.syncadapter; import java.io.IOException; -import java.net.UnknownHostException; -import java.util.Date; import org.apache.http.HttpRequest; import org.apache.http.HttpResponse; import org.apache.http.client.ClientProtocolException; -import org.apache.http.conn.ConnectionKeepAliveStrategy; -import org.apache.http.protocol.HttpContext; -import com.owncloud.android.AccountUtils; -import com.owncloud.android.datamodel.DataStorageManager; -import com.owncloud.android.network.OwnCloudClientUtils; +import com.owncloud.android.datamodel.FileDataStorageManager; +import com.owncloud.android.oc_framework.accounts.AccountUtils; +import com.owncloud.android.oc_framework.accounts.AccountUtils.AccountNotFoundException; +import com.owncloud.android.oc_framework.network.webdav.OwnCloudClientFactory; +import com.owncloud.android.oc_framework.network.webdav.WebdavClient; + import android.accounts.Account; import android.accounts.AccountManager; @@ -39,24 +38,23 @@ import android.accounts.OperationCanceledException; import android.content.AbstractThreadedSyncAdapter; import android.content.ContentProviderClient; import android.content.Context; -import android.net.Uri; -import eu.alefzero.webdav.WebdavClient; /** - * Base SyncAdapter for OwnCloud Designed to be subclassed for the concrete - * SyncAdapter, like ConcatsSync, CalendarSync, FileSync etc.. + * Base synchronization adapter for ownCloud designed to be subclassed for different + * resource types, like FileSync, ConcatsSync, CalendarSync, etc.. * - * @author sassman + * Implements the standard {@link AbstractThreadedSyncAdapter}. * + * @author sassman + * @author David A. Velasco */ public abstract class AbstractOwnCloudSyncAdapter extends AbstractThreadedSyncAdapter { private AccountManager accountManager; private Account account; - private ContentProviderClient contentProvider; - private Date lastUpdated; - private DataStorageManager mStoreManager; + private ContentProviderClient mContentProviderClient; + private FileDataStorageManager mStoreManager; private WebdavClient mClient = null; @@ -65,6 +63,11 @@ public abstract class AbstractOwnCloudSyncAdapter extends this.setAccountManager(AccountManager.get(context)); } + public AbstractOwnCloudSyncAdapter(Context context, boolean autoInitialize, boolean allowParallelSyncs) { + super(context, autoInitialize, allowParallelSyncs); + this.setAccountManager(AccountManager.get(context)); + } + public AccountManager getAccountManager() { return accountManager; } @@ -81,81 +84,37 @@ public abstract class AbstractOwnCloudSyncAdapter extends this.account = account; } - public ContentProviderClient getContentProvider() { - return contentProvider; - } - - public void setContentProvider(ContentProviderClient contentProvider) { - this.contentProvider = contentProvider; - } - - public Date getLastUpdated() { - return lastUpdated; + public ContentProviderClient getContentProviderClient() { + return mContentProviderClient; } - public void setLastUpdated(Date lastUpdated) { - this.lastUpdated = lastUpdated; + public void setContentProviderClient(ContentProviderClient contentProvider) { + this.mContentProviderClient = contentProvider; } - public void setStorageManager(DataStorageManager storage_manager) { + public void setStorageManager(FileDataStorageManager storage_manager) { mStoreManager = storage_manager; } - public DataStorageManager getStorageManager() { + public FileDataStorageManager getStorageManager() { return mStoreManager; } - protected ConnectionKeepAliveStrategy getKeepAliveStrategy() { - return new ConnectionKeepAliveStrategy() { - public long getKeepAliveDuration(HttpResponse response, - HttpContext context) { - // Change keep alive straategy basing on response: ie - // forbidden/not found/etc - // should have keep alive 0 - // default return: 5s - int statusCode = response.getStatusLine().getStatusCode(); - - // HTTP 400, 500 Errors as well as HTTP 118 - Connection timed - // out - if ((statusCode >= 400 && statusCode <= 418) - || (statusCode >= 421 && statusCode <= 426) - || (statusCode >= 500 && statusCode <= 510) - || statusCode == 118) { - return 0; - } - - return 5 * 1000; - } - }; + protected void initClientForCurrentAccount() throws OperationCanceledException, AuthenticatorException, IOException, AccountNotFoundException { + AccountUtils.constructFullURLForAccount(getContext(), account); + mClient = OwnCloudClientFactory.createOwnCloudClient(account, getContext()); } - + + protected WebdavClient getClient() { + return mClient; + } + + + /* method called by ContactSyncAdapter, that is never used */ protected HttpResponse fireRawRequest(HttpRequest query) throws ClientProtocolException, OperationCanceledException, AuthenticatorException, IOException { - /* - * BasicHttpContext httpContext = new BasicHttpContext(); BasicScheme - * basicAuth = new BasicScheme(); - * httpContext.setAttribute("preemptive-auth", basicAuth); - * - * HttpResponse response = getClient().execute(mHost, query, - * httpContext); - */ return null; } - protected Uri getUri() { - return Uri.parse(AccountUtils.constructFullURLForAccount(getContext(), getAccount())); - } - - protected WebdavClient getClient() throws /*OperationCanceledException, - AuthenticatorException,*/ IOException { - if (mClient == null) { - if (AccountUtils.constructFullURLForAccount(getContext(), getAccount()) == null) { - throw new UnknownHostException(); - } - mClient = OwnCloudClientUtils.createOwnCloudClient(account, getContext()); - } - - return mClient; - } } \ No newline at end of file