Bug 929982 - Change Bookmark's parent stack to use a custom type. r=margaret, a=lsblakk
authorLucas Rocha <lucasr@mozilla.com>
Wed, 20 Nov 2013 19:51:00 +0000
changeset 161133 007e71a400d7da67410925113cca8c98adfed75d
parent 161132 3c836f5b410920f95d4e849904c8659e3d23d31e
child 161134 79ece4f7ff8f1ce9da8d1fae49ee8017159f6c37
push id3041
push userryanvm@gmail.com
push dateMon, 25 Nov 2013 21:17:40 +0000
treeherdermozilla-beta@0c2f6fb212aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmargaret, lsblakk
bugs929982
milestone26.0
Bug 929982 - Change Bookmark's parent stack to use a custom type. r=margaret, a=lsblakk
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
@@ -7,33 +7,33 @@ package org.mozilla.gecko.home;
 
 import org.mozilla.gecko.favicons.Favicons;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.Tabs;
 import org.mozilla.gecko.db.BrowserContract.Bookmarks;
 import org.mozilla.gecko.db.BrowserDB;
 import org.mozilla.gecko.db.BrowserDB.URLColumns;
 import org.mozilla.gecko.gfx.BitmapUtils;
+import org.mozilla.gecko.home.BookmarksListAdapter.FolderInfo;
 import org.mozilla.gecko.home.BookmarksListAdapter.OnRefreshFolderListener;
 import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
 import org.mozilla.gecko.util.ThreadUtils;
 
 import android.app.Activity;
 import android.content.ContentResolver;
 import android.content.Context;
 import android.content.res.Configuration;
 import android.database.Cursor;
 import android.graphics.Bitmap;
 import android.os.Bundle;
 import android.support.v4.app.LoaderManager;
 import android.support.v4.app.LoaderManager.LoaderCallbacks;
 import android.support.v4.content.Loader;
 import android.text.TextUtils;
 import android.util.Log;
-import android.util.Pair;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 
 import java.util.List;
 
 /**
  * A page in about:home that displays a ListView of bookmarks.
@@ -49,17 +49,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;
 
     // Callback for cursor loaders.
     private CursorLoaderCallbacks mLoaderCallbacks;
 
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
         final View view = inflater.inflate(R.layout.home_bookmarks_page, container, false);