OC-1701: Conflict detected in keep-in-sync
[pub/Android/ownCloud.git] / src / com / owncloud / android / syncadapter / AbstractOwnCloudSyncAdapter.java
index e8b1fcb..26bfff7 100644 (file)
@@ -1,10 +1,10 @@
 /* ownCloud Android client application\r
  *   Copyright (C) 2011  Bartek Przybylski\r
+ *   Copyright (C) 2012-2013 ownCloud Inc.\r
  *\r
  *   This program is free software: you can redistribute it and/or modify\r
- *   it under the terms of the GNU General Public License as published by\r
- *   the Free Software Foundation, either version 3 of the License, or\r
- *   (at your option) any later version.\r
+ *   it under the terms of the GNU General Public License version 2,\r
+ *   as published by the Free Software Foundation.\r
  *\r
  *   This program is distributed in the hope that it will be useful,\r
  *   but WITHOUT ANY WARRANTY; without even the implied warranty of\r
 package com.owncloud.android.syncadapter;\r
 \r
 import java.io.IOException;\r
-import java.net.UnknownHostException;\r
-import java.util.Date;\r
+//import java.net.UnknownHostException;\r
+//import java.util.Date;\r
 \r
 import org.apache.http.HttpRequest;\r
 import org.apache.http.HttpResponse;\r
 import org.apache.http.client.ClientProtocolException;\r
-import org.apache.http.conn.ConnectionKeepAliveStrategy;\r
-import org.apache.http.protocol.HttpContext;\r
+//import org.apache.http.conn.ConnectionKeepAliveStrategy;\r
+//import org.apache.http.protocol.HttpContext;\r
 \r
-import com.owncloud.android.authenticator.AccountAuthenticator;\r
+import com.owncloud.android.authentication.AccountUtils;\r
+import com.owncloud.android.authentication.AccountUtils.AccountNotFoundException;\r
 import com.owncloud.android.datamodel.DataStorageManager;\r
+import com.owncloud.android.network.OwnCloudClientUtils;\r
 \r
 import android.accounts.Account;\r
 import android.accounts.AccountManager;\r
@@ -38,15 +40,16 @@ import android.accounts.OperationCanceledException;
 import android.content.AbstractThreadedSyncAdapter;\r
 import android.content.ContentProviderClient;\r
 import android.content.Context;\r
-import android.net.Uri;\r
 import eu.alefzero.webdav.WebdavClient;\r
 \r
 /**\r
- * Base SyncAdapter for OwnCloud Designed to be subclassed for the concrete\r
- * SyncAdapter, like ConcatsSync, CalendarSync, FileSync etc..\r
+ * Base synchronization adapter for ownCloud designed to be subclassed for different\r
+ * resource types, like FileSync, ConcatsSync, CalendarSync, etc..\r
  * \r
- * @author sassman\r
+ * Implements the standard {@link AbstractThreadedSyncAdapter}.\r
  * \r
+ * @author sassman\r
+ * @author David A. Velasco\r
  */\r
 public abstract class AbstractOwnCloudSyncAdapter extends\r
         AbstractThreadedSyncAdapter {\r
@@ -54,7 +57,7 @@ public abstract class AbstractOwnCloudSyncAdapter extends
     private AccountManager accountManager;\r
     private Account account;\r
     private ContentProviderClient contentProvider;\r
-    private Date lastUpdated;\r
+    //private Date lastUpdated;\r
     private DataStorageManager mStoreManager;\r
 \r
     private WebdavClient mClient = null;\r
@@ -88,14 +91,6 @@ public abstract class AbstractOwnCloudSyncAdapter extends
         this.contentProvider = contentProvider;\r
     }\r
 \r
-    public Date getLastUpdated() {\r
-        return lastUpdated;\r
-    }\r
-\r
-    public void setLastUpdated(Date lastUpdated) {\r
-        this.lastUpdated = lastUpdated;\r
-    }\r
-\r
     public void setStorageManager(DataStorageManager storage_manager) {\r
         mStoreManager = storage_manager;\r
     }\r
@@ -104,6 +99,41 @@ public abstract class AbstractOwnCloudSyncAdapter extends
         return mStoreManager;\r
     }\r
 \r
+    protected void initClientForCurrentAccount() throws OperationCanceledException, AuthenticatorException, IOException, AccountNotFoundException {\r
+        AccountUtils.constructFullURLForAccount(getContext(), account);\r
+        mClient = OwnCloudClientUtils.createOwnCloudClient(account, getContext());\r
+    }\r
+    \r
+    protected WebdavClient getClient() {\r
+        return mClient;\r
+    }\r
+    \r
+    \r
+    /* method called by ContactSyncAdapter, that is never used */\r
+    protected HttpResponse fireRawRequest(HttpRequest query)\r
+            throws ClientProtocolException, OperationCanceledException,\r
+            AuthenticatorException, IOException {\r
+        /*\r
+         * BasicHttpContext httpContext = new BasicHttpContext(); BasicScheme\r
+         * basicAuth = new BasicScheme();\r
+         * httpContext.setAttribute("preemptive-auth", basicAuth);\r
+         * \r
+         * HttpResponse response = getClient().execute(mHost, query,\r
+         * httpContext);\r
+         */\r
+        return null;\r
+    }\r
+\r
+    /* methods never used  below */\r
+    /*\r
+    public Date getLastUpdated() {\r
+        return lastUpdated;\r
+    }\r
+\r
+    public void setLastUpdated(Date lastUpdated) {\r
+        this.lastUpdated = lastUpdated;\r
+    }\r
+\r
     protected ConnectionKeepAliveStrategy getKeepAliveStrategy() {\r
         return new ConnectionKeepAliveStrategy() {\r
             public long getKeepAliveDuration(HttpResponse response,\r
@@ -127,38 +157,5 @@ public abstract class AbstractOwnCloudSyncAdapter extends
             }\r
         };\r
     }\r
-\r
-    protected HttpResponse fireRawRequest(HttpRequest query)\r
-            throws ClientProtocolException, OperationCanceledException,\r
-            AuthenticatorException, IOException {\r
-        /*\r
-         * BasicHttpContext httpContext = new BasicHttpContext(); BasicScheme\r
-         * basicAuth = new BasicScheme();\r
-         * httpContext.setAttribute("preemptive-auth", basicAuth);\r
-         * \r
-         * HttpResponse response = getClient().execute(mHost, query,\r
-         * httpContext);\r
-         */\r
-        return null;\r
-    }\r
-\r
-    protected Uri getUri() {\r
-        return Uri.parse(this.getAccountManager().getUserData(getAccount(),\r
-                AccountAuthenticator.KEY_OC_URL));\r
-    }\r
-\r
-    protected WebdavClient getClient() throws OperationCanceledException,\r
-            AuthenticatorException, IOException {\r
-        if (mClient == null) {\r
-            if (this.getAccountManager().getUserData(getAccount(),\r
-                    AccountAuthenticator.KEY_OC_URL) == null) {\r
-                throw new UnknownHostException();\r
-            }\r
-            mClient = new WebdavClient(account, getContext());\r
-            mClient.allowSelfsignedCertificates();\r
-            // mHost = mClient.getTargetHost();\r
-        }\r
-\r
-        return mClient;\r
-    }\r
+     */\r
 }
\ No newline at end of file