Bug 929982 - Change Bookmark's parent stack to use a custom type (r=margaret, a=bajaj)
authorLucas Rocha <lucasr@mozilla.com>
Wed, 20 Nov 2013 19:51:00 +0000
changeset 167521 edcf89fbe953b64a1c6c47134cf13ffac9641d70
parent 167520 fa324ac537dd58ff6674f9e5123b2a04519ee780
child 167522 a4bb868db6fb3187833f9ffc6b84cf310b6f7f65
push id428
push userbbajaj@mozilla.com
push dateTue, 28 Jan 2014 00:16:25 +0000
treeherdermozilla-release@cd72a7ff3a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmargaret, bajaj
bugs929982
milestone27.0a2
Bug 929982 - Change Bookmark's parent stack to use a custom type (r=margaret, a=bajaj)
mobile/android/base/home/BookmarksListAdapter.java
mobile/android/base/home/BookmarksPage.java
--- a/mobile/android/base/home/BookmarksListAdapter.java
+++ b/mobile/android/base/home/BookmarksListAdapter.java
@@ -6,70 +6,83 @@
 package org.mozilla.gecko.home;
 
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.db.BrowserContract.Bookmarks;
 
 import android.content.Context;
 import android.content.res.Resources;
 import android.database.Cursor;
-import android.util.Pair;
 import android.view.View;
 
 import java.util.Collections;
 import java.util.List;
 import java.util.LinkedList;
 
 /**
  * Adapter to back the BookmarksListView with a list of bookmarks.
  */
 class BookmarksListAdapter extends MultiTypeCursorAdapter {
     private static final int VIEW_TYPE_ITEM = 0;
     private static final int VIEW_TYPE_FOLDER = 1;
 
     private static final int[] VIEW_TYPES = new int[] { VIEW_TYPE_ITEM, VIEW_TYPE_FOLDER };
     private static final int[] LAYOUT_TYPES = new int[] { R.layout.bookmark_item_row, R.layout.bookmark_folder_row };
 
+    public class FolderInfo {
+        public final int id;
+        public final String title;
+
+        public FolderInfo(int id) {
+            this(id, "");
+        }
+
+        public FolderInfo(int id, String title) {
+            this.id = id;
+            this.title = title;
+        }
+    }
+
     // A listener that knows how to refresh the list for a given folder id.
     // This is usually implemented by the enclosing fragment/activity.
     public static interface OnRefreshFolderListener {
         // The folder id to refresh the list with.
         public void onRefreshFolder(int folderId);
     }
 
-    // mParentStack holds folder id/title pairs that allow us to navigate
-    // back up the folder heirarchy.
-    private LinkedList<Pair<Integer, String>> mParentStack;
+    // mParentStack holds folder info instances (id + title) that allow
+    // us to navigate back up the folder hierarchy.
+    private LinkedList<FolderInfo> mParentStack;
 
     // Refresh folder listener.
     private OnRefreshFolderListener mListener;
 
-    public BookmarksListAdapter(Context context, Cursor cursor, List<Pair<Integer, String>> parentStack) {
+    public BookmarksListAdapter(Context context, Cursor cursor, List<FolderInfo> parentStack) {
         // Initializing with a null cursor.
         super(context, cursor, VIEW_TYPES, LAYOUT_TYPES);
 
         if (parentStack == null) {
-            mParentStack = new LinkedList<Pair<Integer, String>>();
+            mParentStack = new LinkedList<FolderInfo>();
 
             // Add the root folder to the stack
-            Pair<Integer, String> rootFolder = new Pair<Integer, String>(Bookmarks.FIXED_ROOT_ID, "");
+            FolderInfo rootFolder = new FolderInfo(Bookmarks.FIXED_ROOT_ID);
             mParentStack.addFirst(rootFolder);
         } else {
-            mParentStack = new LinkedList<Pair<Integer, String>>(parentStack);
+            mParentStack = new LinkedList<FolderInfo>(parentStack);
         }
     }
 
-    public List<Pair<Integer, String>> getParentStack() {
+    public List<FolderInfo> getParentStack() {
         return Collections.unmodifiableList(mParentStack);
     }
 
     // Refresh the current folder by executing a new task.
     private void refreshCurrentFolder() {
         if (mListener != null) {
-            mListener.onRefreshFolder(mParentStack.peek().first);
+            mListener.onRefreshFolder(mParentStack.peek().id);
         }
     }
 
     /**
      * Moves to parent folder, if one exists.
      *
      * @return Whether the adapter successfully moved to a parent folder.
      */
@@ -86,18 +99,18 @@ class BookmarksListAdapter extends Multi
 
     /**
      * Moves to child folder, given a folderId.
      *
      * @param folderId The id of the folder to show.
      * @param folderTitle The title of the folder to show.
      */
     public void moveToChildFolder(int folderId, String folderTitle) {
-        Pair<Integer, String> folderPair = new Pair<Integer, String>(folderId, folderTitle);
-        mParentStack.addFirst(folderPair);
+        FolderInfo folderInfo = new FolderInfo(folderId, folderTitle);
+        mParentStack.addFirst(folderInfo);
         refreshCurrentFolder();
     }
 
     /**
      * Set a listener that can refresh this adapter.
      *
      * @param listener The listener that can refresh the adapter.
      */
@@ -158,17 +171,17 @@ class BookmarksListAdapter extends Multi
         // the special folders we expect in the UI, just return the title from the DB.
         return c.getString(c.getColumnIndexOrThrow(Bookmarks.TITLE));
     }
 
     /**
      * @return true, if currently showing a child folder, false otherwise.
      */
     public boolean isShowingChildFolder() {
-        return (mParentStack.peek().first != Bookmarks.FIXED_ROOT_ID);
+        return (mParentStack.peek().id != Bookmarks.FIXED_ROOT_ID);
     }
 
     @Override
     public int getCount() {
         return super.getCount() + (isShowingChildFolder() ? 1 : 0);
     }
 
     @Override
@@ -189,17 +202,17 @@ class BookmarksListAdapter extends Multi
         }
 
         if (viewType == VIEW_TYPE_ITEM) {
             final TwoLinePageRow row = (TwoLinePageRow) view;
             row.updateFromCursor(cursor);
         } else {
             final BookmarkFolderView row = (BookmarkFolderView) view;
             if (cursor == null) {
-                row.setText(mParentStack.peek().second);
+                row.setText(mParentStack.peek().title);
                 row.open();
             } else {
                 row.setText(getFolderTitle(context, cursor));
                 row.close();
             }
         }
     }
 }
--- a/mobile/android/base/home/BookmarksPage.java
+++ b/mobile/android/base/home/BookmarksPage.java
@@ -3,27 +3,27 @@
  * 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.R;
 import org.mozilla.gecko.db.BrowserContract.Bookmarks;
 import org.mozilla.gecko.db.BrowserDB;
+import org.mozilla.gecko.home.BookmarksListAdapter.FolderInfo;
 import org.mozilla.gecko.home.BookmarksListAdapter.OnRefreshFolderListener;
 import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
 
 import android.app.Activity;
 import android.content.Context;
 import android.content.res.Configuration;
 import android.database.Cursor;
 import android.os.Bundle;
 import android.support.v4.app.LoaderManager.LoaderCallbacks;
 import android.support.v4.content.Loader;
-import android.util.Pair;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewStub;
 import android.view.ViewGroup;
 import android.widget.ImageView;
 import android.widget.TextView;
 
 import java.util.List;
@@ -42,17 +42,17 @@ public class BookmarksPage extends HomeF
 
     // List of bookmarks.
     private BookmarksListView mList;
 
     // Adapter for list of bookmarks.
     private BookmarksListAdapter mListAdapter;
 
     // Adapter's parent stack.
-    private List<Pair<Integer, String>> mSavedParentStack;
+    private List<FolderInfo> mSavedParentStack;
 
     // Reference to the View to display when there are no results.
     private View mEmptyView;
 
     // Callback for cursor loaders.
     private CursorLoaderCallbacks mLoaderCallbacks;
 
     @Override