Bug 1400072 - wip: Update tileSize when swapping TopSitePage cursor. draft
authorMichael Comella <michael.l.comella@gmail.com>
Thu, 14 Sep 2017 17:06:58 -0700
changeset 665173 c133223661eb2ca41948ec5e893641ffa94e5325
parent 664985 593158cd491002031b4527a95d9bfac79c0cdcef
child 731670 62e9209a111b465170dc499e9b2b4d79a3684f2b
push id79947
push usermichael.l.comella@gmail.com
push dateFri, 15 Sep 2017 00:07:22 +0000
bugs1400072
milestone57.0a1
Bug 1400072 - wip: Update tileSize when swapping TopSitePage cursor. MozReview-Commit-ID: 9Hd2cmbDd0P
mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/topsites/TopSitesPageAdapter.java
mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/topsites/TopSitesPagerAdapter.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
@@ -47,19 +47,22 @@ import java.util.List;
         this.onUrlOpenListener = onUrlOpenListener;
         this.onUrlOpenInBackgroundListener = onUrlOpenInBackgroundListener;
     }
 
     /**
      * @param startIndex The first item that this topsites group should show. This item, and the following
      * 3 items will be displayed by this adapter.
      */
-    public void swapCursor(Cursor cursor, int startIndex) {
+    public void swapCursor(Cursor cursor, int startIndex, int tilesSize, int tiles) {
         topSites.clear();
 
+        this.tilesSize = tilesSize;
+        this.tiles = tiles;
+
         if (cursor == null) {
             return;
         }
 
         for (int i = 0; i < tiles && startIndex + i < cursor.getCount(); i++) {
             cursor.moveToPosition(startIndex + i);
 
             topSites.add(TopSite.fromCursor(cursor));
--- 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
@@ -14,16 +14,18 @@ import android.view.ViewParent;
 
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.home.HomePager;
 import org.mozilla.gecko.widget.RecyclerViewClickSupport;
 
 import java.util.ArrayList;
 import java.util.List;
 
+import static org.mozilla.gecko.R.id.container;
+
 /**
  * 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;
 
@@ -44,18 +46,26 @@ public class TopSitesPagerAdapter extend
         pages = new ArrayList<>(PAGES);
 
         this.context = context;
         this.onUrlOpenListener = onUrlOpenListener;
         this.onUrlOpenInBackgroundListener = onUrlOpenInBackgroundListener;
     }
 
     public void setTilesSize(int tiles, int tilesSize) {
+        if (this.tiles == tiles && this.tilesSize == tilesSize) {
+            return;
+        }
+
         this.tilesSize = tilesSize;
         this.tiles = tiles;
+
+        for (final TopSitesPage page : pages) {
+            page.getAdapter().notifyDataSetChanged();
+        }
     }
 
     @Override
     public int getCount() {
         return Math.min(count, 4);
     }
 
     @Override
@@ -116,25 +126,26 @@ public class TopSitesPagerAdapter extend
                 RecyclerViewClickSupport.addTo(page).setOnItemClickListener(adapter);
                 pages.add(page);
             }
         } else if (pageDelta < 0) {
             for (int i = 0; i > pageDelta; i--) {
                 final TopSitesPage page = pages.get(pages.size() - 1);
 
                 // Ensure the page doesn't use the old/invalid cursor anymore
-                page.getAdapter().swapCursor(null, 0);
+                page.getAdapter().swapCursor(null, 0, tilesSize, tiles);
 
                 pages.remove(pages.size() - 1);
             }
         } else {
             // do nothing: we will be updating all the pages below
         }
 
+        // todo: need to pass in new tiles, tilesSize
         int startIndex = 0;
         for (TopSitesPage page : pages) {
-            page.getAdapter().swapCursor(cursor, startIndex);
+            page.getAdapter().swapCursor(cursor, startIndex, tilesSize, tiles);
             startIndex += tiles;
         }
 
         notifyDataSetChanged();
     }
 }