Bug 882365: Header count recalibaration for click events. [r=lucasr]
authorSriram Ramasubramanian <sriram@mozilla.com>
Tue, 18 Jun 2013 15:12:14 -0700
changeset 143417 42c9ee1b0a158b5970d89f00c831827bf5cf99ef
parent 143416 e2a28f0025f10afb9e5adf1c249b8855f8868200
child 143418 78e379237afba52edd8b5be357cba5984b1b2148
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)
reviewerslucasr
bugs882365
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 882365: Header count recalibaration for click events. [r=lucasr]
mobile/android/base/home/BookmarksListView.java
--- a/mobile/android/base/home/BookmarksListView.java
+++ b/mobile/android/base/home/BookmarksListView.java
@@ -42,16 +42,19 @@ public class BookmarksListView extends H
     private BookmarksListAdapter mCursorAdapter = null;
 
     // A background task to query the db.
     private BookmarksQueryTask mQueryTask = null;
 
     // Folder title for the currently shown list of bookmarks.
     private BookmarkFolderView mFolderView;
 
+    // Check for adding a header view, if needed.
+    private boolean mHasFolderHeader = false;
+
     public BookmarksListView(Context context) {
         this(context, null);
     }
 
     public BookmarksListView(Context context, AttributeSet attrs) {
         this(context, attrs, android.R.attr.listViewStyle);
     }
 
@@ -100,31 +103,35 @@ public class BookmarksListView extends H
         }
     }
 
     @Override
     public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
         final ListView list = (ListView) parent;
         final int headerCount = list.getHeaderViewsCount();
 
-        // If we tap on the header view, move back to parent folder.
-        if (headerCount == 1 && position == 0) {
-            mCursorAdapter.moveToParentFolder();
+        if (mHasFolderHeader) {
+            // If we tap on the folder view (last of the header views),
+            // move back to parent folder.
+            if (position == headerCount - 1) {   
+                mCursorAdapter.moveToParentFolder();
+                return;
+            }
+        } else if (position < headerCount) {
+            // The click is on a header, don't do anything.
             return;
         }
 
         final Cursor cursor = mCursorAdapter.getCursor();
         if (cursor == null) {
             return;
         }
 
-        // The header view takes up a spot in the list
-        if (headerCount == 1) {
-            position--;
-        }
+        // Absolute position for the adapter.
+        position -= headerCount;
 
         cursor.moveToPosition(position);
 
         int type = cursor.getInt(cursor.getColumnIndexOrThrow(Bookmarks.TYPE));
         if (type == Bookmarks.TYPE_FOLDER) {
             // If we're clicking on a folder, update adapter to move to that folder
             final int folderId = cursor.getInt(cursor.getColumnIndexOrThrow(Bookmarks._ID));
             final String folderTitle = mCursorAdapter.getFolderTitle(position);
@@ -140,22 +147,24 @@ public class BookmarksListView extends H
     }
 
     private void refreshListWithCursor(Cursor cursor) {
         // We need to add the header before we set the adapter, hence making it null.
         setAdapter(null);
 
         // Add a header view based on the root folder.
         if (mFolderId == Bookmarks.FIXED_ROOT_ID) {
-            if (getHeaderViewsCount() == 1) {
+            if (mHasFolderHeader) {
                 removeHeaderView(mFolderView);
+                mHasFolderHeader = false;
             }
         } else {
-            if (getHeaderViewsCount() == 0) {
+            if (!mHasFolderHeader) {
                 addHeaderView(mFolderView, null, true);
+                mHasFolderHeader = true;
             }
 
             mFolderView.setText(mFolderTitle);
         }
 
         // This will update the cursorAdapter to use the new one if it already exists.
         mCursorAdapter.changeCursor(cursor);
         setAdapter(mCursorAdapter);