Browse Source

Remove containers in user info

Replace designated containers with Recycler And adapter.
Bartosz Przybylski 7 years ago
parent
commit
23162c36bf

+ 98 - 90
src/main/java/com/owncloud/android/ui/activity/UserInfoActivity.java

@@ -43,7 +43,11 @@ import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 import android.support.design.widget.AppBarLayout;
 import android.support.v4.graphics.drawable.DrawableCompat;
+import android.support.v7.widget.DividerItemDecoration;
+import android.support.v7.widget.RecyclerView;
+import android.support.v7.widget.helper.ItemTouchHelper;
 import android.text.TextUtils;
+import android.view.LayoutInflater;
 import android.view.Menu;
 import android.view.MenuInflater;
 import android.view.MenuItem;
@@ -81,6 +85,9 @@ import org.greenrobot.eventbus.Subscribe;
 import org.greenrobot.eventbus.ThreadMode;
 import org.parceler.Parcels;
 
+import java.util.LinkedList;
+import java.util.List;
+
 /**
  * This Activity presents the user information.
  */
@@ -93,80 +100,18 @@ public class UserInfoActivity extends FileActivity {
 
     private static final int KEY_DELETE_CODE = 101;
 
-    @BindView(R.id.empty_list_view)
-    public LinearLayout emptyContentContainer;
-
-    @BindView(R.id.empty_list_view_text)
-    public TextView emptyContentMessage;
-
-    @BindView(R.id.empty_list_view_headline)
-    public TextView emptyContentHeadline;
-
-    @BindView(R.id.empty_list_icon)
-    public ImageView emptyContentIcon;
-
-    @BindView(R.id.user_info_view)
-    public LinearLayout userInfoView;
-
-    @BindView(R.id.user_icon)
-    public ImageView avatar;
-
-    @BindView(R.id.userinfo_username)
-    public TextView userName;
-
-    @BindView(R.id.userinfo_username_full)
-    public TextView fullName;
-
-    @BindView(R.id.phone_container)
-    public View mPhoneNumberContainer;
-
-    @BindView(R.id.phone_number)
-    public TextView mPhoneNumberTextView;
-
-    @BindView(R.id.phone_icon)
-    public ImageView mPhoneNumberIcon;
-
-    @BindView(R.id.email_container)
-    public View mEmailContainer;
-
-    @BindView(R.id.email_address)
-    public TextView mEmailAddressTextView;
-
-    @BindView(R.id.email_icon)
-    public ImageView mEmailIcon;
-
-    @BindView(R.id.address_container)
-    public View mAddressContainer;
-
-    @BindView(R.id.address)
-    public TextView mAddressTextView;
-
-    @BindView(R.id.address_icon)
-    public ImageView mAddressIcon;
-
-    @BindView(R.id.website_container)
-    public View mWebsiteContainer;
-
-    @BindView(R.id.website_address)
-    public TextView mWebsiteTextView;
-
-    @BindView(R.id.website_icon)
-    public ImageView mWebsiteIcon;
-
-    @BindView(R.id.twitter_container)
-    public View mTwitterContainer;
-
-    @BindView(R.id.twitter_handle)
-    public TextView mTwitterHandleTextView;
-
-    @BindView(R.id.twitter_icon)
-    public ImageView mTwitterIcon;
-
-    @BindView(R.id.empty_list_progress)
-    public ProgressBar multiListProgressBar;
-
-    @BindString(R.string.user_information_retrieval_error)
-    public String sorryMessage;
+    @BindView(R.id.empty_list_view) LinearLayout emptyContentContainer;
+    @BindView(R.id.empty_list_view_text) TextView emptyContentMessage;
+    @BindView(R.id.empty_list_view_headline) TextView emptyContentHeadline;
+    @BindView(R.id.empty_list_icon) ImageView emptyContentIcon;
+    @BindView(R.id.user_info_view) LinearLayout userInfoView;
+    @BindView(R.id.user_icon) ImageView avatar;
+    @BindView(R.id.userinfo_username) TextView userName;
+    @BindView(R.id.userinfo_username_full) TextView fullName;
+    @BindView(R.id.user_info_list) RecyclerView mUserInfoList;
+    @BindView(R.id.empty_list_progress) ProgressBar multiListProgressBar;
+    
+    @BindString(R.string.user_information_retrieval_error) String sorryMessage;
 
     private float mCurrentAccountAvatarRadiusDimension;
 
@@ -202,6 +147,8 @@ public class UserInfoActivity extends FileActivity {
         setupToolbar(useBackgroundImage);
         updateActionBarTitleAndHomeButtonByString("");
 
+        mUserInfoList.setAdapter(new UserInfoAdapter(null, ThemeUtils.primaryColor(getAccount())));
+        mUserInfoList.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
 
         if (userInfo != null) {
             populateUserInfoUi(userInfo);
@@ -335,25 +282,27 @@ public class UserInfoActivity extends FileActivity {
             emptyContentContainer.setVisibility(View.GONE);
             userInfoView.setVisibility(View.VISIBLE);
 
-            populateUserInfoElement(mPhoneNumberContainer, mPhoneNumberTextView, userInfo.getPhone(), mPhoneNumberIcon,
-                    tint);
-            populateUserInfoElement(mEmailContainer, mEmailAddressTextView, userInfo.getEmail(), mEmailIcon, tint);
-            populateUserInfoElement(mAddressContainer, mAddressTextView, userInfo.getAddress(), mAddressIcon, tint);
-            populateUserInfoElement(mWebsiteContainer, mWebsiteTextView,
-                    DisplayUtils.beautifyURL(userInfo.getWebpage()), mWebsiteIcon, tint);
-            populateUserInfoElement(mTwitterContainer, mTwitterHandleTextView,
-                    DisplayUtils.beautifyTwitterHandle(userInfo.getTwitter()), mTwitterIcon, tint);
+            if (mUserInfoList.getAdapter() instanceof UserInfoAdapter) {
+                mUserInfoList.setAdapter(new UserInfoAdapter(createUserInfoDetails(userInfo), tint));
+            }
         }
     }
 
-    private void populateUserInfoElement(View container, TextView textView, String text, ImageView icon,
-                                         @ColorInt int tint) {
-        if (!TextUtils.isEmpty(text)) {
-            textView.setText(text);
-            DrawableCompat.setTint(icon.getDrawable(), tint);
-        } else {
-            container.setVisibility(View.GONE);
-        }
+    private List<UserInfoDetailsItem> createUserInfoDetails(UserInfo userInfo) {
+        List<UserInfoDetailsItem> result = new LinkedList<>();
+
+        addToListIfNeeded(result, R.drawable.ic_phone, userInfo.getPhone());
+        addToListIfNeeded(result, R.drawable.ic_email, userInfo.getEmail());
+        addToListIfNeeded(result, R.drawable.ic_map_marker, userInfo.getAddress());
+        addToListIfNeeded(result, R.drawable.ic_web, DisplayUtils.beautifyURL(userInfo.getWebpage()));
+        addToListIfNeeded(result, R.drawable.ic_twitter, DisplayUtils.beautifyTwitterHandle(userInfo.getTwitter()));
+
+        return result;
+    }
+
+    private void addToListIfNeeded(List<UserInfoDetailsItem> info, @DrawableRes int icon, String text) {
+        if (!TextUtils.isEmpty(text))
+            info.add(new UserInfoDetailsItem(icon, text));
     }
 
     private void changeAccountPassword(Account account) {
@@ -491,4 +440,63 @@ public class UserInfoActivity extends FileActivity {
     public void onMessageEvent(TokenPushEvent event) {
         PushUtils.pushRegistrationToServer();
     }
+
+
+    class UserInfoDetailsItem {
+        @DrawableRes int icon;
+        String text;
+
+        UserInfoDetailsItem(@DrawableRes int icon, String text) {
+            this.icon = icon;
+            this.text = text;
+        }
+    }
+
+    class UserInfoAdapter extends RecyclerView.Adapter<UserInfoAdapter.ViewHolder> {
+
+        class ViewHolder extends RecyclerView.ViewHolder {
+
+            @BindView(R.id.icon) ImageView icon;
+            @BindView(R.id.text) TextView text;
+
+            public ViewHolder(View itemView) {
+                super(itemView);
+                ButterKnife.bind(this, itemView);
+            }
+        }
+
+        List<UserInfoDetailsItem> mDisplayList;
+        @ColorInt int mTintColor;
+
+        public UserInfoAdapter(List<UserInfoDetailsItem> displayList, @ColorInt int tintColor) {
+            mDisplayList = displayList == null ? new LinkedList<>() : displayList;
+            mTintColor = tintColor;
+        }
+
+        public void setData(List<UserInfoDetailsItem> displayList) {
+            mDisplayList = displayList == null ? new LinkedList<>() : displayList;
+            notifyDataSetChanged();
+        }
+
+        @Override
+        public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
+            LayoutInflater inflater = LayoutInflater.from(parent.getContext());
+            View view = inflater.inflate(R.layout.user_info_details_table_item, parent, false);
+            ViewHolder holder = new ViewHolder(view);
+            return holder;
+        }
+
+        @Override
+        public void onBindViewHolder(ViewHolder holder, int position) {
+            UserInfoDetailsItem item = mDisplayList.get(position);
+            holder.icon.setImageResource(item.icon);
+            holder.text.setText(item.text);
+            DrawableCompat.setTint(holder.icon.getDrawable(), mTintColor);
+        }
+
+        @Override
+        public int getItemCount() {
+            return mDisplayList.size();
+        }
+    }
 }

+ 31 - 0
src/main/res/layout/user_info_details_table_item.xml

@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/email_container"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content">
+
+    <ImageView
+        android:id="@+id/icon"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginBottom="@dimen/standard_margin"
+        android:layout_marginLeft="@dimen/standard_icon_list_horizontal_margin"
+        android:layout_marginRight="@dimen/standard_icon_list_horizontal_margin"
+        android:layout_marginTop="@dimen/standard_margin"/>
+
+    <TextView
+        android:id="@+id/text"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_centerInParent="true"
+        android:layout_marginRight="@dimen/standard_padding"
+        android:layout_marginEnd="@dimen/standard_padding"
+        android:layout_marginBottom="@dimen/standard_margin"
+        android:layout_marginTop="@dimen/standard_margin"
+        android:layout_toEndOf="@id/icon"
+        android:layout_toRightOf="@id/icon"
+        android:maxLines="3"
+        android:textAppearance="?android:attr/textAppearanceListItem"/>
+
+</RelativeLayout>

+ 7 - 194
src/main/res/layout/user_info_layout.xml

@@ -19,8 +19,8 @@
   License along with this program.  If not, see <http://www.gnu.org/licenses/>.
 -->
 <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
-                                                 xmlns:card_view="http://schemas.android.com/apk/res-auto"
                                                  xmlns:app="http://schemas.android.com/apk/res-auto"
+                                                 xmlns:card_view="http://schemas.android.com/apk/res-auto"
                                                  android:layout_width="match_parent"
                                                  android:layout_height="match_parent">
 
@@ -53,199 +53,13 @@
                 card_view:cardCornerRadius="3dp"
                 card_view:cardUseCompatPadding="true">
 
-                <LinearLayout
-                    android:layout_width="match_parent"
+                <android.support.v7.widget.RecyclerView
+                    android:id="@+id/user_info_list"
+                    android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
-                    android:orientation="vertical">
-
-                    <RelativeLayout
-                        android:id="@+id/phone_container"
-                        android:layout_width="match_parent"
-                        android:layout_height="wrap_content">
-
-                        <ImageView
-                            android:id="@+id/phone_icon"
-                            android:layout_width="wrap_content"
-                            android:layout_height="wrap_content"
-                            android:layout_marginBottom="@dimen/standard_margin"
-                            android:layout_marginLeft="@dimen/standard_icon_list_horizontal_margin"
-                            android:layout_marginRight="@dimen/standard_icon_list_horizontal_margin"
-                            android:layout_marginTop="@dimen/standard_margin"
-                            android:contentDescription="@string/user_info_phone"
-                            android:src="@drawable/ic_phone"/>
-
-                        <TextView
-                            android:id="@+id/phone_number"
-                            android:layout_width="match_parent"
-                            android:layout_height="wrap_content"
-                            android:layout_centerInParent="true"
-                            android:layout_marginBottom="@dimen/standard_margin"
-                            android:layout_marginEnd="@dimen/standard_padding"
-                            android:layout_marginRight="@dimen/standard_padding"
-                            android:layout_marginTop="@dimen/standard_margin"
-                            android:layout_toEndOf="@id/phone_icon"
-                            android:layout_toRightOf="@id/phone_icon"
-                            android:maxLines="3"
-                            android:text="@string/placeholder_filename"
-                            android:textAppearance="?android:attr/textAppearanceListItem"/>
-
-                    </RelativeLayout>
-
-                    <RelativeLayout
-                        android:id="@+id/email_container"
-                        android:layout_width="match_parent"
-                        android:layout_height="wrap_content">
-
-                        <View
-                            android:layout_width="match_parent"
-                            android:layout_height="1dp"
-                            android:background="@color/list_divider_background"/>
-
-                        <ImageView
-                            android:id="@+id/email_icon"
-                            android:layout_width="wrap_content"
-                            android:layout_height="wrap_content"
-                            android:layout_marginBottom="@dimen/standard_margin"
-                            android:layout_marginLeft="@dimen/standard_icon_list_horizontal_margin"
-                            android:layout_marginRight="@dimen/standard_icon_list_horizontal_margin"
-                            android:layout_marginTop="@dimen/standard_margin"
-                            android:contentDescription="@string/user_info_email"
-                            android:src="@drawable/ic_email"/>
-
-                        <TextView
-                            android:id="@+id/email_address"
-                            android:layout_width="match_parent"
-                            android:layout_height="wrap_content"
-                            android:layout_centerInParent="true"
-                            android:layout_marginBottom="@dimen/standard_margin"
-                            android:layout_marginEnd="@dimen/standard_padding"
-                            android:layout_marginRight="@dimen/standard_padding"
-                            android:layout_marginTop="@dimen/standard_margin"
-                            android:layout_toEndOf="@id/email_icon"
-                            android:layout_toRightOf="@id/email_icon"
-                            android:maxLines="3"
-                            android:text="@string/placeholder_filename"
-                            android:textAppearance="?android:attr/textAppearanceListItem"/>
-
-                    </RelativeLayout>
-
-                    <RelativeLayout
-                        android:id="@+id/address_container"
-                        android:layout_width="match_parent"
-                        android:layout_height="wrap_content">
-
-                        <View
-                            android:layout_width="match_parent"
-                            android:layout_height="1dp"
-                            android:background="@color/list_divider_background"/>
-
-                        <ImageView
-                            android:id="@+id/address_icon"
-                            android:layout_width="wrap_content"
-                            android:layout_height="wrap_content"
-                            android:layout_marginBottom="@dimen/standard_margin"
-                            android:layout_marginLeft="@dimen/standard_icon_list_horizontal_margin"
-                            android:layout_marginRight="@dimen/standard_icon_list_horizontal_margin"
-                            android:layout_marginTop="@dimen/standard_margin"
-                            android:contentDescription="@string/user_info_address"
-                            android:src="@drawable/ic_map_marker"/>
-
-                        <TextView
-                            android:id="@+id/address"
-                            android:layout_width="match_parent"
-                            android:layout_height="wrap_content"
-                            android:layout_centerInParent="true"
-                            android:layout_marginBottom="@dimen/standard_margin"
-                            android:layout_marginEnd="@dimen/standard_padding"
-                            android:layout_marginRight="@dimen/standard_padding"
-                            android:layout_marginTop="@dimen/standard_margin"
-                            android:layout_toEndOf="@+id/address_icon"
-                            android:layout_toRightOf="@+id/address_icon"
-                            android:maxLines="3"
-                            android:text="@string/placeholder_filename"
-                            android:textAppearance="?android:attr/textAppearanceListItem"/>
-
-                    </RelativeLayout>
-
-                    <RelativeLayout
-                        android:id="@+id/website_container"
-                        android:layout_width="match_parent"
-                        android:layout_height="wrap_content">
-
-                        <View
-                            android:layout_width="match_parent"
-                            android:layout_height="1dp"
-                            android:background="@color/list_divider_background"/>
-
-                        <ImageView
-                            android:id="@+id/website_icon"
-                            android:layout_width="wrap_content"
-                            android:layout_height="wrap_content"
-                            android:layout_marginBottom="@dimen/standard_margin"
-                            android:layout_marginLeft="@dimen/standard_icon_list_horizontal_margin"
-                            android:layout_marginRight="@dimen/standard_icon_list_horizontal_margin"
-                            android:layout_marginTop="@dimen/standard_margin"
-                            android:contentDescription="@string/user_info_website"
-                            android:src="@drawable/ic_web"/>
-
-                        <TextView
-                            android:id="@+id/website_address"
-                            android:layout_width="match_parent"
-                            android:layout_height="wrap_content"
-                            android:layout_centerInParent="true"
-                            android:layout_marginBottom="@dimen/standard_margin"
-                            android:layout_marginEnd="@dimen/standard_padding"
-                            android:layout_marginRight="@dimen/standard_padding"
-                            android:layout_marginTop="@dimen/standard_margin"
-                            android:layout_toEndOf="@id/website_icon"
-                            android:layout_toRightOf="@id/website_icon"
-                            android:maxLines="3"
-                            android:text="@string/placeholder_filename"
-                            android:textAppearance="?android:attr/textAppearanceListItem"
-                            android:textColor="?android:attr/textColorSecondary"/>
-
-                    </RelativeLayout>
-
-                    <RelativeLayout
-                        android:id="@+id/twitter_container"
-                        android:layout_width="match_parent"
-                        android:layout_height="wrap_content">
-
-                        <View
-                            android:layout_width="match_parent"
-                            android:layout_height="1dp"
-                            android:background="@color/list_divider_background"/>
-
-                        <ImageView
-                            android:id="@+id/twitter_icon"
-                            android:layout_width="wrap_content"
-                            android:layout_height="wrap_content"
-                            android:layout_marginBottom="@dimen/standard_margin"
-                            android:layout_marginLeft="@dimen/standard_icon_list_horizontal_margin"
-                            android:layout_marginRight="@dimen/standard_icon_list_horizontal_margin"
-                            android:layout_marginTop="@dimen/standard_margin"
-                            android:contentDescription="@string/user_info_twitter"
-                            android:src="@drawable/ic_twitter"/>
-
-                        <TextView
-                            android:id="@+id/twitter_handle"
-                            android:layout_width="match_parent"
-                            android:layout_height="wrap_content"
-                            android:layout_centerInParent="true"
-                            android:layout_marginBottom="@dimen/standard_margin"
-                            android:layout_marginEnd="@dimen/standard_padding"
-                            android:layout_marginRight="@dimen/standard_padding"
-                            android:layout_marginTop="@dimen/standard_margin"
-                            android:layout_toEndOf="@id/twitter_icon"
-                            android:layout_toRightOf="@id/twitter_icon"
-                            android:maxLines="3"
-                            android:text="@string/placeholder_filename"
-                            android:textAppearance="?android:attr/textAppearanceListItem"
-                            android:textColor="?android:attr/textColorSecondary"/>
-
-                    </RelativeLayout>
-
-                </LinearLayout>
+                    android:orientation="vertical"
+                    card_view:layoutManager="android.support.v7.widget.LinearLayoutManager">
+                </android.support.v7.widget.RecyclerView>
 
             </android.support.v7.widget.CardView>
 
@@ -253,5 +67,4 @@
 
     </android.support.v4.widget.NestedScrollView>
 
-
 </android.support.design.widget.CoordinatorLayout>