ソースを参照

cleanup details fragment, use standard character avatars for sharees instead of grey icons (just for iteration 1)

AndyScherzinger 7 年 前
コミット
adb9ab24ef

+ 24 - 4
src/main/java/com/owncloud/android/ui/adapter/UserListAdapter.java

@@ -32,7 +32,10 @@ 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 com.owncloud.android.ui.TextDrawable;
 
+import java.io.UnsupportedEncodingException;
+import java.security.NoSuchAlgorithmException;
 import java.util.ArrayList;
 
 /**
@@ -42,11 +45,14 @@ public class UserListAdapter extends ArrayAdapter {
 
     private Context mContext;
     private ArrayList<OCShare> mShares;
+    private float mAvatarRadiusDimension;
 
     public UserListAdapter(Context context, int resource, ArrayList<OCShare> shares) {
         super(context, resource);
         mContext = context;
         mShares = shares;
+
+        mAvatarRadiusDimension = context.getResources().getDimension(R.dimen.standard_padding);
     }
 
     @Override
@@ -75,15 +81,29 @@ public class UserListAdapter extends ArrayAdapter {
         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);
+            TextView userName = view.findViewById(R.id.userOrGroupName);
+            ImageView icon = 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);
+                try {
+                    icon.setImageDrawable(TextDrawable.createNamedAvatar(name, mAvatarRadiusDimension));
+                } catch (UnsupportedEncodingException | NoSuchAlgorithmException e) {
+                    icon.setImageResource(R.drawable.ic_group);
+                }
             } else if (share.getShareType() == ShareType.EMAIL) {
                 name = getContext().getString(R.string.share_email_clarification, name);
-                icon.setImageResource(R.drawable.ic_email);
+                try {
+                    icon.setImageDrawable(TextDrawable.createNamedAvatar(name, mAvatarRadiusDimension));
+                } catch (UnsupportedEncodingException | NoSuchAlgorithmException e) {
+                    icon.setImageResource(R.drawable.ic_email);
+                }
+            } else {
+                try {
+                    icon.setImageDrawable(TextDrawable.createNamedAvatar(name, mAvatarRadiusDimension));
+                } catch (UnsupportedEncodingException | NoSuchAlgorithmException e) {
+                    icon.setImageResource(R.drawable.ic_user);
+                }
             }
             userName.setText(name);
 

+ 2 - 109
src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java

@@ -23,9 +23,6 @@ package com.owncloud.android.ui.fragment;
 
 import android.accounts.Account;
 import android.graphics.Bitmap;
-import android.graphics.drawable.ColorDrawable;
-import android.graphics.drawable.Drawable;
-import android.graphics.drawable.LayerDrawable;
 import android.os.Build;
 import android.os.Bundle;
 import android.support.annotation.NonNull;
@@ -38,17 +35,11 @@ import android.view.MenuItem;
 import android.view.View;
 import android.view.View.OnClickListener;
 import android.view.ViewGroup;
-import android.webkit.URLUtil;
 import android.widget.ImageView;
-import android.widget.ListAdapter;
-import android.widget.ListView;
 import android.widget.PopupMenu;
 import android.widget.ProgressBar;
 import android.widget.TextView;
 
-import com.bumptech.glide.Glide;
-import com.bumptech.glide.request.animation.GlideAnimation;
-import com.bumptech.glide.request.target.SimpleTarget;
 import com.owncloud.android.MainApp;
 import com.owncloud.android.R;
 import com.owncloud.android.datamodel.FileDataStorageManager;
@@ -59,12 +50,10 @@ 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.activity.ToolbarActivity;
 import com.owncloud.android.ui.adapter.FileDetailTabAdapter;
-import com.owncloud.android.ui.adapter.UserListAdapter;
 import com.owncloud.android.ui.dialog.RemoveFilesDialogFragment;
 import com.owncloud.android.ui.dialog.RenameFileDialogFragment;
 import com.owncloud.android.utils.AnalyticsUtils;
@@ -73,7 +62,6 @@ import com.owncloud.android.utils.MimeTypeUtil;
 import com.owncloud.android.utils.ThemeUtils;
 
 import java.lang.ref.WeakReference;
-import java.util.ArrayList;
 
 
 /**
@@ -90,9 +78,6 @@ public class FileDetailFragment extends FileFragment implements OnClickListener
 
     public ProgressListener progressListener;
 
-    // to show share with users/groups info
-    private ArrayList<OCShare> shares;
-
     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";
@@ -316,7 +301,6 @@ public class FileDetailFragment extends FileFragment implements OnClickListener
         super.onStop();
     }
 
-
     @Override
     public View getView() {
         return super.getView() == null ? view : super.getView();
@@ -457,7 +441,6 @@ public class FileDetailFragment extends FileFragment implements OnClickListener
         return (layout == R.layout.file_details_empty || getFile() == null || account == null);
     }
 
-
     /**
      * Use this method to signal this Activity that it shall update its view.
      *
@@ -471,7 +454,7 @@ public class FileDetailFragment extends FileFragment implements OnClickListener
 
     /**
      * Updates the view with all relevant details about that file.
-     * <p/>
+     *
      * TODO Remove parameter when the transferring state of files is kept in database.
      *
      * @param transferring Flag signaling if the file should be considered as downloading or uploading,
@@ -538,7 +521,6 @@ public class FileDetailFragment extends FileFragment implements OnClickListener
         return (getFile() != null && account != null && layout == R.layout.file_details_fragment);
     }
 
-
     /**
      * Updates the filename in view
      *
@@ -650,90 +632,6 @@ public class FileDetailFragment extends FileFragment implements OnClickListener
         }
     }
 
-    /**
-     * Updates Share by link data
-     *
-     * @param isShareByLink flag is share by link is enable
-     */
-    private void setShareByLinkInfo(boolean isShareByLink) {
-        TextView tv = getView().findViewById(R.id.fdSharebyLink);
-        if (tv != null) {
-            tv.setText(isShareByLink ? R.string.filedetails_share_link_enable :
-                    R.string.filedetails_share_link_disable);
-        }
-        ImageView linkIcon = getView().findViewById(R.id.fdShareLinkIcon);
-        if (linkIcon != null) {
-            linkIcon.setVisibility(isShareByLink ? View.VISIBLE : View.GONE);
-        }
-    }
-
-    /**
-     * Update Share With data
-     */
-    private void setShareWithUserInfo(){
-        // Get Users and Groups
-        if (((FileActivity) getActivity()).getStorageManager() != null) {
-            FileDataStorageManager fileDataStorageManager = ((FileActivity) getActivity()).getStorageManager();
-            shares = fileDataStorageManager.getSharesWithForAFile(
-                    getFile().getRemotePath(), account.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
-        UserListAdapter mUserGroupsAdapter = new UserListAdapter(
-                getActivity().getApplicationContext(),
-                R.layout.share_user_item, shares
-        );
-
-        // Show data
-        ListView usersList = getView().findViewById(R.id.fdshareUsersList);
-
-        // No data
-        TextView noList = getView().findViewById(R.id.fdShareNoUsers);
-
-        if (shares.size() > 0) {
-            usersList.setVisibility(View.VISIBLE);
-            usersList.setAdapter(mUserGroupsAdapter);
-            noList.setVisibility(View.GONE);
-            setListViewHeightBasedOnChildren(usersList);
-
-        } else {
-            usersList.setVisibility(View.GONE);
-            noList.setVisibility(View.VISIBLE);
-        }
-    }
-
-    /**
-     * Fix scroll in listview when the parent is a ScrollView
-     */
-    private static void setListViewHeightBasedOnChildren(ListView listView) {
-        ListAdapter listAdapter = listView.getAdapter();
-        if (listAdapter == null) {
-            return;
-        }
-        int desiredWidth = View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.AT_MOST);
-        int totalHeight = 0;
-        View view = null;
-        for (int i = 0; i < listAdapter.getCount(); i++) {
-            view = listAdapter.getView(i, view, listView);
-            if (i == 0) {
-                view.setLayoutParams(new ViewGroup.LayoutParams(desiredWidth, ViewGroup.LayoutParams.WRAP_CONTENT));
-            }
-            view.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED);
-            totalHeight += view.getMeasuredHeight();
-        }
-        ViewGroup.LayoutParams params = listView.getLayoutParams();
-        params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
-        listView.setLayoutParams(params);
-        listView.requestLayout();
-    }
-
     /**
      * Enables or disables buttons for a file being downloaded
      */
@@ -781,7 +679,6 @@ public class FileDetailFragment extends FileFragment implements OnClickListener
         }
     }
 
-
     public void listenForTransferProgress() {
         if (progressListener != null) {
             if (mContainerActivity.getFileDownloaderBinder() != null) {
@@ -797,7 +694,6 @@ public class FileDetailFragment extends FileFragment implements OnClickListener
         }
     }
 
-
     public void leaveTransferProgress() {
         if (progressListener != null) {
             if (mContainerActivity.getFileDownloaderBinder() != null) {
@@ -811,14 +707,13 @@ public class FileDetailFragment extends FileFragment implements OnClickListener
         }
     }
 
-
     /**
      * Helper class responsible for updating the progress bar shown for file uploading or
      * downloading
      */
     private class ProgressListener implements OnDatatransferProgressListener {
         int mLastPercent = 0;
-        WeakReference<ProgressBar> mProgressBar = null;
+        WeakReference<ProgressBar> mProgressBar;
 
         ProgressListener(ProgressBar progressBar) {
             mProgressBar = new WeakReference<ProgressBar>(progressBar);
@@ -837,7 +732,5 @@ public class FileDetailFragment extends FileFragment implements OnClickListener
             }
             mLastPercent = percent;
         }
-
     }
-
 }

+ 12 - 2
src/main/res/layout/file_details_share_user_item.xml

@@ -21,6 +21,8 @@
     android:layout_height="wrap_content"
     android:orientation="horizontal"
     android:weightSum="1"
+    android:paddingTop="@dimen/standard_eigth_padding"
+    android:paddingBottom="@dimen/standard_eigth_padding"
     tools:ignore="UseCompoundDrawables">
 
         <ImageView
@@ -29,16 +31,24 @@
             android:layout_height="@dimen/file_details_user_icon_layout_height"
             android:src="@drawable/ic_user"
             android:layout_gravity="center_vertical"
+            android:layout_marginTop="@dimen/standard_half_margin"
+            android:layout_marginBottom="@dimen/standard_half_margin"
+            android:layout_marginLeft="@dimen/standard_margin"
+            android:layout_marginStart="@dimen/standard_margin"
+            android:layout_marginEnd="@dimen/standard_margin"
+            android:layout_marginRight="@dimen/standard_margin"
             android:contentDescription="@string/user_icon"/>
 
         <TextView
             android:layout_width="match_parent"
-            android:layout_height="wrap_content"
+            android:layout_height="match_parent"
             android:textSize="@dimen/file_details_username_text_size"
             android:text="@string/username"
             android:id="@+id/userOrGroupName"
-            android:layout_margin="@dimen/file_details_username_layout_text_margin"
+            android:layout_marginRight="@dimen/standard_margin"
+            android:layout_marginEnd="@dimen/standard_margin"
             android:singleLine="true"
             android:ellipsize="middle"
+            android:gravity="center_vertical"
             android:textColor="@color/black"/>
 </LinearLayout>

+ 65 - 67
src/main/res/layout/file_details_sharing_fragment.xml

@@ -17,89 +17,87 @@
   You should have received a copy of the GNU Affero 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"
+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
-    android:orientation="vertical">
+    android:layout_weight="1">
 
-    <ScrollView
+    <LinearLayout
+        android:id="@+id/fdShareContainer"
         android:layout_width="match_parent"
-        android:layout_height="0dp"
-        android:layout_weight="1">
+        android:layout_height="wrap_content"
+        android:orientation="vertical"
+        android:paddingTop="@dimen/standard_padding">
 
-        <LinearLayout
-            android:id="@+id/fdShareContainer"
+        <TextView
+            android:id="@+id/fdShareTitle"
+            style="@style/TextAppearance.AppCompat.Body2"
             android:layout_width="match_parent"
-            android:layout_height="match_parent"
+            android:layout_height="wrap_content"
             android:layout_marginBottom="@dimen/standard_half_margin"
-            android:layout_marginLeft="@dimen/standard_margin"
-            android:layout_marginRight="@dimen/standard_margin"
-            android:layout_marginTop="@dimen/standard_half_margin"
-            android:orientation="vertical">
-
-            <TextView
-                android:id="@+id/fdShareTitle"
-                style="@style/TextAppearance.AppCompat.Body2"
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:layout_marginBottom="@dimen/standard_half_margin"
-                android:text="@string/action_send_share"
-                android:textColor="@color/color_accent" />
+            android:paddingLeft="@dimen/standard_padding"
+            android:paddingRight="@dimen/standard_padding"
+            android:text="@string/action_send_share"
+            android:textColor="@color/color_accent" />
 
-            <LinearLayout
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:orientation="horizontal"
-                tools:ignore="UseCompoundDrawables">
-
-                <ImageView
-                    android:id="@+id/fdShareLinkIcon"
-                    android:layout_width="@dimen/shared_list_icon_width"
-                    android:layout_height="@dimen/shared_list_icon_height"
-                    android:layout_gravity="center_vertical"
-                    android:layout_marginEnd="@dimen/standard_half_margin"
-                    android:layout_marginRight="@dimen/standard_half_margin"
-                    android:contentDescription="@string/shared_icon"
-                    android:src="@drawable/shared_via_link"
-                    android:visibility="gone" />
-
-                <TextView
-                    android:id="@+id/fdSharebyLink"
-                    android:layout_width="match_parent"
-                    android:layout_height="wrap_content"
-                    android:layout_gravity="start"
-                    android:text="@string/filedetails_share_link_disable" />
-            </LinearLayout>
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:orientation="horizontal"
+            android:paddingLeft="@dimen/standard_padding"
+            android:paddingRight="@dimen/standard_padding"
+            tools:ignore="UseCompoundDrawables">
+
+            <ImageView
+                android:id="@+id/fdShareLinkIcon"
+                android:layout_width="@dimen/shared_list_icon_width"
+                android:layout_height="@dimen/shared_list_icon_height"
+                android:layout_gravity="center_vertical"
+                android:layout_marginEnd="@dimen/standard_half_margin"
+                android:layout_marginRight="@dimen/standard_half_margin"
+                android:contentDescription="@string/shared_icon"
+                android:src="@drawable/shared_via_link"
+                android:visibility="gone" />
 
             <TextView
-                android:id="@+id/fdShareWithUsersTitle"
-                style="@style/TextAppearance.AppCompat.Body2"
+                android:id="@+id/fdSharebyLink"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:layout_gravity="start"
-                android:layout_marginBottom="@dimen/standard_half_margin"
-                android:layout_marginTop="@dimen/standard_half_margin"
-                android:text="@string/filedetails_share_users_with_access"
-                android:textColor="@color/color_accent" />
+                android:text="@string/filedetails_share_link_disable" />
+        </LinearLayout>
 
-            <ListView
-                android:id="@+id/fdshareUsersList"
-                android:layout_width="match_parent"
-                android:layout_height="0dip"
-                android:layout_weight="1"
-                android:visibility="gone" />
+        <TextView
+            android:id="@+id/fdShareWithUsersTitle"
+            style="@style/TextAppearance.AppCompat.Body2"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_gravity="start"
+            android:layout_marginBottom="@dimen/standard_half_margin"
+            android:layout_marginTop="@dimen/standard_half_margin"
+            android:paddingLeft="@dimen/standard_padding"
+            android:paddingRight="@dimen/standard_padding"
+            android:text="@string/filedetails_share_users_with_access"
+            android:textColor="@color/color_accent" />
 
-            <TextView
-                android:id="@+id/fdShareNoUsers"
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:text="@string/share_no_users"
-                android:textSize="@dimen/share_no_users_text_size" />
+        <ListView
+            android:id="@+id/fdshareUsersList"
+            android:layout_width="match_parent"
+            android:layout_height="0dip"
+            android:layout_weight="1"
+            android:visibility="gone" />
 
-        </LinearLayout>
+        <TextView
+            android:id="@+id/fdShareNoUsers"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:paddingBottom="@dimen/standard_padding"
+            android:paddingLeft="@dimen/standard_padding"
+            android:paddingRight="@dimen/standard_padding"
+            android:text="@string/share_no_users"
+            android:textSize="@dimen/share_no_users_text_size" />
 
-    </ScrollView>
+    </LinearLayout>
 
-</LinearLayout>
+</ScrollView>