Bug 1277978 - Part 3 - Allow the RecentTabsAdapter to indicate whether the tab count is reliable. r=liuche draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Sat, 20 Aug 2016 17:49:34 +0200
changeset 412354 490581270e65c0e29afa100ee2351b4511114cbf
parent 412353 b5cd02ef0dc8d538bf9fc3402fb5ae44cf95fdf6
child 412355 37919db0672045bbdbb6133273e9c66beb18f84f
push id29155
push usermozilla@buttercookie.de
push dateSat, 10 Sep 2016 11:55:24 +0000
reviewersliuche
bugs1277978
milestone51.0a1
Bug 1277978 - Part 3 - Allow the RecentTabsAdapter to indicate whether the tab count is reliable. r=liuche After we've set the cached tabs count to display within the history adapter, we don't want to revise that number downwards as long as the RecentTabsAdapter hasn't yet checked all of its data sources. MozReview-Commit-ID: BMpiaEb3kGQ
mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryAdapter.java
mobile/android/base/java/org/mozilla/gecko/home/RecentTabsAdapter.java
--- a/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryAdapter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryAdapter.java
@@ -81,27 +81,27 @@ public class CombinedHistoryAdapter exte
                     notifyItemChanged(getSyncedDevicesSmartFolderIndex());
                 }
             };
         }
         return devicesUpdateHandler;
     }
 
     public interface RecentTabsUpdateHandler {
-        void onRecentTabsCountUpdated(int count);
+        void onRecentTabsCountUpdated(int count, boolean countReliable);
     }
 
     public RecentTabsUpdateHandler getRecentTabsUpdateHandler() {
         if (recentTabsUpdateHandler != null) {
             return recentTabsUpdateHandler;
         }
 
         recentTabsUpdateHandler = new RecentTabsUpdateHandler() {
             @Override
-            public void onRecentTabsCountUpdated(final int count) {
+            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() {
                         final boolean prevFolderVisibility = isRecentTabsFolderVisible();
                         recentTabsCount = count;
--- a/mobile/android/base/java/org/mozilla/gecko/home/RecentTabsAdapter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/RecentTabsAdapter.java
@@ -41,16 +41,17 @@ public class RecentTabsAdapter extends R
     private static final int NAVIGATION_BACK_BUTTON_INDEX = 0;
 
     private static final String TELEMETRY_EXTRA_LAST_TIME = "recent_tabs_last_time";
     private static final String TELEMETRY_EXTRA_RECENTLY_CLOSED = "recent_closed_tabs";
     private static final String TELEMETRY_EXTRA_MIXED = "recent_tabs_mixed";
 
     // Recently closed tabs from Gecko.
     private ClosedTab[] recentlyClosedTabs;
+    private boolean recentlyClosedTabsReceived = false;
 
     // "Tabs from last time".
     private ClosedTab[] lastSessionTabs;
 
     public static final class ClosedTab {
         public final String url;
         public final String title;
         public final String data;
@@ -81,16 +82,17 @@ public class RecentTabsAdapter extends R
     public void startListeningForClosedTabs() {
         EventDispatcher.getInstance().registerGeckoThreadListener(this, "ClosedTabs:Data");
         GeckoAppShell.notifyObservers("ClosedTabs:StartNotifications", null);
     }
 
     public void stopListeningForClosedTabs() {
         GeckoAppShell.notifyObservers("ClosedTabs:StopNotifications", null);
         EventDispatcher.getInstance().unregisterGeckoThreadListener(this, "ClosedTabs:Data");
+        recentlyClosedTabsReceived = false;
     }
 
     public void startListeningForHistorySanitize() {
         EventDispatcher.getInstance().registerGeckoThreadListener(this, "Sanitize:Finished");
     }
 
     public void stopListeningForHistorySanitize() {
         EventDispatcher.getInstance().unregisterGeckoThreadListener(this, "Sanitize:Finished");
@@ -124,17 +126,19 @@ public class RecentTabsAdapter extends R
             public void run() {
                 // Save some data about the old panel state, so we can be
                 // smarter about notifying the recycler view which bits changed.
                 int prevClosedTabsCount = recentlyClosedTabs.length;
                 boolean prevSectionHeaderVisibility = isSectionHeaderVisible();
                 int prevSectionHeaderIndex = getSectionHeaderIndex();
 
                 recentlyClosedTabs = closedTabs;
-                recentTabsUpdateHandler.onRecentTabsCountUpdated(getClosedTabsCount());
+                recentlyClosedTabsReceived = true;
+                recentTabsUpdateHandler.onRecentTabsCountUpdated(
+                        getClosedTabsCount(), recentlyClosedTabsReceived);
                 panelStateUpdateHandler.onPanelStateUpdated();
 
                 // Handle the section header hiding/unhiding.
                 updateHeaderVisibility(prevSectionHeaderVisibility, prevSectionHeaderIndex);
 
                 // Update the "Recently closed" part of the tab list.
                 updateTabsList(prevClosedTabsCount, recentlyClosedTabs.length, getFirstRecentTabIndex(), getLastRecentTabIndex());
             }
@@ -180,17 +184,18 @@ public class RecentTabsAdapter extends R
                     public void run() {
                         // Save some data about the old panel state, so we can be
                         // smarter about notifying the recycler view which bits changed.
                         int prevClosedTabsCount = lastSessionTabs.length;
                         boolean prevSectionHeaderVisibility = isSectionHeaderVisible();
                         int prevSectionHeaderIndex = getSectionHeaderIndex();
 
                         lastSessionTabs = closedTabs;
-                        recentTabsUpdateHandler.onRecentTabsCountUpdated(getClosedTabsCount());
+                        recentTabsUpdateHandler.onRecentTabsCountUpdated(
+                                getClosedTabsCount(), recentlyClosedTabsReceived);
                         panelStateUpdateHandler.onPanelStateUpdated();
 
                         // Handle the section header hiding/unhiding.
                         updateHeaderVisibility(prevSectionHeaderVisibility, prevSectionHeaderIndex);
 
                         // Update the "Tabs from last time" part of the tab list.
                         updateTabsList(prevClosedTabsCount, lastSessionTabs.length, getFirstLastSessionTabIndex(), getLastLastSessionTabIndex());
                     }
@@ -210,17 +215,18 @@ public class RecentTabsAdapter extends R
             public void run() {
                 // Save some data about the old panel state, so we can be
                 // smarter about notifying the recycler view which bits changed.
                 int prevClosedTabsCount = lastSessionTabs.length;
                 boolean prevSectionHeaderVisibility = isSectionHeaderVisible();
                 int prevSectionHeaderIndex = getSectionHeaderIndex();
 
                 lastSessionTabs = emptyLastSessionTabs;
-                recentTabsUpdateHandler.onRecentTabsCountUpdated(getClosedTabsCount());
+                recentTabsUpdateHandler.onRecentTabsCountUpdated(
+                        getClosedTabsCount(), recentlyClosedTabsReceived);
                 panelStateUpdateHandler.onPanelStateUpdated();
 
                 // Handle the section header hiding.
                 updateHeaderVisibility(prevSectionHeaderVisibility, prevSectionHeaderIndex);
 
                 // Handle the "tabs from last time" being cleared.
                 if (prevClosedTabsCount > 0) {
                     notifyItemRangeRemoved(getFirstLastSessionTabIndex(), prevClosedTabsCount);