Add new string for share_groups_indicator
authormasensio <masensio@solidgear.es>
Mon, 19 Oct 2015 12:59:32 +0000 (14:59 +0200)
committerDavid A. Velasco <dvelasco@solidgear.es>
Fri, 30 Oct 2015 15:28:41 +0000 (16:28 +0100)
res/values/strings.xml
src/com/owncloud/android/ui/adapter/ShareUserListAdapter.java
src/com/owncloud/android/utils/UnshareWithUserAsyncTask.java [new file with mode: 0644]

index 987a9a0..b7c6155 100644 (file)
     <string name="share_no_users">No data shared with users yet</string>
     <string name="share_add_user_or_group">Add User or Group</string>
     <string name="share_search">Search</string>
+    <string name="share_group_indicator">(group)</string>
 
     <string name="search_users_and_groups_hint">Search users and groups</string>
 
index 900fe15..54ca46e 100644 (file)
@@ -78,7 +78,7 @@ public class ShareUserListAdapter extends ArrayAdapter {
             TextView userName = (TextView) view.findViewById(R.id.userOrGroupName);
             String name = share.getSharedWithDisplayName();
             if (share.getShareType() == ShareType.GROUP) {
-                name = name + "(group)";
+                name = name +  mContext.getResources().getString(R.string.share_group_indicator);
             }
             userName.setText(name);
 
diff --git a/src/com/owncloud/android/utils/UnshareWithUserAsyncTask.java b/src/com/owncloud/android/utils/UnshareWithUserAsyncTask.java
new file mode 100644 (file)
index 0000000..ede9568
--- /dev/null
@@ -0,0 +1,108 @@
+/**
+ *   ownCloud Android client application
+ *
+ *   @author masensio
+ *   Copyright (C) 2015 ownCloud Inc.
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License version 2,
+ *   as published by the Free Software Foundation.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.owncloud.android.utils;
+
+import android.accounts.Account;
+import android.os.AsyncTask;
+
+import com.owncloud.android.MainApp;
+import com.owncloud.android.datamodel.FileDataStorageManager;
+import com.owncloud.android.datamodel.OCFile;
+import com.owncloud.android.lib.common.OwnCloudAccount;
+import com.owncloud.android.lib.common.OwnCloudClient;
+import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
+import com.owncloud.android.lib.common.operations.RemoteOperationResult;
+import com.owncloud.android.lib.common.utils.Log_OC;
+import com.owncloud.android.lib.resources.shares.OCShare;
+import com.owncloud.android.operations.GetSharesForFileOperation;
+
+import java.lang.ref.WeakReference;
+import java.util.ArrayList;
+
+/**
+ * Async Task to get the users and groups which a file is shared with
+ */
+public class UnshareWithUserAsyncTask extends AsyncTask<Object, Void, RemoteOperationResult> {
+
+    private final String TAG = UnshareWithUserAsyncTask.class.getSimpleName();
+    private final WeakReference<OnGetSharesWithUserTaskListener> mListener;
+    private ArrayList<OCShare> mShares;
+
+    public ArrayList<OCShare> getShares(){
+        return mShares;
+    }
+
+    public UnshareWithUserAsyncTask(OnGetSharesWithUserTaskListener listener) {
+        mListener = new WeakReference<OnGetSharesWithUserTaskListener>(listener);
+    }
+
+    @Override
+    protected RemoteOperationResult doInBackground(Object... params) {
+
+        RemoteOperationResult result = null;
+
+        if (params != null && params.length == 3) {
+            OCFile file = (OCFile) params[0];
+            Account account = (Account) params[1];
+            FileDataStorageManager fileDataStorageManager = (FileDataStorageManager) params[2];
+
+            try {
+                // Get shares request
+                GetSharesForFileOperation operation =
+                        new GetSharesForFileOperation(file.getRemotePath(), false, false);
+                OwnCloudAccount ocAccount = new OwnCloudAccount(account,
+                        MainApp.getAppContext());
+                OwnCloudClient client = OwnCloudClientManagerFactory.getDefaultSingleton().
+                        getClientFor(ocAccount, MainApp.getAppContext());
+                result = operation.execute(client, fileDataStorageManager);
+
+            } catch (Exception e) {
+                result = new RemoteOperationResult(e);
+                Log_OC.e(TAG, "Exception while getting shares", e);
+            }
+        } else {
+            result = new RemoteOperationResult(RemoteOperationResult.ResultCode.UNKNOWN_ERROR);
+        }
+
+        return result;
+    }
+
+    @Override
+    protected void onPostExecute(RemoteOperationResult result) {
+
+        if (result!= null)
+        {
+            OnGetSharesWithUserTaskListener listener = mListener.get();
+            if (listener!= null)
+            {
+                listener.onGetDataShareWithFinish(result);
+            }
+        }
+    }
+
+    /*
+     * Interface to retrieve data from get shares task
+     */
+    public interface OnGetSharesWithUserTaskListener{
+
+        void onGetDataShareWithFinish(RemoteOperationResult result);
+    }
+}