Fixed title in action bar when user clicks on upload notification in progress / failed
[pub/Android/ownCloud.git] / src / com / owncloud / android / operations / common / SyncOperation.java
1 /**
2 * ownCloud Android client application
3 *
4 * @author David A. Velasco
5 * Copyright (C) 2015 ownCloud Inc.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2,
9 * as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 package com.owncloud.android.operations.common;
22
23 import com.owncloud.android.MainApp;
24 import com.owncloud.android.datamodel.FileDataStorageManager;
25 import com.owncloud.android.lib.common.OwnCloudClient;
26 import com.owncloud.android.lib.common.operations.OnRemoteOperationListener;
27 import com.owncloud.android.lib.common.operations.RemoteOperation;
28 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
29
30 import android.content.Context;
31 import android.os.Handler;
32
33
34 /**
35 * Operation which execution involves both interactions with an ownCloud server and
36 * with local data in the device.
37 *
38 * Provides methods to execute the operation both synchronously or asynchronously.
39 */
40 public abstract class SyncOperation extends RemoteOperation {
41
42 //private static final String TAG = SyncOperation.class.getSimpleName();
43
44 private FileDataStorageManager mStorageManager;
45
46 public FileDataStorageManager getStorageManager() {
47 return mStorageManager;
48 }
49
50
51 /**
52 * Synchronously executes the operation on the received ownCloud account.
53 *
54 * Do not call this method from the main thread.
55 *
56 * This method should be used whenever an ownCloud account is available, instead of
57 * {@link #execute(OwnCloudClient, com.owncloud.android.datamodel.FileDataStorageManager)}.
58 *
59 * @param storageManager
60 * @param context Android context for the component calling the method.
61 * @return Result of the operation.
62 */
63 public RemoteOperationResult execute(FileDataStorageManager storageManager, Context context) {
64 if (storageManager == null) {
65 throw new IllegalArgumentException("Trying to execute a sync operation with a " +
66 "NULL storage manager");
67 }
68 if (storageManager.getAccount() == null) {
69 throw new IllegalArgumentException("Trying to execute a sync operation with a " +
70 "storage manager for a NULL account");
71 }
72 mStorageManager = storageManager;
73 return super.execute(mStorageManager.getAccount(), context);
74 }
75
76
77 /**
78 * Synchronously executes the remote operation
79 *
80 * Do not call this method from the main thread.
81 *
82 * @param client Client object to reach an ownCloud server during the execution of the o
83 * peration.
84 * @param storageManager
85 * @return Result of the operation.
86 */
87 public RemoteOperationResult execute(OwnCloudClient client,
88 FileDataStorageManager storageManager) {
89 if (storageManager == null)
90 throw new IllegalArgumentException("Trying to execute a sync operation with a " +
91 "NULL storage manager");
92 mStorageManager = storageManager;
93 return super.execute(client);
94 }
95
96
97 /**
98 * Asynchronously executes the remote operation
99 *
100 * This method should be used whenever an ownCloud account is available, instead of
101 * {@link #execute(OwnCloudClient)}.
102 *
103 * @param account ownCloud account in remote ownCloud server to reach during the
104 * execution of the operation.
105 * @param context Android context for the component calling the method.
106 * @param listener Listener to be notified about the execution of the operation.
107 * @param listenerHandler Handler associated to the thread where the methods of the listener
108 * objects must be called.
109 * @return Thread were the remote operation is executed.
110 */
111 /*
112 public Thread execute(FileDataStorageManager storageManager,
113 Context context, OnRemoteOperationListener listener, Handler listenerHandler, Activity callerActivity) {
114 if (storageManager == null) {
115 throw new IllegalArgumentException("Trying to execute a sync operation
116 with a NULL storage manager");
117 }
118 if (storageManager.getAccount() == null) {
119 throw new IllegalArgumentException("Trying to execute a sync operation with a
120 storage manager for a NULL account");
121 }
122 mStorageManager = storageManager;
123 return super.execute(storageManager.getAccount(), context, listener, listenerHandler,
124 callerActivity);
125 }
126 */
127
128
129 /**
130 * Asynchronously executes the remote operation
131 *
132 * @param client Client object to reach an ownCloud server during the
133 * execution of the operation.
134 * @param listener Listener to be notified about the execution of the operation.
135 * @param listenerHandler Handler associated to the thread where the methods of
136 * the listener objects must be called.
137 * @return Thread were the remote operation is executed.
138 */
139 public Thread execute(OwnCloudClient client, FileDataStorageManager storageManager,
140 OnRemoteOperationListener listener, Handler listenerHandler) {
141 if (storageManager == null) {
142 throw new IllegalArgumentException("Trying to execute a sync operation " +
143 "with a NULL storage manager");
144 }
145 mStorageManager = storageManager;
146 return super.execute(client, listener, listenerHandler);
147 }
148
149
150 }