author | Michael Comella <michael.l.comella@gmail.com> |
Fri, 22 Sep 2017 13:56:13 -0700 | |
changeset 382555 | a54290a32fd6978e9f89ab4efd823e936258ba84 |
parent 382554 | 10241c6a7b3a72cfd1310d985d9868da28306724 |
child 382556 | 722e1226aa7a1676dfa936d01ba00920ef2736c1 |
push id | 51906 |
push user | michael.l.comella@gmail.com |
push date | Fri, 22 Sep 2017 22:48:27 +0000 |
treeherder | autoland@a54290a32fd6 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | liuche |
bugs | 1400825 |
milestone | 58.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
|
mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/stream/TopPanelRow.java | file | annotate | diff | comparison | revisions |
--- 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