Bug 877870 - Add finer-grained APIs to update TwoLinePageRow (r=sriram)
authorLucas Rocha <lucasr@mozilla.com>
Tue, 11 Jun 2013 17:57:44 +0100
changeset 143313 06bd6a21602252a120e4c9504513d8df296d4baf
parent 143312 8b24cd7f46aeede79c53ef0b7853e4703636f945
child 143314 33236a7d3ef52eef0ff8e886fb85f9cb12bc9543
push id25130
push userlrocha@mozilla.com
push dateWed, 21 Aug 2013 09:41:27 +0000
treeherdermozilla-central@b2486721572e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssriram
bugs877870
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 877870 - Add finer-grained APIs to update TwoLinePageRow (r=sriram)
mobile/android/base/home/TwoLinePageRow.java
--- a/mobile/android/base/home/TwoLinePageRow.java
+++ b/mobile/android/base/home/TwoLinePageRow.java
@@ -39,54 +39,70 @@ public class TwoLinePageRow extends Line
         setGravity(Gravity.CENTER_VERTICAL);
 
         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);
+    }
+
+    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 setFaviconWithUrl(Bitmap favicon, String url) {
+        mFavicon.updateImage(favicon, url);
+    }
+
     public void updateFromCursor(Cursor cursor) {
         if (cursor == null) {
             return;
         }
 
         int titleIndex = cursor.getColumnIndexOrThrow(URLColumns.TITLE);
         final String title = cursor.getString(titleIndex);
 
         int urlIndex = cursor.getColumnIndexOrThrow(URLColumns.URL);
         final String url = cursor.getString(urlIndex);
 
         // Use the URL instead of an empty title for consistency with the normal URL
         // bar view - this is the equivalent of getDisplayTitle() in Tab.java
-        if (TextUtils.isEmpty(title)) {
-            mTitle.setText(url);
-        } else {
-            mTitle.setText(title);
-        }
+        setTitle(TextUtils.isEmpty(title) ? url : title);
 
         // Update the url with "Switch to tab" if needed.
         // FIXME: Bug 877469: Add back switch to tab functionality.
         Integer tabId = null;
         if (tabId != null) {
-            mUrl.setText(R.string.switch_to_tab);
-            mUrl.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_url_bar_tab, 0, 0, 0);
+            setUrl(R.string.switch_to_tab);
+            setUrlIcon(R.drawable.ic_url_bar_tab);
         } else {
-            mUrl.setText(url);
-            mUrl.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
+            setUrl(url);
+            setUrlIcon(0);
         }
 
         int faviconIndex = cursor.getColumnIndex(URLColumns.FAVICON);
         if (faviconIndex != -1) {
             byte[] b = cursor.getBlob(faviconIndex);
 
             Bitmap favicon = null;
             if (b != null) {
                 Bitmap bitmap = BitmapUtils.decodeByteArray(b);
                 if (bitmap != null) {
                     favicon = Favicons.getInstance().scaleImage(bitmap);
                 }
             }
 
-            mFavicon.updateImage(favicon, url);
+            setFaviconWithUrl(favicon, url);
         }
     }
 }