Bug 898501: Re-use FaviconsLoader from HomeFragment in MostRecentPage. [r=lucasr]
authorSriram Ramasubramanian <sriram@mozilla.com>
Fri, 26 Jul 2013 15:15:54 -0700
changeset 151471 e169d1c5043cbb2799a7fb4adb58f06fae871db5
parent 151470 4e2ac48c10392f34f5f37a8b3fc1bc01efadad8a
child 151472 87e218e885055c379d16985a52def4e797fbfe5d
push idunknown
push userunknown
push dateunknown
reviewerslucasr
bugs898501
milestone25.0a1
Bug 898501: Re-use FaviconsLoader from HomeFragment in MostRecentPage. [r=lucasr]
mobile/android/base/home/MostRecentPage.java
--- a/mobile/android/base/home/MostRecentPage.java
+++ b/mobile/android/base/home/MostRecentPage.java
@@ -12,17 +12,16 @@ import org.mozilla.gecko.home.HomePager.
 import org.mozilla.gecko.home.TwoLinePageRow;
 
 import android.app.Activity;
 import android.content.ContentResolver;
 import android.content.Context;
 import android.content.res.Resources;
 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.SimpleCursorAdapter;
 import android.util.SparseArray;
 import android.view.View;
 import android.view.ViewGroup;
 import android.view.LayoutInflater;
 import android.widget.AdapterView;
 import android.widget.ListView;
@@ -33,17 +32,17 @@ import java.util.Date;
 /**
  * Fragment that displays recent history in a ListView.
  */
 public class MostRecentPage extends HomeFragment {
     // Logging tag name
     private static final String LOGTAG = "GeckoMostRecentPage";
 
     // Cursor loader ID for history query
-    private static final int HISTORY_LOADER_ID = 0;
+    private static final int LOADER_ID_HISTORY = 0;
 
     // For the time sections in history
     private static final long MS_PER_DAY = 86400000;
     private static final long MS_PER_WEEK = MS_PER_DAY * 7;
 
     // The time ranges for each section
     private static enum MostRecentSection {
         TODAY,
@@ -150,17 +149,17 @@ public class MostRecentPage extends Home
 
         // Create callbacks before the initial loader is started
         mCursorLoaderCallbacks = new CursorLoaderCallbacks();
         loadIfVisible();
     }
 
     @Override
     protected void load() {
-        getLoaderManager().initLoader(HISTORY_LOADER_ID, null, mCursorLoaderCallbacks);
+        getLoaderManager().initLoader(LOADER_ID_HISTORY, null, mCursorLoaderCallbacks);
     }
 
     private String getMostRecentSectionTitle(MostRecentSection section) {
         final Resources resources = getActivity().getResources();
 
         switch (section) {
         case TODAY:
             return resources.getString(R.string.history_today_section);
@@ -340,26 +339,44 @@ public class MostRecentPage extends Home
 
                 row.updateFromCursor(c);
 
                 return row;
             }
         }
     }
 
-    private class CursorLoaderCallbacks implements LoaderCallbacks<Cursor> {
+    private class CursorLoaderCallbacks extends HomeCursorLoaderCallbacks {
         @Override
         public Loader<Cursor> onCreateLoader(int id, Bundle args) {
-            return new MostRecentCursorLoader(getActivity());
+            if (id == LOADER_ID_HISTORY) {
+                return new MostRecentCursorLoader(getActivity());
+            } else {
+                return super.onCreateLoader(id, args);
+            }
         }
 
         @Override
         public void onLoadFinished(Loader<Cursor> loader, Cursor c) {
-            loadMostRecentSections(c);
-            mAdapter.swapCursor(c);
+            if (loader.getId() == LOADER_ID_HISTORY) {
+                loadMostRecentSections(c);
+                mAdapter.swapCursor(c);
+                loadFavicons(c);
+            } else {
+                super.onLoadFinished(loader, c);
+            }
         }
 
         @Override
         public void onLoaderReset(Loader<Cursor> loader) {
-            mAdapter.swapCursor(null);
+            if (loader.getId() == LOADER_ID_HISTORY) {
+                mAdapter.swapCursor(null);
+            } else {
+                super.onLoaderReset(loader);
+            }
         }
-    }
+
+        @Override
+        public void onFaviconsLoaded() {
+            mAdapter.notifyDataSetChanged();
+        }
+   }
 }