Bug 898501: Re-use FaviconsLoader from HomeFragment in BookmarksPage. [r=lucasr]
authorSriram Ramasubramanian <sriram@mozilla.com>
Mon, 29 Jul 2013 15:05:18 -0700
changeset 143479 f2d68c93e066df60706cffd8a09fe8f941accf3c
parent 143478 0398421459d76af1ccd8f677fd2fe315177e34e8
child 143480 4fa359c591e579c98b7abd3d955aa781eba60fbc
push id25130
push userlrocha@mozilla.com
push dateWed, 21 Aug 2013 09:41:27 +0000
treeherdermozilla-central@b2486721572e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslucasr
bugs898501
milestone25.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 898501: Re-use FaviconsLoader from HomeFragment in BookmarksPage. [r=lucasr]
mobile/android/base/home/BookmarksPage.java
--- a/mobile/android/base/home/BookmarksPage.java
+++ b/mobile/android/base/home/BookmarksPage.java
@@ -51,26 +51,23 @@ import java.util.Map;
 
 /**
  * A page in about:home that displays a ListView of bookmarks.
  */
 public class BookmarksPage extends HomeFragment {
     public static final String LOGTAG = "GeckoBookmarksPage";
 
     // Cursor loader ID for list of bookmarks.
-    private static final int BOOKMARKS_LIST_LOADER_ID = 0;
+    private static final int LOADER_ID_BOOKMARKS_LIST = 0;
 
     // Cursor loader ID for grid of bookmarks.
-    private static final int TOP_BOOKMARKS_LOADER_ID = 1;
-
-    // Loader ID for favicons.
-    private static final int FAVICONS_LOADER_ID = 2;
+    private static final int LOADER_ID_TOP_BOOKMARKS = 1;
 
     // Loader ID for thumbnails.
-    private static final int THUMBNAILS_LOADER_ID = 3;
+    private static final int LOADER_ID_THUMBNAILS = 2;
 
     // Key for bookmarks folder id.
     private static final String BOOKMARKS_FOLDER_KEY = "folder_id";
 
     // Key for thumbnail urls.
     private static final String THUMBNAILS_URLS_KEY = "urls";
 
     // List of bookmarks.
@@ -139,17 +136,17 @@ public class BookmarksPage extends HomeF
         // Setup the list adapter.
         mListAdapter = new BookmarksListAdapter(getActivity(), null);
         mListAdapter.setOnRefreshFolderListener(new OnRefreshFolderListener() {
             @Override
             public void onRefreshFolder(int folderId) {
                 // Restart the loader with folder as the argument.
                 Bundle bundle = new Bundle();
                 bundle.putInt(BOOKMARKS_FOLDER_KEY, folderId);
-                getLoaderManager().restartLoader(BOOKMARKS_LIST_LOADER_ID, bundle, mLoaderCallbacks);
+                getLoaderManager().restartLoader(LOADER_ID_BOOKMARKS_LIST, bundle, mLoaderCallbacks);
             }
         });
         mList.setAdapter(mListAdapter);
 
         // Create callbacks before the initial loader is started.
         mLoaderCallbacks = new CursorLoaderCallbacks();
         mThumbnailsLoaderCallbacks = new ThumbnailsLoaderCallbacks();
         loadIfVisible();
@@ -285,18 +282,18 @@ public class BookmarksPage extends HomeF
         }
 
         return false;
     }
 
     @Override
     protected void load() {
         final LoaderManager manager = getLoaderManager();
-        manager.initLoader(BOOKMARKS_LIST_LOADER_ID, null, mLoaderCallbacks);
-        manager.initLoader(TOP_BOOKMARKS_LOADER_ID, null, mLoaderCallbacks);
+        manager.initLoader(LOADER_ID_BOOKMARKS_LIST, null, mLoaderCallbacks);
+        manager.initLoader(LOADER_ID_TOP_BOOKMARKS, null, mLoaderCallbacks);
     }
 
     /**
      * Listener for pinning bookmarks.
      */
     private class PinBookmarkListener implements OnPinBookmarkListener,
                                                  OnBookmarkSelectedListener {
         // Tag for the PinBookmarkDialog fragment.
@@ -366,103 +363,104 @@ public class BookmarksPage extends HomeF
             final int max = getContext().getResources().getInteger(R.integer.number_of_top_sites);
             return BrowserDB.getTopSites(getContext().getContentResolver(), max);
         }
     }
 
     /**
      * Loader callbacks for the LoaderManager of this fragment.
      */
-    private class CursorLoaderCallbacks implements LoaderCallbacks<Cursor> {
+    private class CursorLoaderCallbacks extends HomeCursorLoaderCallbacks {
         @Override
         public Loader<Cursor> onCreateLoader(int id, Bundle args) {
             switch(id) {
-                case BOOKMARKS_LIST_LOADER_ID: {
+                case LOADER_ID_BOOKMARKS_LIST: {
                     if (args == null) {
                         return new BookmarksLoader(getActivity());
                     } else {
                         return new BookmarksLoader(getActivity(), args.getInt(BOOKMARKS_FOLDER_KEY));
                     }
                 }
 
-                case TOP_BOOKMARKS_LOADER_ID: {
+                case LOADER_ID_TOP_BOOKMARKS: {
                     return new TopBookmarksLoader(getActivity());
                 }
 
-                case FAVICONS_LOADER_ID: {
-                    return FaviconsLoader.createInstance(getActivity(), args);
+                default: {
+                    return super.onCreateLoader(id, args);
                 }
             }
-
-            return null;
         }
 
         @Override
         public void onLoadFinished(Loader<Cursor> loader, Cursor c) {
             final int loaderId = loader.getId();
             switch(loaderId) {
-                case BOOKMARKS_LIST_LOADER_ID: {
+                case LOADER_ID_BOOKMARKS_LIST: {
                     mListAdapter.swapCursor(c);
-                    FaviconsLoader.restartFromCursor(getLoaderManager(), FAVICONS_LOADER_ID,
-                            mLoaderCallbacks, c);
+                    loadFavicons(c);
                     break;
                 }
 
-                case TOP_BOOKMARKS_LOADER_ID: {
+                case LOADER_ID_TOP_BOOKMARKS: {
                     mTopBookmarksAdapter.swapCursor(c);
 
                     // Load the thumbnails.
                     if (c.getCount() > 0 && c.moveToFirst()) {
                         final ArrayList<String> urls = new ArrayList<String>();
                         do {
                             final String url = c.getString(c.getColumnIndexOrThrow(URLColumns.URL));
                             urls.add(url);
                         } while (c.moveToNext());
 
                         if (urls.size() > 0) {
                             Bundle bundle = new Bundle();
                             bundle.putStringArrayList(THUMBNAILS_URLS_KEY, urls);
-                            getLoaderManager().restartLoader(THUMBNAILS_LOADER_ID, bundle, mThumbnailsLoaderCallbacks);
+                            getLoaderManager().restartLoader(LOADER_ID_THUMBNAILS, bundle, mThumbnailsLoaderCallbacks);
                         }
                     }
                     break;
                 }
 
-                case FAVICONS_LOADER_ID: {
-                    // Force the list to use in-memory favicons.
-                    mListAdapter.notifyDataSetChanged();
+                default: {
+                    super.onLoadFinished(loader, c);
                     break;
                 }
             }
         }
 
         @Override
         public void onLoaderReset(Loader<Cursor> loader) {
             final int loaderId = loader.getId();
             switch(loaderId) {
-                case BOOKMARKS_LIST_LOADER_ID: {
+                case LOADER_ID_BOOKMARKS_LIST: {
                     if (mList != null) {
                         mListAdapter.swapCursor(null);
                     }
                     break;
                 }
 
-                case TOP_BOOKMARKS_LOADER_ID: {
+                case LOADER_ID_TOP_BOOKMARKS: {
                     if (mTopBookmarks != null) {
                         mTopBookmarksAdapter.swapCursor(null);
                         break;
                     }
                 }
 
-                case FAVICONS_LOADER_ID: {
-                    // Do nothing.
+                default: {
+                    super.onLoaderReset(loader);
                     break;
                 }
             }
         }
+
+        @Override
+        public void onFaviconsLoaded() {
+            mListAdapter.notifyDataSetChanged();
+        }
     }
 
     /**
      * An AsyncTaskLoader to load the thumbnails from a cursor.
      */
     private static class ThumbnailsLoader extends AsyncTaskLoader<Map<String, Thumbnail>> {
         private Map<String, Thumbnail> mThumbnails;
         private ArrayList<String> mUrls;