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
;
26 import com
.owncloud
.android
.MainApp
;
27 import com
.owncloud
.android
.datamodel
.FileDataStorageManager
;
28 import com
.owncloud
.android
.datamodel
.OCFile
;
29 import com
.owncloud
.android
.lib
.common
.OwnCloudAccount
;
30 import com
.owncloud
.android
.lib
.common
.OwnCloudClient
;
31 import com
.owncloud
.android
.lib
.common
.OwnCloudClientManagerFactory
;
32 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperationResult
;
33 import com
.owncloud
.android
.lib
.common
.utils
.Log_OC
;
34 import com
.owncloud
.android
.lib
.resources
.shares
.OCShare
;
35 import com
.owncloud
.android
.operations
.GetSharesForFileOperation
;
37 import java
.lang
.ref
.WeakReference
;
38 import java
.util
.ArrayList
;
41 * Async Task to get the users and groups which a file is shared with
43 public class GetShareWithUsersAsyncTask
extends AsyncTask
<Object
, Void
, RemoteOperationResult
> {
45 private final String TAG
= GetShareWithUsersAsyncTask
.class.getSimpleName();
46 private final WeakReference
<OnGetSharesWithUsersTaskListener
> mListener
;
47 private ArrayList
<OCShare
> mShares
;
49 public ArrayList
<OCShare
> getShares(){
53 public GetShareWithUsersAsyncTask(OnGetSharesWithUsersTaskListener listener
) {
54 mListener
= new WeakReference
<OnGetSharesWithUsersTaskListener
>(listener
);
58 protected RemoteOperationResult
doInBackground(Object
... params
) {
60 RemoteOperationResult result
= null
;
62 if (params
!= null
&& params
.length
== 3) {
63 OCFile file
= (OCFile
) params
[0];
64 Account account
= (Account
) params
[1];
65 FileDataStorageManager fileDataStorageManager
= (FileDataStorageManager
) params
[2];
69 GetSharesForFileOperation operation
=
70 new GetSharesForFileOperation(file
.getRemotePath(), false
, false
);
71 OwnCloudAccount ocAccount
= new OwnCloudAccount(account
,
72 MainApp
.getAppContext());
73 OwnCloudClient client
= OwnCloudClientManagerFactory
.getDefaultSingleton().
74 getClientFor(ocAccount
, MainApp
.getAppContext());
75 result
= operation
.execute(client
, fileDataStorageManager
);
77 } catch (Exception e
) {
78 result
= new RemoteOperationResult(e
);
79 Log_OC
.e(TAG
, "Exception while getting shares", e
);
82 result
= new RemoteOperationResult(RemoteOperationResult
.ResultCode
.UNKNOWN_ERROR
);
89 protected void onPostExecute(RemoteOperationResult result
) {
93 OnGetSharesWithUsersTaskListener listener
= mListener
.get();
96 listener
.onGetDataShareWithFinish(result
);
102 * Interface to retrieve data from get shares task
104 public interface OnGetSharesWithUsersTaskListener
{
106 void onGetDataShareWithFinish(RemoteOperationResult result
);