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
.lib
.resources
.shares
.RemoveRemoteShareOperation
;
36 import com
.owncloud
.android
.operations
.GetSharesForFileOperation
;
38 import java
.lang
.ref
.WeakReference
;
39 import java
.util
.ArrayList
;
42 * Async Task to delete a share
44 public class UnshareWithUserAsyncTask
extends AsyncTask
<Object
, Void
, RemoteOperationResult
> {
46 private final String TAG
= UnshareWithUserAsyncTask
.class.getSimpleName();
47 private final WeakReference
<OnUnshareWithUserTaskListener
> mListener
;
49 public UnshareWithUserAsyncTask(OnUnshareWithUserTaskListener listener
) {
50 mListener
= new WeakReference
<OnUnshareWithUserTaskListener
>(listener
);
54 protected RemoteOperationResult
doInBackground(Object
... params
) {
56 RemoteOperationResult result
= null
;
58 if (params
!= null
&& params
.length
== 3) {
59 int shareId
= (int) params
[0];
60 Account account
= (Account
) params
[1];
61 FileDataStorageManager fileDataStorageManager
= (FileDataStorageManager
) params
[2];
65 RemoveRemoteShareOperation operation
=
66 new RemoveRemoteShareOperation(shareId
);
67 OwnCloudAccount ocAccount
= new OwnCloudAccount(account
,
68 MainApp
.getAppContext());
69 OwnCloudClient client
= OwnCloudClientManagerFactory
.getDefaultSingleton().
70 getClientFor(ocAccount
, MainApp
.getAppContext());
71 result
= operation
.execute(client
);
73 } catch (Exception e
) {
74 result
= new RemoteOperationResult(e
);
75 Log_OC
.e(TAG
, "Exception while unshare", e
);
78 result
= new RemoteOperationResult(RemoteOperationResult
.ResultCode
.UNKNOWN_ERROR
);
85 protected void onPostExecute(RemoteOperationResult result
) {
89 OnUnshareWithUserTaskListener listener
= mListener
.get();
92 listener
.onUnshareWithFinish(result
);
98 * Interface to retrieve the result
100 public interface OnUnshareWithUserTaskListener
{
102 void onUnshareWithFinish(RemoteOperationResult result
);