Bug 1251362 - Part 6 - Update empty panel state when recent tabs count changes. r=liuche
authorJan Henning <jh+bugzilla@buttercookie.de>
Sun, 15 May 2016 01:41:45 +0200
changeset 301159 6d3b17555d95b47def48b5186fed8d883b5825ec
parent 301158 9ccad5daa84c0d76e2712f137c9f33e48d97ea81
child 301160 26b34894a22e724ba180143f41cfed5c825ead78
push id78241
push userkwierso@gmail.com
push dateThu, 09 Jun 2016 00:09:10 +0000
treeherdermozilla-inbound@2c66b75bbb7f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersliuche
bugs1251362
milestone50.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 1251362 - Part 6 - Update empty panel state when recent tabs count changes. r=liuche The recent tabs count might change while the Recent Tabs folder is open, e.g. immediately after startup, once we receive the first "ClosedTabs:Data" message from the session store. Therefore, we need to hide/unhide the empty view as necessary, which is normally handled by the Combined History panel's updateEmptyView() function. Since we aren't using a cursor, we can't hinge calling that on the CursorLoader's onLoadFinished() callback, so instead, we include our own callback to the Combined History panel, modelled after the DeviceUpdateHandler used for updating the count of synced devices. MozReview-Commit-ID: GLHM9LoWk2h
mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
mobile/android/base/java/org/mozilla/gecko/home/RecentTabsAdapter.java
--- a/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
@@ -75,16 +75,18 @@ public class CombinedHistoryPanel extend
     private CombinedHistoryAdapter mHistoryAdapter;
     private ClientsAdapter mClientsAdapter;
     private RecentTabsAdapter mRecentTabsAdapter;
     private CursorLoaderCallbacks mCursorLoaderCallbacks;
 
     private PanelLevel mPanelLevel;
     private Button mPanelFooterButton;
 
+    private PanelStateUpdateHandler mPanelStateUpdateHandler;
+
     // Child refresh layout view.
     protected SwipeRefreshLayout mRefreshLayout;
 
     // Sync listener that stops refreshing when a sync is completed.
     protected RemoteTabsSyncListener mSyncStatusListener;
 
     // Reference to the View to display when there are no results.
     private View mHistoryEmptyView;
@@ -105,17 +107,20 @@ public class CombinedHistoryPanel extend
     }
 
     @Override
     public void onCreate(Bundle savedInstance) {
         super.onCreate(savedInstance);
 
         mHistoryAdapter = new CombinedHistoryAdapter(getResources());
         mClientsAdapter = new ClientsAdapter(getContext());
-        mRecentTabsAdapter = new RecentTabsAdapter(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(), getPanelStateUpdateHandler());
 
         mSyncStatusListener = new RemoteTabsSyncListener();
         FirefoxAccounts.addSyncStatusListener(mSyncStatusListener);
     }
 
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
         return inflater.inflate(R.layout.home_combined_history_panel, container, false);
@@ -307,16 +312,33 @@ public class CombinedHistoryPanel extend
 
         @Override
         public void onLoaderReset(Loader<Cursor> loader) {
             mClientsAdapter.setClients(Collections.<RemoteClient>emptyList());
             mHistoryAdapter.setHistory(null);
         }
     }
 
+    public interface PanelStateUpdateHandler {
+        void onPanelStateUpdated();
+    }
+
+    public PanelStateUpdateHandler getPanelStateUpdateHandler() {
+        if (mPanelStateUpdateHandler == null) {
+            mPanelStateUpdateHandler = new PanelStateUpdateHandler() {
+                @Override
+                public void onPanelStateUpdated() {
+                    updateEmptyView();
+                    updateButtonFromLevel();
+                }
+            };
+        }
+        return mPanelStateUpdateHandler;
+    }
+
     protected class OnLevelChangeListener implements OnPanelLevelChangeListener {
         @Override
         public boolean changeLevel(PanelLevel level) {
             if (level == mPanelLevel) {
                 return false;
             }
 
             mPanelLevel = level;
@@ -399,17 +421,17 @@ public class CombinedHistoryPanel extend
                 showEmptyHistoryView = mHistoryAdapter.getItemCount() == NUM_SMART_FOLDERS;
                 break;
 
             case CHILD_SYNC:
                 showEmptyClientsView = mClientsAdapter.getItemCount() == 1;
                 break;
 
             case CHILD_RECENT_TABS:
-                showEmptyRecentTabsView = mRecentTabsAdapter.getItemCount() == 1;
+                showEmptyRecentTabsView = mRecentTabsAdapter.getClosedTabsCount() == 0;
                 break;
         }
 
         final boolean showEmptyView = showEmptyClientsView || showEmptyHistoryView || showEmptyRecentTabsView;
         mRecyclerView.setOverScrollMode(showEmptyView ? View.OVER_SCROLL_NEVER : View.OVER_SCROLL_IF_CONTENT_SCROLLS);
 
         mClientsEmptyView.setVisibility(showEmptyClientsView ? View.VISIBLE : View.GONE);
         mHistoryEmptyView.setVisibility(showEmptyHistoryView ? View.VISIBLE : View.GONE);
--- a/mobile/android/base/java/org/mozilla/gecko/home/RecentTabsAdapter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/RecentTabsAdapter.java
@@ -13,16 +13,17 @@ import android.view.ViewGroup;
 import android.widget.TextView;
 
 import org.mozilla.gecko.AboutPages;
 import org.mozilla.gecko.EventDispatcher;
 import org.mozilla.gecko.GeckoAppShell;
 import org.mozilla.gecko.GeckoProfile;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.SessionParser;
+import org.mozilla.gecko.home.CombinedHistoryPanel.PanelStateUpdateHandler;
 import org.mozilla.gecko.util.EventCallback;
 import org.mozilla.gecko.util.NativeEventListener;
 import org.mozilla.gecko.util.NativeJSObject;
 import org.mozilla.gecko.util.ThreadUtils;
 
 import java.util.ArrayList;
 import java.util.List;
 
@@ -48,19 +49,22 @@ public class RecentTabsAdapter extends R
         public ClosedTab(String url, String title, String data) {
             this.url = url;
             this.title = title;
             this.data = data;
         }
     }
 
     private final Context context;
+    private final PanelStateUpdateHandler panelStateUpdateHandler;
 
-    public RecentTabsAdapter(Context context) {
+    public RecentTabsAdapter(Context context,
+                             PanelStateUpdateHandler panelStateUpdateHandler) {
         this.context = context;
+        this.panelStateUpdateHandler = panelStateUpdateHandler;
         recentlyClosedTabs = new ClosedTab[0];
         lastSessionTabs = new ClosedTab[0];
 
         readPreviousSessionData();
     }
 
     public void startListeningForClosedTabs() {
         EventDispatcher.getInstance().registerGeckoThreadListener(this, "ClosedTabs:Data");
@@ -89,16 +93,17 @@ 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;
+                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());
             }
         });
@@ -141,16 +146,17 @@ 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;
+                        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());
                     }
                 });