Bug 737867 - Apply ViewHolder pattern on AwesomeBar's History tab (r=mfinkle)
authorLucas Rocha <lucasr@mozilla.com>
Tue, 27 Mar 2012 18:05:41 +0100
changeset 93740 1b3fc8a816342c7e3fa4e4704aadc6a1d4324675
parent 93739 9b69a0003fafbc38e8901b3bc55d9797c7d978aa
child 93741 4cf5f398d6bf0afec3e36616110122242b6e5140
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs737867
milestone14.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 737867 - Apply ViewHolder pattern on AwesomeBar's History tab (r=mfinkle)
mobile/android/base/AwesomeBarTabs.java
--- a/mobile/android/base/AwesomeBarTabs.java
+++ b/mobile/android/base/AwesomeBarTabs.java
@@ -119,47 +119,69 @@ public class AwesomeBarTabs extends TabH
 
     private class ViewHolder {
         public TextView titleView;
         public TextView urlView;
         public ImageView faviconView;
     }
 
     private class HistoryListAdapter extends SimpleExpandableListAdapter {
+        LayoutInflater mInflater;
+
         public HistoryListAdapter(Context context, List<? extends Map<String, ?>> groupData,
                 int groupLayout, String[] groupFrom, int[] groupTo,
-                List<? extends List<? extends Map<String, ?>>> childData,
-                int childLayout, String[] childFrom, int[] childTo) {
+                List<? extends List<? extends Map<String, ?>>> childData) {
 
             super(context, groupData, groupLayout, groupFrom, groupTo,
-                  childData, childLayout, childFrom, childTo);
+                  childData, -1, new String[] {}, new int[] {});
+
+            mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
         }
 
         @Override
         public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
                 View convertView, ViewGroup parent) {
+            ViewHolder viewHolder = null;
 
-            View childView =
-                    super.getChildView(groupPosition, childPosition, isLastChild, convertView, parent); 
+            if (convertView == null) {
+                convertView = mInflater.inflate(R.layout.awesomebar_row, null);
+
+                viewHolder = new ViewHolder();
+                viewHolder.titleView = (TextView) convertView.findViewById(R.id.title);
+                viewHolder.urlView = (TextView) convertView.findViewById(R.id.url);
+                viewHolder.faviconView = (ImageView) convertView.findViewById(R.id.favicon);
+
+                convertView.setTag(viewHolder);
+            } else {
+                viewHolder = (ViewHolder) convertView.getTag();
+            }
 
             @SuppressWarnings("unchecked")
             Map<String,Object> historyItem =
                     (Map<String,Object>) mHistoryAdapter.getChild(groupPosition, childPosition);
 
+            String title = (String) historyItem.get(URLColumns.TITLE);
+            String url = (String) historyItem.get(URLColumns.URL);
+
+            if (TextUtils.isEmpty(title))
+                title = url;
+
+            viewHolder.titleView.setText(title);
+            viewHolder.urlView.setText(url);
+
             byte[] b = (byte[]) historyItem.get(URLColumns.FAVICON);
-            ImageView favicon = (ImageView) childView.findViewById(R.id.favicon);
 
             if (b == null) {
-                favicon.setImageDrawable(null);
+                viewHolder.faviconView.setImageDrawable(null);
             } else {
                 Bitmap bitmap = BitmapFactory.decodeByteArray(b, 0, b.length);
-                favicon.setImageBitmap(bitmap);
+                viewHolder.faviconView.setImageBitmap(bitmap);
             }
 
-            return childView;
+            return convertView;
         }
     }
 
     private class BookmarksListAdapter extends SimpleCursorAdapter {
         private static final int VIEW_TYPE_ITEM = 0;
         private static final int VIEW_TYPE_FOLDER = 1;
         private static final int VIEW_TYPE_COUNT = 2;
 
@@ -527,20 +549,17 @@ public class AwesomeBarTabs extends TabH
                 return;
 
             mHistoryAdapter = new HistoryListAdapter(
                 mContext,
                 result.first,
                 R.layout.awesomebar_header_row,
                 new String[] { URLColumns.TITLE },
                 new int[] { R.id.title },
-                result.second,
-                R.layout.awesomebar_row,
-                new String[] { URLColumns.TITLE, URLColumns.URL },
-                new int[] { R.id.title, R.id.url }
+                result.second
             );
 
             final ExpandableListView historyList =
                     (ExpandableListView) findViewById(R.id.history_list);
 
             historyList.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
                 public boolean onChildClick(ExpandableListView parent, View view,
                         int groupPosition, int childPosition, long id) {