Bug 1277978 - Part 4 - Actually cache the recent tabs count when it updates. r=liuche draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Sat, 10 Sep 2016 13:51:35 +0200
changeset 412355 37919db0672045bbdbb6133273e9c66beb18f84f
parent 412354 490581270e65c0e29afa100ee2351b4511114cbf
child 412356 9b5848c1d183817693413b9a7a0f4478f86cf2cb
push id29155
push usermozilla@buttercookie.de
push dateSat, 10 Sep 2016 11:55:24 +0000
reviewersliuche
bugs1277978
milestone51.0a1
Bug 1277978 - Part 4 - Actually cache the recent tabs count when it updates. r=liuche MozReview-Commit-ID: JUsM3qdxhIr
mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryAdapter.java
mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
--- a/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryAdapter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryAdapter.java
@@ -34,16 +34,18 @@ public class CombinedHistoryAdapter exte
         MONTH_AGO,
         TWO_MONTHS_AGO,
         THREE_MONTHS_AGO,
         FOUR_MONTHS_AGO,
         FIVE_MONTHS_AGO,
         OLDER_THAN_SIX_MONTHS
     }
 
+    private HomeFragment.PanelStateChangeListener panelStateChangeListener;
+
     private Cursor historyCursor;
     private DevicesUpdateHandler devicesUpdateHandler;
     private int deviceCount = 0;
     private RecentTabsUpdateHandler recentTabsUpdateHandler;
     private int recentTabsCount = 0;
 
     private LinearLayoutManager linearLayoutManager; // Only used on the UI thread, so no need to be volatile.
 
@@ -52,16 +54,21 @@ public class CombinedHistoryAdapter exte
 
     public CombinedHistoryAdapter(Resources resources) {
         super();
         sectionHeaders = new SparseArray<>();
         HistorySectionsHelper.updateRecentSectionOffset(resources, sectionDateRangeArray);
         this.setHasStableIds(true);
     }
 
+    public void setPanelStateChangeListener(
+            HomeFragment.PanelStateChangeListener panelStateChangeListener) {
+        this.panelStateChangeListener = panelStateChangeListener;
+    }
+
     @UiThread
     public void setLinearLayoutManager(LinearLayoutManager linearLayoutManager) {
         this.linearLayoutManager = linearLayoutManager;
     }
 
     public void setHistory(Cursor history) {
         historyCursor = history;
         populateSectionHeaders(historyCursor, sectionHeaders);
@@ -131,16 +138,20 @@ public class CombinedHistoryAdapter exte
                             // However we only do this if our current scroll position is at the
                             // top of the list.
                             if (linearLayoutManager != null && scrollPos == 0) {
                                 linearLayoutManager.scrollToPosition(0);
                             }
                         } else {
                             notifyItemRemoved(RECENT_TABS_SMARTFOLDER_INDEX);
                         }
+
+                        if (countReliable) {
+                            panelStateChangeListener.setCachedRecentTabsCount(recentTabsCount);
+                        }
                     }
                 });
             }
         };
         return recentTabsUpdateHandler;
     }
 
     @UiThread
--- a/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
@@ -106,16 +106,19 @@ public class CombinedHistoryPanel extend
         boolean changeLevel(PanelLevel level);
     }
 
     @Override
     public void onCreate(Bundle savedInstance) {
         super.onCreate(savedInstance);
 
         mHistoryAdapter = new CombinedHistoryAdapter(getResources());
+        if (mPanelStateChangeListener != null) {
+            mHistoryAdapter.setPanelStateChangeListener(mPanelStateChangeListener);
+        }
         mClientsAdapter = new ClientsAdapter(getContext());
         // The RecentTabsAdapter doesn't use a cursor and therefore can't use the CursorLoader's
         // onLoadFinished() callback for updating the panel state when the closed tab count changes.
         // Instead, we provide it with independent callbacks as necessary.
         mRecentTabsAdapter = new RecentTabsAdapter(getContext(),
                 mHistoryAdapter.getRecentTabsUpdateHandler(), getPanelStateUpdateHandler());
 
         mSyncStatusListener = new RemoteTabsSyncListener();
@@ -235,16 +238,25 @@ public class CombinedHistoryPanel extend
         final ImageView recentTabsIcon = (ImageView) mRecentTabsEmptyView.findViewById(R.id.home_empty_image);
         recentTabsIcon.setImageResource(R.drawable.icon_remote_tabs_empty);
 
         final TextView recentTabsText = (TextView) mRecentTabsEmptyView.findViewById(R.id.home_empty_text);
         recentTabsText.setText(R.string.home_last_tabs_empty);
     }
 
     @Override
+    public void setPanelStateChangeListener(
+            PanelStateChangeListener panelStateChangeListener) {
+        super.setPanelStateChangeListener(panelStateChangeListener);
+        if (mHistoryAdapter != null) {
+            mHistoryAdapter.setPanelStateChangeListener(panelStateChangeListener);
+        }
+    }
+
+    @Override
     public void restoreData(Bundle data) {
         if (mRecyclerView != null) {
             setPanelStateFromBundle(data);
         } else {
             mSavedRestoreBundle = data;
         }
     }