Bug 882081 - Restore bookmark indicator in TwoLinePageRow (r=sriram)
authorLucas Rocha <lucasr@mozilla.com>
Fri, 14 Jun 2013 17:26:36 +0100
changeset 143405 0addf6e4c687c9146b5a43d68a920bca6d213a27
parent 143404 cdee85022d13443a41d8322abb0444e0c0b4af7c
child 143406 441bc08c4d28b09e83417ddda14328f3cda379de
push id32723
push useremorley@mozilla.com
push dateWed, 21 Aug 2013 12:10:14 +0000
treeherdermozilla-inbound@ab6bc4d9e4c0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssriram
bugs882081
milestone24.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 882081 - Restore bookmark indicator in TwoLinePageRow (r=sriram)
mobile/android/base/BrowserSearch.java
mobile/android/base/home/TwoLinePageRow.java
mobile/android/base/resources/layout/two_line_page_row.xml
--- a/mobile/android/base/BrowserSearch.java
+++ b/mobile/android/base/BrowserSearch.java
@@ -574,18 +574,16 @@ public class BrowserSearch extends Fragm
 
                 final Cursor c = getCursor();
                 if (!c.moveToPosition(position)) {
                     throw new IllegalStateException("Couldn't move cursor to position " + position);
                 }
 
                 row.updateFromCursor(c);
 
-                // FIXME: show bookmark icon
-
                 return row;
             }
         }
 
         private int getSuggestEngineCount() {
             return (TextUtils.isEmpty(mSearchTerm) || mSuggestClient == null || !mSuggestionsEnabled) ? 0 : 1;
         }
 
--- a/mobile/android/base/home/TwoLinePageRow.java
+++ b/mobile/android/base/home/TwoLinePageRow.java
@@ -3,45 +3,53 @@
  * 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.Favicons;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.Tabs;
+import org.mozilla.gecko.db.BrowserContract.Combined;
 import org.mozilla.gecko.db.BrowserDB.URLColumns;
 import org.mozilla.gecko.gfx.BitmapUtils;
 import org.mozilla.gecko.widget.FaviconView;
 
 import android.content.Context;
 import android.database.Cursor;
 import android.graphics.Bitmap;
 import android.text.TextUtils;
 import android.util.AttributeSet;
 import android.view.Gravity;
 import android.view.LayoutInflater;
 import android.widget.LinearLayout;
 import android.widget.TextView;
 
 public class TwoLinePageRow extends LinearLayout {
+    private static final int NO_ICON = 0;
 
     private final TextView mTitle;
     private final TextView mUrl;
     private final FaviconView mFavicon;
 
+    private int mUrlIconId;
+    private int mBookmarkIconId;
+
     public TwoLinePageRow(Context context) {
         this(context, null);
     }
 
     public TwoLinePageRow(Context context, AttributeSet attrs) {
         super(context, attrs);
 
         setGravity(Gravity.CENTER_VERTICAL);
 
+        mUrlIconId = NO_ICON;
+        mBookmarkIconId = NO_ICON;
+
         LayoutInflater.from(context).inflate(R.layout.two_line_page_row, this);
         mTitle = (TextView) findViewById(R.id.title);
         mUrl = (TextView) findViewById(R.id.url);
         mFavicon = (FaviconView) findViewById(R.id.favicon);
     }
 
     private void setTitle(String title) {
         mTitle.setText(title);
@@ -50,24 +58,38 @@ public class TwoLinePageRow extends Line
     private void setUrl(String url) {
         mUrl.setText(url);
     }
 
     private void setUrl(int stringId) {
         mUrl.setText(stringId);
     }
 
-    private void setUrlIcon(int resourceId) {
-        mUrl.setCompoundDrawablesWithIntrinsicBounds(resourceId, 0, 0, 0);
+    private void setUrlIcon(int urlIconId) {
+        if (mUrlIconId == urlIconId) {
+            return;
+        }
+
+        mUrlIconId = urlIconId;
+        mUrl.setCompoundDrawablesWithIntrinsicBounds(mUrlIconId, 0, mBookmarkIconId, 0);
     }
 
     private void setFaviconWithUrl(Bitmap favicon, String url) {
         mFavicon.updateImage(favicon, url);
     }
 
+    private void setBookmarkIcon(int bookmarkIconId) {
+        if (mBookmarkIconId == bookmarkIconId) {
+            return;
+        }
+
+        mBookmarkIconId = bookmarkIconId;
+        mUrl.setCompoundDrawablesWithIntrinsicBounds(mUrlIconId, 0, mBookmarkIconId, 0);
+    }
+
     public void updateFromCursor(Cursor cursor) {
         if (cursor == null) {
             return;
         }
 
         int titleIndex = cursor.getColumnIndexOrThrow(URLColumns.TITLE);
         final String title = cursor.getString(titleIndex);
 
@@ -79,17 +101,17 @@ public class TwoLinePageRow extends Line
         setTitle(TextUtils.isEmpty(title) ? url : title);
 
         // Update the url with "Switch to tab" if needed.
         if (Tabs.getInstance().hasUrl(url)) {
             setUrl(R.string.switch_to_tab);
             setUrlIcon(R.drawable.ic_url_bar_tab);
         } else {
             setUrl(url);
-            setUrlIcon(0);
+            setUrlIcon(NO_ICON);
         }
 
         int faviconIndex = cursor.getColumnIndex(URLColumns.FAVICON);
         if (faviconIndex != -1) {
             byte[] b = cursor.getBlob(faviconIndex);
 
             Bitmap favicon = null;
             if (b != null) {
@@ -99,10 +121,35 @@ public class TwoLinePageRow extends Line
                 }
             }
 
             setFaviconWithUrl(favicon, url);
         } else {
             // If favicons is not on the cursor, try to fetch it from the memory cache
             setFaviconWithUrl(Favicons.getInstance().getFaviconFromMemCache(url), url);
         }
+
+        final int bookmarkIdIndex = cursor.getColumnIndex(Combined.BOOKMARK_ID);
+        if (bookmarkIdIndex != -1) {
+            final long bookmarkId = cursor.getLong(bookmarkIdIndex);
+            final int displayIndex = cursor.getColumnIndex(Combined.DISPLAY);
+
+            final int display;
+            if (displayIndex != -1) {
+                display = cursor.getInt(displayIndex);
+            } else {
+                display = Combined.DISPLAY_NORMAL;
+            }
+
+            // The bookmark id will be 0 (null in database) when the url
+            // is not a bookmark.
+            if (bookmarkId == 0) {
+                setBookmarkIcon(NO_ICON);
+            } else if (display == Combined.DISPLAY_READER) {
+                setBookmarkIcon(R.drawable.ic_url_bar_reader);
+            } else {
+                setBookmarkIcon(R.drawable.ic_url_bar_star);
+            }
+        } else {
+            setBookmarkIcon(NO_ICON);
+        }
     }
 }
--- a/mobile/android/base/resources/layout/two_line_page_row.xml
+++ b/mobile/android/base/resources/layout/two_line_page_row.xml
@@ -7,27 +7,29 @@
        xmlns:gecko="http://schemas.android.com/apk/res-auto">
 
     <org.mozilla.gecko.widget.FaviconView android:id="@+id/favicon"
                                           android:layout_width="@dimen/favicon_bg"
                                           android:layout_height="@dimen/favicon_bg"
                                           android:layout_marginLeft="10dip"
                                           android:layout_marginRight="10dip"/>
 
-    <LinearLayout android:layout_width="wrap_content"
+    <LinearLayout android:layout_width="fill_parent"
                   android:layout_height="wrap_content"
+                  android:layout_marginRight="10dip"
                   android:orientation="vertical">
 
         <org.mozilla.gecko.home.FadedTextView
                 android:id="@+id/title"
                 style="@style/Widget.TwoLinePageRow.Title"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 gecko:fadeWidth="30dp"/>
 
         <TextView android:id="@+id/url"
                   style="@style/Widget.TwoLinePageRow.Url"
-                  android:layout_width="wrap_content"
-                  android:layout_height="wrap_content"/>
+                  android:layout_width="fill_parent"
+                  android:layout_height="wrap_content"
+                  android:drawablePadding="5dp"/>
 
     </LinearLayout>
 
 </merge>