Bug 1400072: Pass in tilesSize when needed, rather than caching. r=liuche
authorMichael Comella <michael.l.comella@gmail.com>
Fri, 15 Sep 2017 10:39:36 -0700
changeset 665873 ec4dcc7799ad8fa5beb6e728b0801e55dd616e0a
parent 665872 fea444196dee6a021d70f38f5e6884f87f2aa64e
child 665874 45f33d2b572218950d819c0341774d45a40c7bb5
push id80212
push usermaglione.k@gmail.com
push dateSat, 16 Sep 2017 04:24:53 +0000
reviewersliuche
bugs1400072
milestone57.0a1
Bug 1400072: Pass in tilesSize when needed, rather than caching. r=liuche This will help prevent the cache from going out of date. MozReview-Commit-ID: GdUXF0oOSiK
mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/stream/TopPanelRow.java
mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/topsites/TopSitesPagerAdapter.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
@@ -50,18 +50,17 @@ public class TopPanelRow extends StreamV
 
         topSitesPager = (ViewPager) itemView.findViewById(R.id.topsites_pager);
         topSitesPager.setAdapter(new TopSitesPagerAdapter(itemView.getContext(), onUrlOpenListener, onUrlOpenInBackgroundListener));
         topSitesPager.addOnPageChangeListener(swipeListener);
     }
 
     public void bind(Cursor cursor, int tilesSize) {
         final TopSitesPagerAdapter adapter = (TopSitesPagerAdapter) topSitesPager.getAdapter();
-        adapter.setTilesSize(tilesSize);
-        adapter.swapCursor(cursor);
+        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;
 
         ViewGroup.LayoutParams layoutParams = topSitesPager.getLayoutParams();
         layoutParams.height = (tilesSize * rows) + (tilesMargin * 2);
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/topsites/TopSitesPagerAdapter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/topsites/TopSitesPagerAdapter.java
@@ -24,18 +24,16 @@ import static org.mozilla.gecko.activity
 /**
  * The primary / top-level TopSites adapter: it handles the ViewPager, and also handles
  * all lower-level Adapters that populate the individual topsite items.
  */
 public class TopSitesPagerAdapter extends PagerAdapter {
     public static final int PAGES = 2;
     public static final int SUGGESTED_SITES_MAX_PAGES = 2;
 
-    private int tilesSize;
-
     private final List<TopSitesPage> pages;
 
     private final Context context;
     private final HomePager.OnUrlOpenListener onUrlOpenListener;
     private final HomePager.OnUrlOpenInBackgroundListener onUrlOpenInBackgroundListener;
 
     private int count = 0;
 
@@ -44,20 +42,16 @@ public class TopSitesPagerAdapter extend
                                 HomePager.OnUrlOpenInBackgroundListener onUrlOpenInBackgroundListener) {
         pages = new ArrayList<>(PAGES);
 
         this.context = context;
         this.onUrlOpenListener = onUrlOpenListener;
         this.onUrlOpenInBackgroundListener = onUrlOpenInBackgroundListener;
     }
 
-    public void setTilesSize(int tilesSize) {
-        this.tilesSize = tilesSize;
-    }
-
     @Override
     public int getCount() {
         return Math.min(count, 4);
     }
 
     @Override
     public boolean isViewFromObject(View view, Object object) {
         return view == object;
@@ -88,17 +82,17 @@ public class TopSitesPagerAdapter extend
         }
     }
 
     @Override
     public void destroyItem(ViewGroup container, int position, Object object) {
         container.removeView((View) object);
     }
 
-    public void swapCursor(Cursor cursor) {
+    public void swapCursor(final Cursor cursor, final int tilesSize) {
         // Divide while rounding up: 0 items = 0 pages, 1-ITEMS_PER_PAGE items = 1 page, etc.
         if (cursor != null) {
             count = (cursor.getCount() - 1) / TopSitesPage.NUM_TILES + 1;
         } else {
             count = 0;
         }
 
         // Try to only add/remove pages if really needed: this minimises the amount of UI work that