Merge branch 'develop' into accessibility
[pub/Android/ownCloud.git] / src / com / owncloud / android / operations / GetSharesOperation.java
1 /**
2 * ownCloud Android client application
3 *
4 * @author masensio
5 * @author David A. Velasco
6 * Copyright (C) 2015 ownCloud Inc.
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2,
10 * as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22 package com.owncloud.android.operations;
23
24 import java.util.ArrayList;
25
26 import com.owncloud.android.lib.common.OwnCloudClient;
27 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
28 import com.owncloud.android.lib.common.utils.Log_OC;
29 import com.owncloud.android.lib.resources.shares.OCShare;
30 import com.owncloud.android.lib.resources.shares.GetRemoteSharesOperation;
31 import com.owncloud.android.operations.common.SyncOperation;
32
33 /**
34 * Access to remote operation to get the share files/folders
35 * Save the data in Database
36 */
37
38 public class GetSharesOperation extends SyncOperation {
39
40 private static final String TAG = GetSharesOperation.class.getSimpleName();
41
42 @Override
43 protected RemoteOperationResult run(OwnCloudClient client) {
44 GetRemoteSharesOperation operation = new GetRemoteSharesOperation();
45 RemoteOperationResult result = operation.execute(client);
46
47 if (result.isSuccess()) {
48
49 // Update DB with the response
50 Log_OC.d(TAG, "Share list size = " + result.getData().size());
51 ArrayList<OCShare> shares = new ArrayList<OCShare>();
52 for(Object obj: result.getData()) {
53 shares.add((OCShare) obj);
54 }
55
56 getStorageManager().saveSharesDB(shares);
57 }
58
59 return result;
60 }
61
62 }