Bug 1246243 - Use special icon for reading list folder r?liuche draft
authorAndrzej Hunt <ahunt@mozilla.com>
Tue, 12 Apr 2016 14:47:24 -0700
changeset 350099 2013196a2c3386ab6fb1b1c50c68c9e8e1adda01
parent 350098 52fd03359506f1b31eb1ef8ac97063bb52adc88c
child 518251 2d5330e73e9ed42174f8044c749dd0d73f9af413
push id15249
push userahunt@mozilla.com
push dateTue, 12 Apr 2016 21:48:35 +0000
reviewersliuche
bugs1246243
milestone48.0a1
Bug 1246243 - Use special icon for reading list folder r?liuche This approach is extensible and would allow easy addition of special icons for e.g. the screenshots folder. MozReview-Commit-ID: 44yWq85x2HG
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-hdpi/reading_list_folder.png
mobile/android/base/resources/drawable-xhdpi/reading_list_folder.png
mobile/android/base/resources/drawable-xxhdpi/reading_list_folder.png
mobile/android/base/resources/drawable/bookmark_folder.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
@@ -3,53 +3,73 @@
  * 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/. */
 
 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.widget.TextView;
 
 public class BookmarkFolderView extends TextView {
-    private static final int[] STATE_OPEN = { R.attr.state_open };
+    public enum FolderState {
+        /**
+         * A standard folder, i.e. a folder in a list of bookmarks and folders.
+         */
+        FOLDER(0),
+
+        /**
+         * A currently opened folder, i.e. this indicates that you are able to return to the previous
+         * folder.
+         */
+        OPENED_FOLDER(R.attr.state_open),
 
-    private boolean mIsOpen;
+        /**
+         * The reading list smartfolder: this displays a reading list icon instead of the
+         * normal folder icon.
+         */
+        SMARTFOLDER_READINGLIST(R.attr.state_smartfolder_readinglist);
+
+        public final int state;
+
+        FolderState(final int state) { this.state = state; }
+    }
+
+    private FolderState mState;
+
+    private static final int[] STATE_OPEN = { R.attr.state_open };
 
     public BookmarkFolderView(Context context) {
         super(context);
+        mState = FolderState.FOLDER;
     }
 
     public BookmarkFolderView(Context context, AttributeSet attrs) {
         super(context, attrs);
+        mState = FolderState.FOLDER;
     }
 
     public BookmarkFolderView(Context context, AttributeSet attrs, int defStyle) {
         super(context, attrs, defStyle);
+        mState = FolderState.FOLDER;
     }
 
     @Override
     public int[] onCreateDrawableState(int extraSpace) {
         final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
 
-        if (mIsOpen) {
-            mergeDrawableStates(drawableState, STATE_OPEN);
+        if (mState != null && mState != FolderState.FOLDER) {
+            mergeDrawableStates(drawableState, new int[] {  mState.state });
         }
 
         return drawableState;
     }
 
-    public void open() {
-        if (!mIsOpen) {
-            mIsOpen = true;
-            refreshDrawableState();
-        }
-    }
-
-    public void close() {
-        if (mIsOpen) {
-            mIsOpen = false;
+    public void setState(@NonNull FolderState state) {
+        if (state != mState) {
+            mState = state;
             refreshDrawableState();
         }
     }
 }
--- a/mobile/android/base/java/org/mozilla/gecko/home/BookmarksListAdapter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/BookmarksListAdapter.java
@@ -6,16 +6,17 @@
 package org.mozilla.gecko.home;
 
 import java.util.Collections;
 import java.util.LinkedList;
 import java.util.List;
 
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.db.BrowserContract.Bookmarks;
+import org.mozilla.gecko.home.BookmarkFolderView.FolderState;
 
 import android.content.Context;
 import android.content.res.Resources;
 import android.database.Cursor;
 import android.os.Parcel;
 import android.os.Parcelable;
 import android.view.View;
 
@@ -324,16 +325,22 @@ class BookmarksListAdapter extends Multi
         } 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.open();
+                row.setState(FolderState.OPENED_FOLDER);
             } else {
                 row.setText(getFolderTitle(context, cursor));
-                row.close();
+
+                int id = cursor.getInt(cursor.getColumnIndexOrThrow(Bookmarks._ID));
+                if (id == Bookmarks.FAKE_READINGLIST_SMARTFOLDER_ID) {
+                    row.setState(FolderState.SMARTFOLDER_READINGLIST);
+                } else {
+                    row.setState(FolderState.FOLDER);
+                }
             }
         }
     }
 }
new file mode 100644
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..052994110de4bc328d462825e068bdea5a120e7e
GIT binary patch
literal 424
zc%17D@N?(olHy`uVBq!ia0vp^DnKmF!3-poKi$0qq!^2X+?^QKos)S9<a7o2gt!9f
z|Np^g6~q7i4F6|>8MDERsSN*TF#MkeMsPN=2r>iCg|M*-B1@rZoXYTcL-+!qYjjJ3
z{DK)6nV4Bv*~B$8wTvwsJ-q$n6O+^G8rmjLnZA78;iJbcUcUDH^_y?sfBpXR_g}#_
zQz@Xv$(}BbAr*{o&$%`o2@qfkc$8UQ-e2>se$U6w-EV%aUCr?2T+_benR<yuJGiTk
zZ0+Y(zNYOKqbQ-6<Hj+e#odU_y2#u>rNX1iecn@{`<wbpbl-OT7YO~PvFhpK?;p(C
zy*Dk&nzb&Q%QJ#!*W3031@*}jT9uW>xZPwfSVo;mkv)4tsQB@OciXg;FTeOHrF^}l
bZH51VLMMr(VIKd0&SUU&^>bP0l+XkKd7Zr?
new file mode 100644
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..c7ad1cade1daceaae3716637e0fa2b35cf1a9b56
GIT binary patch
literal 542
zc%17D@N?(olHy`uVBq!ia0vp^20*OB!3-pS%=WYZQjEnx?oJHr&dIz4at;Legt!9f
z|Np^g6~q7i4F6|>8QU2C&j&Mr+(iuk=Q8|X!tj4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Z9r_r@^V?=!ax3Tid@2oDSq`yM*s>dXrq-x}*Jx+@xxc
zbpqer{}(ClbI=g-UJ^7jW?_KFRIgSiH7nhc+pFR^Bw20<NI13r>w0&1f?ReK<AGaC
zj<cN*^bS(;6!I1mOX_m#JjtQ*g1v*eLDhW8d!sWmKTe2vo_E>t`s(QqXLrUV-<nam
z<cHmR*<VZ6A1|-Y6WAK}fq9Q_dek3*GWHvGOpzjAPB-YUkpjjBgQu&X%Q~loCIBFk
BPn`e&
--- a/mobile/android/base/resources/drawable/bookmark_folder.xml
+++ b/mobile/android/base/resources/drawable/bookmark_folder.xml
@@ -5,12 +5,16 @@
 
 <selector xmlns:android="http://schemas.android.com/apk/res/android"
           xmlns:gecko="http://schemas.android.com/apk/res-auto">
 
     <!-- state open -->
     <item gecko:state_open="true"
           android:drawable="@drawable/bookmark_folder_arrow_up"/>
 
+    <!-- reading list folder -->
+    <item gecko:state_smartfolder_readinglist="true"
+          android:drawable="@drawable/reading_list_folder"/>
+
     <!-- state close -->
     <item android:drawable="@drawable/folder_closed"/>
 
 </selector>
--- a/mobile/android/base/resources/values/attrs.xml
+++ b/mobile/android/base/resources/values/attrs.xml
@@ -133,16 +133,17 @@
     <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="state_open" format="boolean"/>
+        <attr name="state_smartfolder_readinglist" 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" />