2 * ownCloud Android client application
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
.utils
;
23 import android
.accounts
.Account
;
24 import android
.os
.AsyncTask
;
25 import android
.util
.Pair
;
27 import com
.owncloud
.android
.MainApp
;
28 import com
.owncloud
.android
.datamodel
.FileDataStorageManager
;
29 import com
.owncloud
.android
.datamodel
.OCFile
;
30 import com
.owncloud
.android
.lib
.common
.OwnCloudAccount
;
31 import com
.owncloud
.android
.lib
.common
.OwnCloudClient
;
32 import com
.owncloud
.android
.lib
.common
.OwnCloudClientManagerFactory
;
33 import com
.owncloud
.android
.lib
.common
.operations
.OnRemoteOperationListener
;
34 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperation
;
35 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperationResult
;
36 import com
.owncloud
.android
.lib
.common
.utils
.Log_OC
;
37 import com
.owncloud
.android
.operations
.GetSharesForFileOperation
;
39 import java
.lang
.ref
.WeakReference
;
42 * Async Task to get the users and groups which a file is shared with
44 public class GetShareWithUsersAsyncTask
extends AsyncTask
<Object
, Void
, Pair
<RemoteOperation
, RemoteOperationResult
>> {
46 private final String TAG
= GetShareWithUsersAsyncTask
.class.getSimpleName();
47 private final WeakReference
<OnRemoteOperationListener
> mListener
;
49 public GetShareWithUsersAsyncTask(OnRemoteOperationListener listener
) {
50 mListener
= new WeakReference
<OnRemoteOperationListener
>(listener
);
54 protected Pair
<RemoteOperation
, RemoteOperationResult
> doInBackground(Object
... params
) {
56 GetSharesForFileOperation operation
= null
;
57 RemoteOperationResult result
= null
;
59 if (params
!= null
&& params
.length
== 3) {
60 OCFile file
= (OCFile
) params
[0];
61 Account account
= (Account
) params
[1];
62 FileDataStorageManager fileDataStorageManager
= (FileDataStorageManager
) params
[2];
66 operation
= new GetSharesForFileOperation(file
.getRemotePath(), false
, false
);
67 OwnCloudAccount ocAccount
= new OwnCloudAccount(account
,
68 MainApp
.getAppContext());
69 OwnCloudClient client
= OwnCloudClientManagerFactory
.getDefaultSingleton().
70 getClientFor(ocAccount
, MainApp
.getAppContext());
71 result
= operation
.execute(client
, fileDataStorageManager
);
73 } catch (Exception e
) {
74 result
= new RemoteOperationResult(e
);
75 Log_OC
.e(TAG
, "Exception while getting shares", e
);
78 result
= new RemoteOperationResult(RemoteOperationResult
.ResultCode
.UNKNOWN_ERROR
);
81 return new Pair(operation
, result
);
85 protected void onPostExecute(Pair
<RemoteOperation
, RemoteOperationResult
> result
) {
89 OnRemoteOperationListener listener
= mListener
.get();
92 listener
.onRemoteOperationFinish(result
.first
, result
.second
);