2 * ownCloud Android client application
4 * @author David A. Velasco
5 * Copyright (C) 2015 ownCloud Inc.
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.
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.
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/>.
21 package com
.owncloud
.android
.operations
.common
;
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
;
30 import android
.content
.Context
;
31 import android
.os
.Handler
;
35 * Operation which execution involves both interactions with an ownCloud server and
36 * with local data in the device.
38 * Provides methods to execute the operation both synchronously or asynchronously.
40 public abstract class SyncOperation
extends RemoteOperation
{
42 //private static final String TAG = SyncOperation.class.getSimpleName();
44 private FileDataStorageManager mStorageManager
;
46 public FileDataStorageManager
getStorageManager() {
47 return mStorageManager
;
52 * Synchronously executes the operation on the received ownCloud account.
54 * Do not call this method from the main thread.
56 * This method should be used whenever an ownCloud account is available, instead of
57 * {@link #execute(OwnCloudClient, com.owncloud.android.datamodel.FileDataStorageManager)}.
59 * @param storageManager
60 * @param context Android context for the component calling the method.
61 * @return Result of the operation.
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");
68 if (storageManager
.getAccount() == null
) {
69 throw new IllegalArgumentException("Trying to execute a sync operation with a " +
70 "storage manager for a NULL account");
72 mStorageManager
= storageManager
;
73 return super.execute(mStorageManager
.getAccount(), context
);
78 * Synchronously executes the remote operation
80 * Do not call this method from the main thread.
82 * @param client Client object to reach an ownCloud server during the execution of the o
84 * @param storageManager
85 * @return Result of the operation.
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
);
98 * Asynchronously executes the remote operation
100 * This method should be used whenever an ownCloud account is available, instead of
101 * {@link #execute(OwnCloudClient)}.
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.
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");
118 if (storageManager.getAccount() == null) {
119 throw new IllegalArgumentException("Trying to execute a sync operation with a
120 storage manager for a NULL account");
122 mStorageManager = storageManager;
123 return super.execute(storageManager.getAccount(), context, listener, listenerHandler,
130 * Asynchronously executes the remote operation
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.
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");
145 mStorageManager
= storageManager
;
146 return super.execute(client
, listener
, listenerHandler
);