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