Bug 1400072: Specify card size in onBind instead of onCreate. r=liuche
authorMichael Comella <michael.l.comella@gmail.com>
Fri, 15 Sep 2017 14:05:21 -0700
changeset 665876 62f03c05db7827f2dcc242bb4b58049e09e1398c
parent 665875 cd4c24e98e044705b210d8bb0beb0b93c7016e84
child 665877 e8d66b5b8f6ba7ea489e8546b5b7603a4cf4f693
push id80212
push usermaglione.k@gmail.com
push dateSat, 16 Sep 2017 04:24:53 +0000
reviewersliuche
bugs1400072
milestone57.0a1
Bug 1400072: Specify card size in onBind instead of onCreate. r=liuche I believe this doesn't affect this bug because I think the ViewHolders are recreated on rotation but for any other type of change, only bind will be called so for correctness, we should update the size in bind. MozReview-Commit-ID: 3ojO4TF89i4
mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/topsites/TopSitesPageAdapter.java
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/topsites/TopSitesPageAdapter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/topsites/TopSitesPageAdapter.java
@@ -83,29 +83,28 @@ import java.util.List;
         );
 
         onUrlOpenListener.onUrlOpen(StringUtils.decodeUserEnteredUrl(topSite.getUrl()), EnumSet.noneOf(HomePager.OnUrlOpenListener.Flags.class));
     }
 
     @Override
     public void onBindViewHolder(TopSitesCard holder, int position) {
         holder.bind(topSites.get(position), getTopSiteAbsolutePosition(position));
+
+        final View card = holder.itemView;
+        final ViewGroup.LayoutParams layoutParams = card.getLayoutParams();
+        layoutParams.width = tilesSize;
+        layoutParams.height = tilesSize;
+        card.setLayoutParams(layoutParams);
     }
 
     @Override
     public TopSitesCard onCreateViewHolder(ViewGroup parent, int viewType) {
         final LayoutInflater inflater = LayoutInflater.from(parent.getContext());
-
         final FrameLayout card = (FrameLayout) inflater.inflate(R.layout.activity_stream_topsites_card, parent, false);
-
-        ViewGroup.LayoutParams layoutParams = card.getLayoutParams();
-        layoutParams.width = tilesSize;
-        layoutParams.height = tilesSize;
-        card.setLayoutParams(layoutParams);
-
         return new TopSitesCard(card, onUrlOpenListener, onUrlOpenInBackgroundListener);
     }
 
     @Override
     public int getItemCount() {
         return topSites.size();
     }