Merge branch 'develop' into create_folder_during_upload_pr_701_with_develop
[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.datamodel.FileDataStorageManager;
24 import com.owncloud.android.lib.common.OwnCloudClient;
25 import com.owncloud.android.lib.common.operations.OnRemoteOperationListener;
26 import com.owncloud.android.lib.common.operations.RemoteOperation;
27 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
28
29 import android.content.Context;
30 import android.os.Handler;
31
32
33 /**
34 * Operation which execution involves both interactions with an ownCloud server and
35 * with local data in the device.
36 *
37 * Provides methods to execute the operation both synchronously or asynchronously.
38 */
39 public abstract class SyncOperation extends RemoteOperation {
40
41 //private static final String TAG = SyncOperation.class.getSimpleName();
42
43 private FileDataStorageManager mStorageManager;
44
45 public FileDataStorageManager getStorageManager() {
46 return mStorageManager;
47 }
48
49
50 /**
51 * Synchronously executes the operation on the received ownCloud account.
52 *
53 * Do not call this method from the main thread.
54 *
55 * This method should be used whenever an ownCloud account is available, instead of {@link #execute(OwnCloudClient)}.
56 *
57 * @param account ownCloud account in remote ownCloud server to reach during the execution of the operation.
58 * @param context Android context for the component calling the method.
59 * @return Result of the operation.
60 */
61 public RemoteOperationResult execute(FileDataStorageManager storageManager, Context context) {
62 if (storageManager == null) {
63 throw new IllegalArgumentException("Trying to execute a sync operation with a NULL storage manager");
64 }
65 if (storageManager.getAccount() == null) {
66 throw new IllegalArgumentException("Trying to execute a sync operation with a storage manager for a NULL account");
67 }
68 mStorageManager = storageManager;
69 return super.execute(mStorageManager.getAccount(), context);
70 }
71
72
73 /**
74 * Synchronously executes the remote operation
75 *
76 * Do not call this method from the main thread.
77 *
78 * @param client Client object to reach an ownCloud server during the execution of the operation.
79 * @return Result of the operation.
80 */
81 public RemoteOperationResult execute(OwnCloudClient client, FileDataStorageManager storageManager) {
82 if (storageManager == null)
83 throw new IllegalArgumentException("Trying to execute a sync operation with a NULL storage manager");
84 mStorageManager = storageManager;
85 return super.execute(client);
86 }
87
88
89 /**
90 * Asynchronously executes the remote operation
91 *
92 * This method should be used whenever an ownCloud account is available, instead of {@link #execute(OwnCloudClient)}.
93 *
94 * @param account ownCloud account in remote ownCloud server to reach during the execution of the operation.
95 * @param context Android context for the component calling the method.
96 * @param listener Listener to be notified about the execution of the operation.
97 * @param listenerHandler Handler associated to the thread where the methods of the listener objects must be called.
98 * @return Thread were the remote operation is executed.
99 */
100 /*
101 public Thread execute(FileDataStorageManager storageManager, Context context, OnRemoteOperationListener listener, Handler listenerHandler, Activity callerActivity) {
102 if (storageManager == null) {
103 throw new IllegalArgumentException("Trying to execute a sync operation with a NULL storage manager");
104 }
105 if (storageManager.getAccount() == null) {
106 throw new IllegalArgumentException("Trying to execute a sync operation with a storage manager for a NULL account");
107 }
108 mStorageManager = storageManager;
109 return super.execute(storageManager.getAccount(), context, listener, listenerHandler, callerActivity);
110 }
111 */
112
113
114 /**
115 * Asynchronously executes the remote operation
116 *
117 * @param client Client object to reach an ownCloud server during the execution of the operation.
118 * @param listener Listener to be notified about the execution of the operation.
119 * @param listenerHandler Handler associated to the thread where the methods of the listener objects must be called.
120 * @return Thread were the remote operation is executed.
121 */
122 public Thread execute(OwnCloudClient client, FileDataStorageManager storageManager, OnRemoteOperationListener listener, Handler listenerHandler) {
123 if (storageManager == null) {
124 throw new IllegalArgumentException("Trying to execute a sync operation with a NULL storage manager");
125 }
126 mStorageManager = storageManager;
127 return super.execute(client, listener, listenerHandler);
128 }
129
130
131 }