Merge pull request #294 from owncloud/setup_buttons
[pub/Android/ownCloud.git] / src / com / owncloud / android / syncadapter / AbstractOwnCloudSyncAdapter.java
1 /* ownCloud Android client application
2 * Copyright (C) 2011 Bartek Przybylski
3 * Copyright (C) 2012-2013 ownCloud Inc.
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2,
7 * as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 */
18
19 package com.owncloud.android.syncadapter;
20
21 import java.io.IOException;
22
23 import org.apache.http.HttpRequest;
24 import org.apache.http.HttpResponse;
25 import org.apache.http.client.ClientProtocolException;
26
27 import com.owncloud.android.authentication.AccountUtils;
28 import com.owncloud.android.authentication.AccountUtils.AccountNotFoundException;
29 import com.owncloud.android.datamodel.FileDataStorageManager;
30 import com.owncloud.android.network.OwnCloudClientUtils;
31
32
33 import android.accounts.Account;
34 import android.accounts.AccountManager;
35 import android.accounts.AuthenticatorException;
36 import android.accounts.OperationCanceledException;
37 import android.content.AbstractThreadedSyncAdapter;
38 import android.content.ContentProviderClient;
39 import android.content.Context;
40 import eu.alefzero.webdav.WebdavClient;
41
42 /**
43 * Base synchronization adapter for ownCloud designed to be subclassed for different
44 * resource types, like FileSync, ConcatsSync, CalendarSync, etc..
45 *
46 * Implements the standard {@link AbstractThreadedSyncAdapter}.
47 *
48 * @author sassman
49 * @author David A. Velasco
50 */
51 public abstract class AbstractOwnCloudSyncAdapter extends
52 AbstractThreadedSyncAdapter {
53
54 private AccountManager accountManager;
55 private Account account;
56 private ContentProviderClient contentProvider;
57 private FileDataStorageManager mStoreManager;
58
59 private WebdavClient mClient = null;
60
61 public AbstractOwnCloudSyncAdapter(Context context, boolean autoInitialize) {
62 super(context, autoInitialize);
63 this.setAccountManager(AccountManager.get(context));
64 }
65
66 public AccountManager getAccountManager() {
67 return accountManager;
68 }
69
70 public void setAccountManager(AccountManager accountManager) {
71 this.accountManager = accountManager;
72 }
73
74 public Account getAccount() {
75 return account;
76 }
77
78 public void setAccount(Account account) {
79 this.account = account;
80 }
81
82 public ContentProviderClient getContentProvider() {
83 return contentProvider;
84 }
85
86 public void setContentProvider(ContentProviderClient contentProvider) {
87 this.contentProvider = contentProvider;
88 }
89
90 public void setStorageManager(FileDataStorageManager storage_manager) {
91 mStoreManager = storage_manager;
92 }
93
94 public FileDataStorageManager getStorageManager() {
95 return mStoreManager;
96 }
97
98 protected void initClientForCurrentAccount() throws OperationCanceledException, AuthenticatorException, IOException, AccountNotFoundException {
99 AccountUtils.constructFullURLForAccount(getContext(), account);
100 mClient = OwnCloudClientUtils.createOwnCloudClient(account, getContext());
101 }
102
103 protected WebdavClient getClient() {
104 return mClient;
105 }
106
107
108 /* method called by ContactSyncAdapter, that is never used */
109 protected HttpResponse fireRawRequest(HttpRequest query)
110 throws ClientProtocolException, OperationCanceledException,
111 AuthenticatorException, IOException {
112 return null;
113 }
114
115 }