浏览代码

Add share users to details view

masensio 9 年之前
父节点
当前提交
b2a1d9962f

二进制
res/drawable-hdpi/ic_account_circle_dark.png


二进制
res/drawable-hdpi/ic_group_dark.png


二进制
res/drawable-mdpi/ic_account_circle_dark.png


二进制
res/drawable-mdpi/ic_group_dark.png


二进制
res/drawable-xhdpi/ic_account_circle_dark.png


二进制
res/drawable-xhdpi/ic_group_dark.png


二进制
res/drawable-xxhdpi/ic_account_circle_dark.png


二进制
res/drawable-xxhdpi/ic_group_dark.png


二进制
res/drawable-xxxhdpi/ic_account_circle_dark.png


二进制
res/drawable-xxxhdpi/ic_group_dark.png


+ 5 - 6
res/layout/file_details_fragment.xml

@@ -109,8 +109,7 @@
                             android:layout_width="wrap_content"
                             android:layout_height="wrap_content"
                             android:text="@string/placeholder_filetype"
-                            android:textSize="16sp"
-                            android:maxLines="2"/>
+                            android:textSize="16sp"/>
 
                     </TableRow>
                     <TableRow
@@ -138,7 +137,8 @@
                         android:layout_width="match_parent"
                         android:layout_height="wrap_content"
                         android:padding="5dp"
-                        android:layout_marginTop="12dp">
+                        android:layout_marginTop="12dp"
+                        android:visibility="gone">
                         <TextView
                             android:id="@+id/fdCreatedLabel"
                             android:layout_width="wrap_content"
@@ -283,15 +283,14 @@
                     <ListView
                         android:layout_width="match_parent"
                         android:layout_height="0dip"
-                        android:id="@+id/shareUsersList"
+                        android:id="@+id/fdshareUsersList"
                         android:visibility="gone"
-                        android:scrollbars="vertical"
                         android:layout_weight="1"/>
 
                     <TextView
                         android:layout_width="match_parent"
                         android:layout_height="wrap_content"
-                        android:id="@+id/shareNoUsers"
+                        android:id="@+id/fdShareNoUsers"
                         android:text="@string/share_no_users"
                         android:textSize="12sp"
                         android:padding="12dp" />

+ 56 - 0
res/layout/file_details_share_user_item.xml

@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ownCloud Android client application
+  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/>.
+-->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+              android:layout_width="match_parent"
+              android:layout_height="match_parent"
+              android:orientation="vertical">
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:orientation="horizontal"
+        android:weightSum="1"
+        android:longClickable="true">
+
+        <ImageView
+            android:id="@+id/userIcon"
+            android:layout_width="24sp"
+            android:layout_height="24sp"
+            android:layout_marginLeft="16sp"
+            android:layout_gravity="center_vertical"
+            android:src="@drawable/ic_account_circle_dark"
+            />
+
+        <TextView
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_weight="0.9"
+            android:textSize="16dip"
+            android:text="@string/username"
+            android:id="@+id/userOrGroupName"
+            android:layout_margin="12dp"
+            android:singleLine="true"
+            android:ellipsize="middle"
+            android:textColor="@color/owncloud_blue"/>
+    </LinearLayout>
+
+    <View
+        android:layout_width="match_parent"
+        android:layout_height="1dp"
+        android:background="@color/list_divider_background"></View>
+</LinearLayout>

+ 87 - 0
src/com/owncloud/android/ui/adapter/UserListAdapter.java

@@ -0,0 +1,87 @@
+/**
+ *   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.ui.adapter;
+
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import com.owncloud.android.R;
+import com.owncloud.android.lib.resources.shares.OCShare;
+import com.owncloud.android.lib.resources.shares.ShareType;
+
+import java.util.ArrayList;
+
+/**
+ * Adapter to show a user/group in Share With List in Details View
+ */
+public class UserListAdapter extends ArrayAdapter {
+
+    private Context mContext;
+    private ArrayList<OCShare> mShares;
+
+    public UserListAdapter(Context context, int resource, ArrayList<OCShare> shares) {
+        super(context, resource);
+        mContext = context;
+        mShares = shares;
+    }
+
+    @Override
+    public int getCount() {
+        return mShares.size();
+    }
+
+    @Override
+    public Object getItem(int position) {
+        return mShares.get(position);
+    }
+
+    @Override
+    public long getItemId(int position) {
+        return 0;
+    }
+
+    @Override
+    public View getView(final int position, View convertView, ViewGroup parent) {
+        LayoutInflater inflator = (LayoutInflater) mContext
+                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+        View view = inflator.inflate(R.layout.file_details_share_user_item, parent, false);
+
+        if (mShares != null && mShares.size() > position) {
+            OCShare share = mShares.get(position);
+
+            TextView userName = (TextView) view.findViewById(R.id.userOrGroupName);
+            ImageView icon = (ImageView) view.findViewById(R.id.userIcon);
+            String name = share.getSharedWithDisplayName();
+            if (share.getShareType() == ShareType.GROUP) {
+                name = getContext().getString(R.string.share_group_clarification, name);
+                icon.setImageResource(R.drawable.ic_group_dark);
+            }
+            userName.setText(name);
+
+        }
+        return view;
+    }
+}

+ 83 - 7
src/com/owncloud/android/ui/fragment/FileDetailFragment.java

@@ -32,6 +32,7 @@ import android.view.View;
 import android.view.View.OnClickListener;
 import android.view.ViewGroup;
 import android.widget.ImageView;
+import android.widget.ListView;
 import android.widget.ProgressBar;
 import android.widget.RelativeLayout;
 import android.widget.Switch;
@@ -47,14 +48,17 @@ import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
 import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
 import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
 import com.owncloud.android.lib.common.utils.Log_OC;
+import com.owncloud.android.lib.resources.shares.OCShare;
 import com.owncloud.android.ui.activity.FileActivity;
 import com.owncloud.android.ui.activity.FileDisplayActivity;
+import com.owncloud.android.ui.adapter.UserListAdapter;
 import com.owncloud.android.ui.dialog.RemoveFileDialogFragment;
 import com.owncloud.android.ui.dialog.RenameFileDialogFragment;
 import com.owncloud.android.utils.DisplayUtils;
 import com.owncloud.android.utils.MimetypeIconUtil;
 
 import java.lang.ref.WeakReference;
+import java.util.ArrayList;
 
 
 /**
@@ -62,12 +66,6 @@ import java.lang.ref.WeakReference;
  */
 public class FileDetailFragment extends FileFragment implements OnClickListener {
 
-    private int mLayout;
-    private View mView;
-    private Account mAccount;
-
-    public ProgressListener mProgressListener;
-
     private static final String TAG = FileDetailFragment.class.getSimpleName();
     public static final String FTAG_CONFIRMATION = "REMOVE_CONFIRMATION_FRAGMENT";
     public static final String FTAG_RENAME_FILE = "RENAME_FILE_FRAGMENT";
@@ -75,6 +73,16 @@ public class FileDetailFragment extends FileFragment implements OnClickListener
     private static final String ARG_FILE = "FILE";
     private static final String ARG_ACCOUNT = "ACCOUNT";
 
+    private int mLayout;
+    private View mView;
+    private Account mAccount;
+
+    public ProgressListener mProgressListener;
+
+    // to show share with users/groups info
+    private ArrayList<OCShare> mShares;
+    private UserListAdapter mUserGroupsAdapter = null;
+
 
     /**
      * Public factory method to create new FileDetailFragment instances.
@@ -342,7 +350,11 @@ public class FileDetailFragment extends FileFragment implements OnClickListener
             setTimeModified(file.getModificationTimestamp());
             
             Switch favSwitch = (Switch) getView().findViewById(R.id.fdFavorite);
-            favSwitch.setChecked(file.isFavorite());
+            favSwitch.setActivated(file.isFavorite());
+
+            setShareByLinkInfo(file.isSharedViaLink());
+
+            setShareWithUserInfo();
 
             // configure UI for depending upon local state of the file
             FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();
@@ -481,6 +493,70 @@ public class FileDetailFragment extends FileFragment implements OnClickListener
         }
     }
 
+    /**
+     * Updates the creation time of the file
+     *
+     * @param milliseconds Unix time to set
+     */
+    private void setTimeCreated(long milliseconds) {
+        TextView tv = (TextView) getView().findViewById(R.id.fdCreated);
+        if (tv != null) {
+            tv.setText(DisplayUtils.unixTimeToHumanReadable(milliseconds));
+        }
+    }
+
+    /**
+     * Updates Share by link data
+     * @param isShareByLink
+     */
+    private void setShareByLinkInfo(boolean isShareByLink) {
+        TextView tv = (TextView) getView().findViewById(R.id.fdSharebyLink);
+        if (tv != null) {
+            tv.setText(isShareByLink ? R.string.filedetails_share_link_enable :
+                    R.string.filedetails_share_link_disable);
+        }
+    }
+
+    /**
+     * Update Share With data
+     */
+    private void setShareWithUserInfo(){
+        // Get Users and Groups
+        if (((FileActivity) getActivity()).getStorageManager() != null) {
+            FileDataStorageManager fileDataStorageManager = ((FileActivity) getActivity()).getStorageManager();
+            mShares =fileDataStorageManager.getSharesWithForAFile(
+                    getFile().getRemotePath(),mAccount.name
+            );
+
+            // Update list of users/groups
+            updateListOfUserGroups();
+        }
+    }
+
+    private void updateListOfUserGroups() {
+        // Update list of users/groups
+        // TODO Refactoring: create a new {@link ShareUserListAdapter} instance with every call should not be needed
+        mUserGroupsAdapter = new UserListAdapter(
+                getActivity().getApplicationContext(),
+                R.layout.share_user_item, mShares
+        );
+
+        // Show data
+        ListView usersList = (ListView) getView().findViewById(R.id.fdshareUsersList);
+
+        // No data
+        TextView noList = (TextView) getView().findViewById(R.id.fdShareNoUsers);
+
+        if (mShares.size() > 0) {
+            usersList.setVisibility(View.VISIBLE);
+            usersList.setAdapter(mUserGroupsAdapter);
+            noList.setVisibility(View.GONE);
+
+        } else {
+            usersList.setVisibility(View.GONE);
+            noList.setVisibility(View.VISIBLE);
+        }
+    }
     /**
      * Enables or disables buttons for a file being downloaded
      */