Bug 715274: Fix lists in AwesomeScreen. [r=mfinkle, r=margaret]
authorSriram Ramasubramanian <sriram@mozilla.com>
Mon, 26 Mar 2012 14:39:24 -0700
changeset 92035 c730b2ecebecc36d3917e14c1e128574299a2208
parent 92034 7573b4f06d486c02e25df55db48b6b8744ca81b3
child 92036 585261ed3fc3f011d8dc8ceadb42062f7112f64b
push idunknown
push userunknown
push dateunknown
reviewersmfinkle, margaret
bugs715274
milestone13.0a2
Bug 715274: Fix lists in AwesomeScreen. [r=mfinkle, r=margaret]
mobile/android/base/AwesomeBarTabs.java
mobile/android/base/Makefile.in
mobile/android/base/resources/layout/awesomebar_folder_header_row.xml
mobile/android/base/resources/layout/awesomebar_header_row.xml
mobile/android/base/resources/layout/awesomebar_tabs.xml
mobile/android/base/resources/values-v11/styles.xml
mobile/android/base/resources/values/styles.xml
--- a/mobile/android/base/AwesomeBarTabs.java
+++ b/mobile/android/base/AwesomeBarTabs.java
@@ -57,16 +57,17 @@ import android.view.LayoutInflater;
 import android.view.MotionEvent;
 import android.view.View;
 import android.view.ViewGroup;
 import android.view.inputmethod.InputMethodManager;
 import android.widget.AdapterView;
 import android.widget.ExpandableListView;
 import android.widget.FilterQueryProvider;
 import android.widget.ImageView;
+import android.widget.LinearLayout;
 import android.widget.ListView;
 import android.widget.SimpleCursorAdapter;
 import android.widget.SimpleExpandableListAdapter;
 import android.widget.TabHost;
 import android.widget.TextView;
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
@@ -200,17 +201,17 @@ public class AwesomeBarTabs extends TabH
         private static final int VIEW_TYPE_ITEM = 0;
         private static final int VIEW_TYPE_FOLDER = 1;
         private static final int VIEW_TYPE_COUNT = 2;
 
         private LayoutInflater mInflater;
         private Resources mResources;
         private LinkedList<Pair<Integer, String>> mParentStack;
         private RefreshBookmarkCursorTask mRefreshTask = null;
-        private TextView mBookmarksTitleView;
+        private LinearLayout mBookmarksTitleView;
 
         public BookmarksListAdapter(Context context, int layout, Cursor c, String[] from, int[] to) {
             super(context, layout, c, from, to);
 
             mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
             mResources = mContext.getResources();
 
             // mParentStack holds folder id/title pairs that allow us to navigate
@@ -302,17 +303,21 @@ public class AwesomeBarTabs extends TabH
                 convertView = mInflater.inflate(R.layout.awesomebar_folder_row, null);
 
             TextView titleView = (TextView) convertView.findViewById(R.id.title);
             titleView.setText(getFolderTitle(position));
 
             return convertView;
         }
 
-        public void setBookmarksTitleView(TextView titleView) {
+        public LinearLayout getBookmarksTitleView() {
+            return mBookmarksTitleView;
+        }
+
+        public void setBookmarksTitleView(LinearLayout titleView) {
             mBookmarksTitleView = titleView;
         }
 
         private class RefreshBookmarkCursorTask extends AsyncTask<Void, Void, Cursor> {
             private int mFolderId;
             private String mFolderTitle;
 
             public RefreshBookmarkCursorTask(int folderId, String folderTitle) {
@@ -320,26 +325,33 @@ public class AwesomeBarTabs extends TabH
                 mFolderTitle = folderTitle;
             }
 
             protected Cursor doInBackground(Void... params) {
                 return BrowserDB.getBookmarksInFolder(mContentResolver, mFolderId);
             }
 
             protected void onPostExecute(Cursor cursor) {
-                mRefreshTask = null;
-                mBookmarksAdapter.changeCursor(cursor);
+                ListView list = (ListView) findViewById(R.id.bookmarks_list);
+                list.setAdapter(null);
 
                 // Hide the header text if we're at the root folder
                 if (mFolderId == Bookmarks.FIXED_ROOT_ID) {
-                    mBookmarksTitleView.setVisibility(View.GONE);
+                    if (list.getHeaderViewsCount() == 1)
+                        list.removeHeaderView(mBookmarksTitleView);
                 } else {
-                    mBookmarksTitleView.setText(mFolderTitle);
-                    mBookmarksTitleView.setVisibility(View.VISIBLE);
+                    if (list.getHeaderViewsCount() == 0)
+                        list.addHeaderView(mBookmarksTitleView, null, true);
+
+                    ((TextView) mBookmarksTitleView.findViewById(R.id.title)).setText(mFolderTitle);
                 }
+
+                mBookmarksAdapter.changeCursor(cursor);
+                list.setAdapter(mBookmarksAdapter);
+                mRefreshTask = null;
             }
         }
     }
 
     // This method checks to see if we're in a bookmark sub-folder. If we are,
     // it will go up a level and return true. Otherwise it will return false.
     public boolean onBackPressed() {
         // If we're not in the bookmarks tab, we have nothing to do. We should
@@ -368,31 +380,25 @@ public class AwesomeBarTabs extends TabH
                 new int[] { R.id.title, R.id.url, R.id.favicon }
             );
 
             mBookmarksAdapter.setViewBinder(new AwesomeCursorViewBinder());
 
             ListView bookmarksList = (ListView) findViewById(R.id.bookmarks_list);
             bookmarksList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
-                    handleBookmarkItemClick(position);
+                    handleBookmarkItemClick(parent, view, position, id);
                 }
             });
 
-            // We need to add the header before we set the adapter
-            LayoutInflater inflater =
-                    (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
-            View headerView = inflater.inflate(R.layout.awesomebar_folder_header_row, null);
-
-            // Hide the header title view to begin with
-            TextView titleView = (TextView) headerView.findViewById(R.id.title);
-            titleView.setVisibility(View.GONE);
-            mBookmarksAdapter.setBookmarksTitleView(titleView);
-
-            bookmarksList.addHeaderView(headerView, null, true);
+            if (mBookmarksAdapter.getBookmarksTitleView() == null) {
+                // Caching the header view
+                LinearLayout headerView = (LinearLayout) LayoutInflater.from(mContext).inflate(R.layout.awesomebar_header_row, null);
+                mBookmarksAdapter.setBookmarksTitleView(headerView);
+            }
 
             bookmarksList.setAdapter(mBookmarksAdapter);
 
             mBookmarksQueryTask = null;
         }
     }
 
     private static class GroupList extends LinkedList<Map<String,String>> {
@@ -858,30 +864,34 @@ public class AwesomeBarTabs extends TabH
 
     private void hideSoftInput(View view) {
         InputMethodManager imm =
                 (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
 
         imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
     }
 
-    private void handleBookmarkItemClick(int position) {
+    private void handleBookmarkItemClick(AdapterView<?> parent, View view, int position, long id) {
+        int headerCount = ((ListView) parent).getHeaderViewsCount();
         // If we tap on the header view, there's nothing to do
-        if (position == 0)
+        if (headerCount == 1 && position == 0)
             return;
 
         Cursor cursor = mBookmarksAdapter.getCursor();
         // The header view takes up a spot in the list
-        cursor.moveToPosition(position - 1);
+        if (headerCount == 1)
+            position--;
+
+        cursor.moveToPosition(position);
 
         int type = cursor.getInt(cursor.getColumnIndexOrThrow(Bookmarks.TYPE));
         if (type == Bookmarks.TYPE_FOLDER) {
             // If we're clicking on a folder, update mBookmarksAdapter to move to that folder
             int folderId = cursor.getInt(cursor.getColumnIndexOrThrow(Bookmarks._ID));
-            String folderTitle = mBookmarksAdapter.getFolderTitle(position - 1);
+            String folderTitle = mBookmarksAdapter.getFolderTitle(position);
 
             mBookmarksAdapter.moveToChildFolder(folderId, folderTitle);
             return;
         }
 
         // Otherwise, just open the URL
         String url = cursor.getString(cursor.getColumnIndexOrThrow(URLColumns.URL));
         if (mUrlOpenListener != null)
--- a/mobile/android/base/Makefile.in
+++ b/mobile/android/base/Makefile.in
@@ -237,17 +237,16 @@ endif
 
 RES_LAYOUT = \
   $(SYNC_RES_LAYOUT) \
   res/layout/autocomplete_list.xml \
   res/layout/autocomplete_list_item.xml \
   res/layout/awesomebar.xml \
   res/layout/awesomebar_actionbar.xml \
   res/layout/awesomebar_folder_row.xml \
-  res/layout/awesomebar_folder_header_row.xml \
   res/layout/awesomebar_header_row.xml \
   res/layout/awesomebar_row.xml \
   res/layout/awesomebar_search.xml \
   res/layout/awesomebar_tab_indicator.xml \
   res/layout/awesomebar_tabs.xml \
   res/layout/bookmark_edit.xml \
   res/layout/browser_toolbar.xml \
   res/layout/doorhangerpopup.xml \
deleted file mode 100644
--- a/mobile/android/base/resources/layout/awesomebar_folder_header_row.xml
+++ /dev/null
@@ -1,18 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-                android:orientation="vertical"
-                android:layout_width="fill_parent"
-                android:layout_height="wrap_content">
-
-    <TextView android:id="@+id/title"
-              android:layout_width="fill_parent"
-              android:layout_height="wrap_content"
-              style="?android:attr/listSeparatorTextViewStyle"
-              android:textColor="?android:attr/textColorPrimary"
-              android:paddingTop="2dip"
-              android:paddingBottom="2dip"
-              android:paddingLeft="5dip"
-              android:singleLine="true"
-              android:ellipsize="middle"/>
-
-</LinearLayout>
--- a/mobile/android/base/resources/layout/awesomebar_header_row.xml
+++ b/mobile/android/base/resources/layout/awesomebar_header_row.xml
@@ -1,9 +1,22 @@
-<TextView xmlns:android="http://schemas.android.com/apk/res/android"
-          style="?android:attr/listSeparatorTextViewStyle"
-          android:textColor="?android:attr/textColorPrimary"
-          android:id="@+id/title"
-          android:layout_width="fill_parent"
-          android:layout_height="wrap_content"
-          android:paddingTop="2dip"
-          android:paddingBottom="2dip"
-          android:paddingLeft="5dip"/>
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+              android:orientation="vertical"
+              android:layout_width="fill_parent"
+              android:layout_height="wrap_content"
+              android:paddingBottom="2dp"
+              android:background="#E5E5E5">
+
+    <TextView android:id="@+id/title"
+              android:layout_width="fill_parent"
+              android:layout_height="wrap_content"
+              android:background="#FFFFFF"
+              android:textColor="#222222"
+              android:textStyle="bold"
+              android:textAppearance="?android:attr/textAppearanceSmall"
+              android:paddingTop="2dip"
+              android:paddingBottom="2dip"
+              android:paddingLeft="5dip"
+              android:singleLine="true"
+              android:ellipsize="middle"/>
+
+</LinearLayout>
--- a/mobile/android/base/resources/layout/awesomebar_tabs.xml
+++ b/mobile/android/base/resources/layout/awesomebar_tabs.xml
@@ -18,15 +18,16 @@
             <ListView android:id="@+id/all_pages_list"
                       style="@style/AwesomeBarList"/>
 
             <ListView android:id="@+id/bookmarks_list"
                       style="@style/AwesomeBarList"/>
 
             <ExpandableListView android:id="@+id/history_list"
                                 style="@style/AwesomeBarList"
+                                android:childDivider="#E5E5E5"
                                 android:groupIndicator="@android:color/transparent"/>
 
         </FrameLayout>
 
     </LinearLayout>
 
 </org.mozilla.gecko.AwesomeBarTabs>
--- a/mobile/android/base/resources/values-v11/styles.xml
+++ b/mobile/android/base/resources/values-v11/styles.xml
@@ -20,16 +20,18 @@
         <item name="android:orientation">horizontal</item>
     </style>
 
     <!-- Lists in AwesomeBar -->
     <style name="AwesomeBarList" parent="android:style/Widget.Holo.ListView">
         <item name="android:layout_width">fill_parent</item>
         <item name="android:layout_height">fill_parent</item>
         <item name="android:layout_weight">1</item>
+        <item name="android:divider">#E5E5E5</item>
+        <item name="android:dividerHeight">1dp</item>
     </style>
  
     <!-- ActionBar -->
     <style name="ActionBar" parent="android:style/Widget.Holo.ActionBar" />
 
     <!-- GeckoApp ActionBar -->
     <style name="ActionBar.GeckoApp">
          <item name="android:background">@drawable/gecko_actionbar_bg</item>
--- a/mobile/android/base/resources/values/styles.xml
+++ b/mobile/android/base/resources/values/styles.xml
@@ -62,16 +62,18 @@
         <item name="android:orientation">horizontal</item>
     </style>
 
     <!-- Lists in AwesomeBar -->
     <style name="AwesomeBarList" parent="android:style/Widget.ListView.White">
         <item name="android:layout_width">fill_parent</item>
         <item name="android:layout_height">fill_parent</item>
         <item name="android:layout_weight">1</item>
+        <item name="android:divider">#E5E5E5</item>
+        <item name="android:dividerHeight">1dp</item>
     </style>
 
     <!-- Lists in TabsTray -->
     <style name="TabsList" parent="android:style/Widget.ListView">
         <item name="android:layout_width">fill_parent</item>
         <item name="android:layout_height">fill_parent</item>
         <item name="android:layout_weight">1</item>
     </style>