Bug 1399683: Change padding of content view rather than self in onSizeChanged. r=sebastian

To be honest, I'm not sure why this works. onSizeChanged seems to be a callback
to notify the user that your layout has completed and not a place to update
layout params. However, it makes *slightly* more sense that you could update
your children's layout from this view, which is what this patch changes the
code to do.

I think I could figure out why this works if I dug further into [1] but I have
other things to focus on.

I don't think this is the most correct solution, but it is likely the smallest
and least risky change we can make to fix this issue, which is ideal because
we'd like to uplift this to the 57 Beta.

A more correct solution would override the Activity Stream RecyclerView and
provide different desired measurements to its parent so that the new size is
set *during* layout rather than after it, which would make the layout process
more efficient. However, this type of code is less commonly written day-to-day
by developers so it's harder to write, harder to maintain, and I'd have to read
a lot of [1] in order to write it. :)

[1]: https://developer.android.com/guide/topics/ui/how-android-draws.html

MozReview-Commit-ID: AceUvDYGWCR

--HG--
extra : rebase_source : 5fe014388db8e4186c2cda54a453930bf8eed211
This commit is contained in:
Michael Comella 2017-09-21 15:40:55 -07:00
parent 4ead787594
commit 2eca8411a3

View File

@ -54,6 +54,8 @@ public class ActivityStreamPanel extends FrameLayout {
public static final String PREF_VISITED_ENABLED = "pref_activitystream_visited_enabled";
public static final String PREF_BOOKMARKS_ENABLED = "pref_activitystream_recentbookmarks_enabled";
private final RecyclerView contentRecyclerView;
private int desiredTileWidth;
private int tileMargin;
private final SharedPreferences sharedPreferences;
@ -68,16 +70,15 @@ public class ActivityStreamPanel extends FrameLayout {
adapter = new StreamRecyclerAdapter();
sharedPreferences = GeckoSharedPrefs.forProfile(context);
final RecyclerView rv = (RecyclerView) findViewById(R.id.activity_stream_main_recyclerview);
rv.setAdapter(adapter);
rv.setLayoutManager(new LinearLayoutManager(getContext()));
rv.setHasFixedSize(true);
contentRecyclerView = (RecyclerView) findViewById(R.id.activity_stream_main_recyclerview);
contentRecyclerView.setAdapter(adapter);
contentRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
contentRecyclerView.setHasFixedSize(true);
// Override item animations to avoid horrible topsites refreshing
rv.setItemAnimator(new StreamItemAnimator());
rv.addItemDecoration(new HighlightsDividerItemDecoration(context));
contentRecyclerView.setItemAnimator(new StreamItemAnimator());
contentRecyclerView.addItemDecoration(new HighlightsDividerItemDecoration(context));
RecyclerViewClickSupport.addTo(rv)
RecyclerViewClickSupport.addTo(contentRecyclerView)
.setOnItemClickListener(adapter)
.setOnItemLongClickListener(adapter);
@ -150,7 +151,7 @@ public class ActivityStreamPanel extends FrameLayout {
if (fittingTiles <= TopSitesPage.NUM_COLUMNS) {
// We can't fit all tiles (or they fit exactly) if we are using the desired tiles width.
// We will still show all tiles but they might be smaller than what we would like them to be.
setPadding(0, 0, 0, 0);
contentRecyclerView.setPadding(0, 0, 0, 0);
} else if (fittingTiles > TopSitesPage.NUM_COLUMNS) {
// We can fit more tiles than we want to display. Calculate how much space we need and
// use the remaining space as padding on the left and right.
@ -160,7 +161,7 @@ public class ActivityStreamPanel extends FrameLayout {
// With the padding applied we have less space available for the tiles
w = needed;
setPadding(padding, 0, padding, 0);
contentRecyclerView.setPadding(padding, 0, padding, 0);
}
// Now calculate how large an individual tile is