1 /* ownCloud Android client application
2 * Copyright (C) 2012-2014 ownCloud Inc.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2,
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package com
.owncloud
.android
.operations
.common
;
20 import com
.owncloud
.android
.datamodel
.FileDataStorageManager
;
21 import com
.owncloud
.android
.lib
.network
.OwnCloudClient
;
22 import com
.owncloud
.android
.lib
.operations
.common
.OnRemoteOperationListener
;
23 import com
.owncloud
.android
.lib
.operations
.common
.RemoteOperation
;
24 import com
.owncloud
.android
.lib
.operations
.common
.RemoteOperationResult
;
26 import android
.app
.Activity
;
27 import android
.content
.Context
;
28 import android
.os
.Handler
;
32 * Operation which execution involves both interactions with an ownCloud server and
33 * with local data in the device.
35 * Provides methods to execute the operation both synchronously or asynchronously.
37 * @author David A. Velasco
39 public abstract class SyncOperation
extends RemoteOperation
{
41 //private static final String TAG = SyncOperation.class.getSimpleName();
43 private FileDataStorageManager mStorageManager
;
45 public FileDataStorageManager
getStorageManager() {
46 return mStorageManager
;
51 * Synchronously executes the operation on the received ownCloud account.
53 * Do not call this method from the main thread.
55 * This method should be used whenever an ownCloud account is available, instead of {@link #execute(OwnCloudClient)}.
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.
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");
65 if (storageManager
.getAccount() == null
) {
66 throw new IllegalArgumentException("Trying to execute a sync operation with a storage manager for a NULL account");
68 mStorageManager
= storageManager
;
69 return super.execute(mStorageManager
.getAccount(), context
);
74 * Synchronously executes the remote operation
76 * Do not call this method from the main thread.
78 * @param client Client object to reach an ownCloud server during the execution of the operation.
79 * @return Result of the operation.
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
);
90 * Asynchronously executes the remote operation
92 * This method should be used whenever an ownCloud account is available, instead of {@link #execute(OwnCloudClient)}.
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.
100 public Thread
execute(FileDataStorageManager storageManager
, Context context
, OnRemoteOperationListener listener
, Handler listenerHandler
, Activity callerActivity
) {
101 if (storageManager
== null
) {
102 throw new IllegalArgumentException("Trying to execute a sync operation with a NULL storage manager");
104 if (storageManager
.getAccount() == null
) {
105 throw new IllegalArgumentException("Trying to execute a sync operation with a storage manager for a NULL account");
107 mStorageManager
= storageManager
;
108 return super.execute(storageManager
.getAccount(), context
, listener
, listenerHandler
, callerActivity
);
113 * Asynchronously executes the remote operation
115 * @param client Client object to reach an ownCloud server during the execution of the operation.
116 * @param listener Listener to be notified about the execution of the operation.
117 * @param listenerHandler Handler associated to the thread where the methods of the listener objects must be called.
118 * @return Thread were the remote operation is executed.
120 public Thread
execute(OwnCloudClient client
, FileDataStorageManager storageManager
, OnRemoteOperationListener listener
, Handler listenerHandler
) {
121 if (storageManager
== null
) {
122 throw new IllegalArgumentException("Trying to execute a sync operation with a NULL storage manager");
124 mStorageManager
= storageManager
;
125 return super.execute(client
, listener
, listenerHandler
);