Bug 1400825 - Collapse top sites if there are no sites. r=liuche, a=sledru
authorMichael Comella <michael.l.comella@gmail.com>
Fri, 22 Sep 2017 13:56:13 -0700
changeset 431835 c7907ac20968c2311d83e5338158d5c6621c3852
parent 431834 2ac4b62c58a1dda9582e521459dc2827626b90eb
child 431836 2d4c045f3066e9b6292bb8bf5571517be0161502
push id7821
push userryanvm@gmail.com
push dateMon, 25 Sep 2017 14:09:06 +0000
treeherdermozilla-beta@fd78928b00d8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersliuche, sledru
bugs1400825
milestone57.0
Bug 1400825 - Collapse top sites if there are no sites. r=liuche, a=sledru MozReview-Commit-ID: D0eNQBp6IZB
mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/stream/TopPanelRow.java
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/stream/TopPanelRow.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/stream/TopPanelRow.java
@@ -9,16 +9,17 @@ import android.content.res.Resources;
 import android.database.Cursor;
 import android.support.v4.view.ViewPager;
 import android.view.View;
 import android.view.ViewGroup;
 
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.Telemetry;
 import org.mozilla.gecko.TelemetryContract;
+import org.mozilla.gecko.activitystream.homepanel.topsites.TopSitesPage;
 import org.mozilla.gecko.activitystream.homepanel.topsites.TopSitesPagerAdapter;
 import org.mozilla.gecko.home.HomePager;
 
 public class TopPanelRow extends StreamViewHolder {
     public static final int LAYOUT_ID = R.layout.activity_stream_main_toppanel;
 
     private final ViewPager topSitesPager;
 
@@ -55,20 +56,33 @@ public class TopPanelRow extends StreamV
 
     public void bind(Cursor cursor, int tilesSize) {
         final TopSitesPagerAdapter adapter = (TopSitesPagerAdapter) topSitesPager.getAdapter();
         adapter.swapCursor(cursor, tilesSize);
 
         final Resources resources = itemView.getResources();
         final int tilesMargin = resources.getDimensionPixelSize(R.dimen.activity_stream_base_margin);
 
-        final int rows = cursor == null || cursor.getCount() > 4 ? 2 : 1;
+        final int rows;
+
+        // The cursor is null when the view is first created. The view will layout with the number of rows we
+        // set initially (while we load the Cursor) and these rows (with no content) will be briefly visible
+        // to users. Since we expect 2 rows to be the most common for users, we show 2 rows at this point;
+        // the RecyclerView will gracefully animate a collapse if we display fewer.
+        if (cursor == null || cursor.getCount() > TopSitesPage.NUM_COLUMNS) {
+            rows = 2;
+        } else if (cursor.getCount() > 0) {
+            rows = 1;
+        } else {
+            // The user has deleted history and removed all suggested sites.
+            rows = 0;
+        }
 
         ViewGroup.LayoutParams layoutParams = topSitesPager.getLayoutParams();
-        layoutParams.height = (tilesSize * rows) + (tilesMargin * 2);
+        layoutParams.height = rows > 0 ? (tilesSize * rows) + (tilesMargin * 2) : 0;
         topSitesPager.setLayoutParams(layoutParams);
 
         // Reset the page position: binding a new Cursor means that topsites reverts to the first page,
         // no event is sent in that case, but we need to know the right page number to send correct
         // page swipe events
         swipeListener.currentPosition = 0;
     }
 }
\ No newline at end of file