Bug 1269001 - Pre: use two line layout for BookmarkFolderView r?mcomella draft
authorAndrzej Hunt <andrzej@ahunt.org>
Thu, 05 May 2016 11:06:46 -0700
changeset 365464 bd2fc0a01cf59ca42b103752dbf44e097c90f039
parent 365338 2f9351bae69d056e4615d21dda6bf42fec5d16b7
child 365465 e0dbe5cef22eb1cbb1702c0d8aba0981985f2f87
push id17748
push userbmo:ahunt@mozilla.com
push dateTue, 10 May 2016 20:42:10 +0000
reviewersmcomella
bugs1269001
milestone49.0a1
Bug 1269001 - Pre: use two line layout for BookmarkFolderView r?mcomella We want to be able to show the numebr of items for certain folders (e.g. the reading list smartfolder). The previous state list drawable was also unnecessarily confusing, let's just reference the desired images directly. We can do this largely by copying the existing TwoLinePageRow, modulo the unneeded status / switch-to-tab icons. MozReview-Commit-ID: 3w0Hcj0kIfG
mobile/android/base/java/org/mozilla/gecko/home/BookmarkFolderView.java
mobile/android/base/java/org/mozilla/gecko/home/BookmarksListAdapter.java
mobile/android/base/resources/drawable/bookmark_folder.xml
mobile/android/base/resources/layout/bookmark_folder_row.xml
mobile/android/base/resources/layout/two_line_folder_row.xml
mobile/android/base/resources/values/attrs.xml
--- a/mobile/android/base/java/org/mozilla/gecko/home/BookmarkFolderView.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/BookmarkFolderView.java
@@ -5,69 +5,74 @@
 
 package org.mozilla.gecko.home;
 
 import org.mozilla.gecko.R;
 
 import android.content.Context;
 import android.support.annotation.NonNull;
 import android.util.AttributeSet;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
 import android.widget.TextView;
 
-public class BookmarkFolderView extends TextView {
+public class BookmarkFolderView extends LinearLayout {
     public enum FolderState {
         /**
          * A standard folder, i.e. a folder in a list of bookmarks and folders.
          */
-        FOLDER(0),
+        FOLDER(R.drawable.folder_closed),
 
         /**
          * The parent folder: this indicates that you are able to return to the previous
          * folder ("Back to {name}").
          */
-        PARENT(R.attr.parent),
+        PARENT(R.drawable.bookmark_folder_arrow_up),
 
         /**
          * The reading list smartfolder: this displays a reading list icon instead of the
          * normal folder icon.
          */
-        READING_LIST(R.attr.reading_list);
+        READING_LIST(R.drawable.reading_list_folder);
 
-        public final int state;
+        public final int image;
 
-        FolderState(final int state) { this.state = state; }
+        FolderState(final int image) { this.image = image; }
     }
 
-    private FolderState mState;
+    private final TextView mTitle;
+    private final TextView mSubtitle;
+
+    private final ImageView mIcon;
 
     public BookmarkFolderView(Context context) {
-        super(context);
-        mState = FolderState.FOLDER;
+        this(context, null);
     }
 
     public BookmarkFolderView(Context context, AttributeSet attrs) {
         super(context, attrs);
-        mState = FolderState.FOLDER;
-    }
+
+        LayoutInflater.from(context).inflate(R.layout.two_line_folder_row, this);
 
-    public BookmarkFolderView(Context context, AttributeSet attrs, int defStyle) {
-        super(context, attrs, defStyle);
-        mState = FolderState.FOLDER;
+        mTitle = (TextView) findViewById(R.id.title);
+        mSubtitle = (TextView) findViewById(R.id.subtitle);
+        mIcon =  (ImageView) findViewById(R.id.icon);
     }
 
-    @Override
-    public int[] onCreateDrawableState(int extraSpace) {
-        final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
+    public void update(String title, int folderID) {
+        setTitle(title);
+    }
 
-        if (mState != null && mState != FolderState.FOLDER) {
-            mergeDrawableStates(drawableState, new int[] {  mState.state });
+    private void setTitle(String title) {
+        mTitle.setText(title);
+    }
+
         }
 
-        return drawableState;
+        mSubtitle.setVisibility(View.GONE);
     }
 
     public void setState(@NonNull FolderState state) {
-        if (state != mState) {
-            mState = state;
-            refreshDrawableState();
-        }
+        mIcon.setImageResource(state.image);
     }
 }
--- a/mobile/android/base/java/org/mozilla/gecko/home/BookmarksListAdapter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/BookmarksListAdapter.java
@@ -329,22 +329,23 @@ class BookmarksListAdapter extends Multi
             ((BookmarkScreenshotRow) view).updateFromCursor(cursor);
         } else if (viewType == VIEW_TYPE_BOOKMARK_ITEM) {
             final TwoLinePageRow row = (TwoLinePageRow) view;
             row.updateFromCursor(cursor);
         } else {
             final BookmarkFolderView row = (BookmarkFolderView) view;
             if (cursor == null) {
                 final Resources res = context.getResources();
-                row.setText(res.getString(R.string.home_move_back_to_filter, mParentStack.get(1).title));
+                row.update(res.getString(R.string.home_move_back_to_filter, mParentStack.get(1).title), -1);
                 row.setState(FolderState.PARENT);
             } else {
-                row.setText(getFolderTitle(context, cursor));
+                int id = cursor.getInt(cursor.getColumnIndexOrThrow(Bookmarks._ID));
 
-                int id = cursor.getInt(cursor.getColumnIndexOrThrow(Bookmarks._ID));
+                row.update(getFolderTitle(context, cursor), id);
+
                 if (id == Bookmarks.FAKE_READINGLIST_SMARTFOLDER_ID) {
                     row.setState(FolderState.READING_LIST);
                 } else {
                     row.setState(FolderState.FOLDER);
                 }
             }
         }
     }
deleted file mode 100644
--- a/mobile/android/base/resources/drawable/bookmark_folder.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- This Source Code Form is subject to the terms of the Mozilla Public
-   - License, v. 2.0. If a copy of the MPL was not distributed with this
-   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
-
-<selector xmlns:android="http://schemas.android.com/apk/res/android"
-          xmlns:gecko="http://schemas.android.com/apk/res-auto">
-
-    <!-- state open -->
-    <item gecko:parent="true"
-          android:drawable="@drawable/bookmark_folder_arrow_up"/>
-
-    <!-- reading list folder -->
-    <item gecko:reading_list="true"
-          android:drawable="@drawable/reading_list_folder"/>
-
-    <!-- state close -->
-    <item android:drawable="@drawable/folder_closed"/>
-
-</selector>
--- a/mobile/android/base/resources/layout/bookmark_folder_row.xml
+++ b/mobile/android/base/resources/layout/bookmark_folder_row.xml
@@ -1,12 +1,13 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <org.mozilla.gecko.home.BookmarkFolderView xmlns:android="http://schemas.android.com/apk/res/android"
                                            style="@style/Widget.FolderView"
                                            android:layout_width="match_parent"
-                                           android:paddingLeft="20dp"
-                                           android:drawablePadding="20dp"
-                                           android:drawableLeft="@drawable/bookmark_folder"
+                                           android:paddingLeft="0dp"
+                                           android:paddingTop="0dp"
+                                           android:paddingBottom="0dp"
+                                           android:paddingRight="16dp"
                                            android:gravity="center_vertical"/>
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/resources/layout/two_line_folder_row.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+   - License, v. 2.0. If a copy of the MPL was not distributed with this
+   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<merge xmlns:android="http://schemas.android.com/apk/res/android"
+       xmlns:tools="http://schemas.android.com/tools"
+       xmlns:gecko="http://schemas.android.com/apk/res-auto"
+       tools:context=".BrowserApp">
+
+    <ImageView android:id="@+id/icon"
+               android:src="@drawable/folder_closed"
+               android:layout_width="24dp"
+               android:layout_height="24dp"
+               android:scaleType="fitCenter"
+               android:layout_margin="20dp"/>
+
+    <LinearLayout android:layout_width="0dp"
+                  android:layout_height="wrap_content"
+                  android:layout_weight="1"
+                  android:layout_gravity="center_vertical"
+                  android:paddingRight="10dp"
+                  android:orientation="vertical">
+
+        <org.mozilla.gecko.widget.FadedSingleColorTextView
+                android:id="@+id/title"
+                style="@style/Widget.TwoLinePageRow.Title"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                gecko:fadeWidth="90dp"
+                tools:text="This is a long test title"/>
+
+        <org.mozilla.gecko.widget.FadedSingleColorTextView android:id="@+id/subtitle"
+                  style="@style/Widget.TwoLinePageRow.Url"
+                  android:layout_width="match_parent"
+                  android:layout_height="wrap_content"
+                  android:visibility="gone"
+                  gecko:fadeWidth="90dp"
+                  tools:text="1 items"/>
+
+    </LinearLayout>
+
+</merge>
--- a/mobile/android/base/resources/values/attrs.xml
+++ b/mobile/android/base/resources/values/attrs.xml
@@ -131,21 +131,16 @@
     </declare-styleable>
 
     <declare-styleable name="FadedMultiColorTextView">
         <!-- The background color we should be fading over. Useful because the
              background is full alpha and we need to copy the background underneath. -->
         <attr name="fadeBackgroundColor" format="dimension"/>
     </declare-styleable>
 
-    <declare-styleable name="BookmarkFolderView">
-        <attr name="parent" format="boolean"/>
-        <attr name="reading_list" format="boolean"/>
-    </declare-styleable>
-
     <declare-styleable name="IconTabWidget">
         <attr name="android:layout"/>
 
         <!-- Sets the tab's content type. Defaults to icon. -->
         <attr name="display">
             <enum name="icon" value="0x00" />
             <enum name="text" value="0x01" />
         </attr>