Bug 1400825: Collapse top sites if there are no sites. r=liuche draft
authorMichael Comella <michael.l.comella@gmail.com>
Fri, 22 Sep 2017 13:56:13 -0700
changeset 669347 df34bcfc2feaedee88f24c5c0bf9500358f6c331
parent 669346 9c3feafe5a2d5499a8dac278214776f81e36aee4
child 732932 8ef8a0b1dfc59bad7f620c284b787b8e7d9e6385
push id81302
push usermichael.l.comella@gmail.com
push dateFri, 22 Sep 2017 22:43:34 +0000
reviewersliuche
bugs1400825
milestone58.0a1
Bug 1400825: Collapse top sites if there are no sites. r=liuche 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