Bug 1277978 - Part 5 - Once we can access the panelStateChangeListener, use it to retrieve the cached tabs count when initialising the HistoryAdapter. r=liuche
authorJan Henning <jh+bugzilla@buttercookie.de>
Mon, 29 Aug 2016 20:51:21 +0200
changeset 356956 31471e296123b59d27df63649984b801d9e4b2fd
parent 356955 11658ac8e339ee16684a8742f5240d97a8240efe
child 356957 126538cebd689046dc2ad1fe13acbd2f4b6aae76
push id1324
push usermtabara@mozilla.com
push dateMon, 16 Jan 2017 13:07:44 +0000
treeherdermozilla-release@a01c49833940 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersliuche
bugs1277978
milestone51.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 1277978 - Part 5 - Once we can access the panelStateChangeListener, use it to retrieve the cached tabs count when initialising the HistoryAdapter. r=liuche While passing the cached tabs count to the HistoryAdapter in its constructor greatly simplifies getting the cached count into the adapter before the RecyclerView initialises, this relies on the History panel having the panelStateChangeListener available before the HistoryAdapter is created in onCreate(). MozReview-Commit-ID: 64IbAe6SaEq
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
@@ -47,18 +47,19 @@ public class CombinedHistoryAdapter exte
     private RecentTabsUpdateHandler recentTabsUpdateHandler;
     private int recentTabsCount = 0;
 
     private LinearLayoutManager linearLayoutManager; // Only used on the UI thread, so no need to be volatile.
 
     // We use a sparse array to store each section header's position in the panel [more cheaply than a HashMap].
     private final SparseArray<SectionHeader> sectionHeaders;
 
-    public CombinedHistoryAdapter(Resources resources) {
+    public CombinedHistoryAdapter(Resources resources, int cachedRecentTabsCount) {
         super();
+        recentTabsCount = cachedRecentTabsCount;
         sectionHeaders = new SparseArray<>();
         HistorySectionsHelper.updateRecentSectionOffset(resources, sectionDateRangeArray);
         this.setHasStableIds(true);
     }
 
     public void setPanelStateChangeListener(
             HomeFragment.PanelStateChangeListener panelStateChangeListener) {
         this.panelStateChangeListener = panelStateChangeListener;
@@ -105,16 +106,25 @@ public class CombinedHistoryAdapter exte
             @Override
             public void onRecentTabsCountUpdated(final int count, final boolean countReliable) {
                 // Now that other items can move around depending on the visibility of the
                 // Recent Tabs folder, only update the recentTabsCount on the UI thread.
                 ThreadUtils.postToUiThread(new Runnable() {
                     @UiThread
                     @Override
                     public void run() {
+                        if (!countReliable && count <= recentTabsCount) {
+                            // The final tab count (where countReliable = true) is normally >= than
+                            // previous values with countReliable = false. Hence we only want to
+                            // update the displayed tab count with a preliminary value if it's larger
+                            // than the previous count, so as to avoid the displayed count jumping
+                            // downwards and then back up, as well as unnecessary folder animations.
+                            return;
+                        }
+
                         final boolean prevFolderVisibility = isRecentTabsFolderVisible();
                         recentTabsCount = count;
                         final boolean folderVisible = isRecentTabsFolderVisible();
 
                         if (prevFolderVisibility == folderVisible) {
                             if (prevFolderVisibility) {
                                 notifyItemChanged(RECENT_TABS_SMARTFOLDER_INDEX);
                             }
--- a/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
@@ -105,20 +105,25 @@ public class CombinedHistoryPanel extend
          */
         boolean changeLevel(PanelLevel level);
     }
 
     @Override
     public void onCreate(Bundle savedInstance) {
         super.onCreate(savedInstance);
 
-        mHistoryAdapter = new CombinedHistoryAdapter(getResources());
+        int cachedRecentTabsCount = 0;
+        if (mPanelStateChangeListener != null ) {
+            cachedRecentTabsCount = mPanelStateChangeListener.getCachedRecentTabsCount();
+        }
+        mHistoryAdapter = new CombinedHistoryAdapter(getResources(), cachedRecentTabsCount);
         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();