Bug 1288127 - load() History/Bookmarks during onResume() to ensure data is loaded r?sebastian draft
authorAndrzej Hunt <ahunt@mozilla.com>
Wed, 10 Aug 2016 14:33:08 -0700
changeset 399345 0a5f1d70e234d0bf2af605ba5f9e97ff188cd6f4
parent 399344 0fe680d7ebc47e0eb03c8e56b1d6d9a85bccb1ea
child 403368 9e62e609ca1e9af5f918c1986612221feec0afc2
push id25805
push userahunt@mozilla.com
push dateWed, 10 Aug 2016 22:18:08 +0000
reviewerssebastian
bugs1288127
milestone51.0a1
Bug 1288127 - load() History/Bookmarks during onResume() to ensure data is loaded r?sebastian HomePager has a complex story behind it. For normal ViewPager usage however (i.e. for the ASDetailActivity) we want to just load data when the fragment is shown. MozReview-Commit-ID: DUuHKbYdpXj
mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
--- a/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
@@ -36,16 +36,17 @@ import android.widget.ImageView;
 import android.widget.TextView;
 import org.json.JSONException;
 import org.json.JSONObject;
 import org.mozilla.gecko.EventDispatcher;
 import org.mozilla.gecko.GeckoAppShell;
 import org.mozilla.gecko.GeckoProfile;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.RemoteClientsDialogFragment;
+import org.mozilla.gecko.activitystream.ActivityStream;
 import org.mozilla.gecko.fxa.FirefoxAccounts;
 import org.mozilla.gecko.fxa.FxAccountConstants;
 import org.mozilla.gecko.fxa.SyncStatusListener;
 import org.mozilla.gecko.home.CombinedHistoryPanel.OnPanelLevelChangeListener.PanelLevel;
 import org.mozilla.gecko.restrictions.Restrictions;
 import org.mozilla.gecko.Telemetry;
 import org.mozilla.gecko.TelemetryContract;
 import org.mozilla.gecko.db.BrowserDB;
@@ -273,16 +274,35 @@ public class CombinedHistoryPanel extend
 
     @Override
     public void onActivityCreated(Bundle savedInstanceState) {
         super.onActivityCreated(savedInstanceState);
         mCursorLoaderCallbacks = new CursorLoaderCallbacks();
     }
 
     @Override
+    public void onResume() {
+        super.onResume();
+
+        // This is hacky, but the simplest way of reusing this panel for AS. HomePager and its
+        // HomeFragments have a complicated initialisation story (the Fragments seem to be kept
+        // alive throughout runtime, and are told to load/unload themselves - i.e. to enable/disable
+        // their loaders - when the HomePager appears/disappears).
+        // For AS we're reusing this panel in a separate activity, we really don't want to have
+        // to worry about the complex initialisation.
+        // There doesn't seem to be a good way of calling load() within the ASDetailActivity,
+        // since it can only be called once the fragment is being made visible. onResume
+        // seems to be the most logical location independent of other concerns, it seems to be cleanest
+        // to therefore just make this AS specific code within the panel.
+        if (ActivityStream.isEnabled(getContext())) {
+            load();
+        }
+    }
+
+    @Override
     protected void load() {
         getLoaderManager().initLoader(LOADER_ID_HISTORY, null, mCursorLoaderCallbacks);
         if (!mBookmarksMode) {
             getLoaderManager().initLoader(LOADER_ID_REMOTE, null, mCursorLoaderCallbacks);
         }
     }
 
     private static class RemoteTabsCursorLoader extends SimpleCursorLoader {