Bug 898501: Re-use FaviconsLoader from HomeFragment in MostVisitedPage. [r=lucasr]
authorSriram Ramasubramanian <sriram@mozilla.com>
Fri, 26 Jul 2013 15:44:29 -0700
changeset 151472 87e218e885055c379d16985a52def4e797fbfe5d
parent 151471 e169d1c5043cbb2799a7fb4adb58f06fae871db5
child 151473 1cc7d733d8c11f8c54ee64f944eb6efe3d6f10ff
push idunknown
push userunknown
push dateunknown
reviewerslucasr
bugs898501
milestone25.0a1
Bug 898501: Re-use FaviconsLoader from HomeFragment in MostVisitedPage. [r=lucasr]
mobile/android/base/home/MostVisitedPage.java
--- a/mobile/android/base/home/MostVisitedPage.java
+++ b/mobile/android/base/home/MostVisitedPage.java
@@ -10,17 +10,16 @@ import org.mozilla.gecko.db.BrowserDB;
 import org.mozilla.gecko.db.BrowserDB.URLColumns;
 import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
 
 import android.app.Activity;
 import android.content.ContentResolver;
 import android.content.Context;
 import android.database.Cursor;
 import android.os.Bundle;
-import android.support.v4.app.LoaderManager.LoaderCallbacks;
 import android.support.v4.content.Loader;
 import android.support.v4.widget.CursorAdapter;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.AdapterView;
 import android.widget.ListView;
 import android.widget.TextView;
@@ -28,20 +27,17 @@ import android.widget.TextView;
 /**
  * Fragment that displays frecency search results in a ListView.
  */
 public class MostVisitedPage extends HomeFragment {
     // Logging tag name
     private static final String LOGTAG = "GeckoMostVisitedPage";
 
     // Cursor loader ID for search query
-    private static final int FRECENCY_LOADER_ID = 0;
-
-    // Cursor loader ID for favicons query
-    private static final int FAVICONS_LOADER_ID = 1;
+    private static final int LOADER_ID_FRECENCY = 0;
 
     // Adapter for the list of search results
     private VisitedAdapter mAdapter;
 
     // The view shown by the fragment.
     private ListView mList;
 
     // Empty message view
@@ -126,17 +122,17 @@ public class MostVisitedPage extends Hom
 
         // Create callbacks before the initial loader is started
         mCursorLoaderCallbacks = new CursorLoaderCallbacks();
         loadIfVisible();
     }
 
     @Override
     protected void load() {
-        getLoaderManager().initLoader(FRECENCY_LOADER_ID, null, mCursorLoaderCallbacks);
+        getLoaderManager().initLoader(LOADER_ID_FRECENCY, null, mCursorLoaderCallbacks);
     }
 
     private static class FrecencyCursorLoader extends SimpleCursorLoader {
         // Max number of search results
         private static final int SEARCH_LIMIT = 50;
 
         public FrecencyCursorLoader(Context context) {
             super(context);
@@ -161,60 +157,47 @@ public class MostVisitedPage extends Hom
         }
 
         @Override
         public View newView(Context context, Cursor cursor, ViewGroup parent) {
             return LayoutInflater.from(parent.getContext()).inflate(R.layout.home_item_row, parent, false);
         }
     }
 
-    private class CursorLoaderCallbacks implements LoaderCallbacks<Cursor> {
+    private class CursorLoaderCallbacks extends HomeCursorLoaderCallbacks {
         @Override
         public Loader<Cursor> onCreateLoader(int id, Bundle args) {
-            switch(id) {
-            case FRECENCY_LOADER_ID:
+            if (id == LOADER_ID_FRECENCY) {
                 return new FrecencyCursorLoader(getActivity());
-
-            case FAVICONS_LOADER_ID:
-                return FaviconsLoader.createInstance(getActivity(), args);
+            } else {
+                return super.onCreateLoader(id, args);
             }
-
-            return null;
         }
 
         @Override
         public void onLoadFinished(Loader<Cursor> loader, Cursor c) {
-            final int loaderId = loader.getId();
-            switch(loaderId) {
-            case FRECENCY_LOADER_ID:
+            if (loader.getId() == LOADER_ID_FRECENCY) {
                 // Only set empty view once cursor is loaded to avoid
                 // flashing the empty message before loading.
                 mList.setEmptyView(mEmptyMessage);
 
                 mAdapter.swapCursor(c);
-
-                FaviconsLoader.restartFromCursor(getLoaderManager(), FAVICONS_LOADER_ID,
-                        mCursorLoaderCallbacks, c);
-                break;
-
-            case FAVICONS_LOADER_ID:
-                // Causes the listview to recreate its children and use the
-                // now in-memory favicons.
-                mAdapter.notifyDataSetChanged();
-                break;
+                loadFavicons(c);
+            } else {
+                super.onLoadFinished(loader, c);
             }
         }
 
         @Override
         public void onLoaderReset(Loader<Cursor> loader) {
-            final int loaderId = loader.getId();
-            switch(loaderId) {
-            case FRECENCY_LOADER_ID:
+            if (loader.getId() == LOADER_ID_FRECENCY) {
                 mAdapter.swapCursor(null);
-                break;
+            } else {
+                super.onLoaderReset(loader);
+            }
+        }
 
-            case FAVICONS_LOADER_ID:
-                // Do nothing
-                break;
-            }
+        @Override
+        public void onFaviconsLoaded() {
+            mAdapter.notifyDataSetChanged();
         }
     }
 }