Bug 1400072: Move TOP_SITE_COLUMNS/ROWS -> TopSitesPage. r=liuche
The TopSitesPage should really own details about the appearance of top sites.
MozReview-Commit-ID: LPfHGcUTv00
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/ActivityStreamPanel.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/ActivityStreamPanel.java
@@ -16,16 +16,17 @@ import android.support.v7.widget.LinearL
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.widget.FrameLayout;
import org.mozilla.gecko.GeckoSharedPrefs;
import org.mozilla.gecko.R;
import org.mozilla.gecko.activitystream.ActivityStreamTelemetry;
import org.mozilla.gecko.activitystream.homepanel.model.TopStory;
+import org.mozilla.gecko.activitystream.homepanel.topsites.TopSitesPage;
import org.mozilla.gecko.activitystream.homepanel.topstories.PocketStoriesLoader;
import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.fxa.FirefoxAccounts;
import org.mozilla.gecko.home.HomePager;
import org.mozilla.gecko.activitystream.homepanel.model.Highlight;
import org.mozilla.gecko.activitystream.homepanel.topsites.TopSitesPagerAdapter;
import org.mozilla.gecko.widget.RecyclerViewClickSupport;
@@ -44,19 +45,16 @@ public class ActivityStreamPanel extends
*/
private static final int HIGHLIGHTS_CANDIDATES = 500;
/**
* Number of highlights that should be returned (max).
*/
private static final int HIGHLIGHTS_LIMIT = 10;
- public static final int TOP_SITES_COLUMNS = 4;
- public static final int TOP_SITES_ROWS = 2;
-
public static final String PREF_POCKET_ENABLED = "pref_activitystream_pocket_enabled";
public static final String PREF_VISITED_ENABLED = "pref_activitystream_visited_enabled";
public static final String PREF_BOOKMARKS_ENABLED = "pref_activitystream_recentbookmarks_enabled";
private int desiredTileWidth;
private int tileMargin;
private final SharedPreferences sharedPreferences;
@@ -123,36 +121,36 @@ public class ActivityStreamPanel extends
// * Calculate the size of the tiles we want to display (using a desired width as anchor point)
// * Add padding to the left/right side if there's too much space that we do not need
// Calculate how many tiles fit into the available horizontal space if we are using our
// desired tile width.
int fittingTiles = (w - tileMargin) / (desiredTileWidth + tileMargin);
- if (fittingTiles <= TOP_SITES_COLUMNS) {
+ 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);
- } else if (fittingTiles > TOP_SITES_COLUMNS) {
+ } 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.
- int needed = TOP_SITES_COLUMNS * (desiredTileWidth + tileMargin) + tileMargin;
+ int needed = TopSitesPage.NUM_COLUMNS * (desiredTileWidth + tileMargin) + tileMargin;
int padding = (w - needed) / 2;
// With the padding applied we have less space available for the tiles
w = needed;
setPadding(padding, 0, padding, 0);
}
// Now calculate how large an individual tile is
- final int tilesSize = (w - (TOP_SITES_COLUMNS * tileMargin) - tileMargin) / TOP_SITES_COLUMNS;
+ final int tilesSize = (w - (TopSitesPage.NUM_COLUMNS * tileMargin) - tileMargin) / TopSitesPage.NUM_COLUMNS;
- adapter.setTileSize(TOP_SITES_COLUMNS * TOP_SITES_ROWS, tilesSize);
+ adapter.setTileSize(TopSitesPage.NUM_COLUMNS * TopSitesPage.NUM_ROWS, tilesSize);
}
private class HighlightsCallbacks implements LoaderManager.LoaderCallbacks<List<Highlight>> {
@Override
public Loader<List<Highlight>> onCreateLoader(int id, Bundle args) {
return new HighlightsLoader(getContext(), HIGHLIGHTS_CANDIDATES, HIGHLIGHTS_LIMIT);
}
@@ -165,17 +163,17 @@ public class ActivityStreamPanel extends
public void onLoaderReset(Loader<List<Highlight>> loader) {
adapter.swapHighlights(Collections.<Highlight>emptyList());
}
}
private class TopSitesCallback implements LoaderManager.LoaderCallbacks<Cursor> {
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
- final int topSitesPerPage = TOP_SITES_COLUMNS * TOP_SITES_ROWS;
+ final int topSitesPerPage = TopSitesPage.NUM_COLUMNS * TopSitesPage.NUM_ROWS;
final Context context = getContext();
return BrowserDB.from(context).getActivityStreamTopSites(
context,
topSitesPerPage * TopSitesPagerAdapter.SUGGESTED_SITES_MAX_PAGES,
topSitesPerPage * TopSitesPagerAdapter.PAGES);
}
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/topsites/TopSitesPage.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/topsites/TopSitesPage.java
@@ -5,22 +5,23 @@
package org.mozilla.gecko.activitystream.homepanel.topsites;
import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
-import org.mozilla.gecko.activitystream.homepanel.ActivityStreamPanel;
-import org.mozilla.gecko.home.HomePager;
+public class TopSitesPage extends RecyclerView {
-public class TopSitesPage extends RecyclerView {
+ public static final int NUM_COLUMNS = 4;
+ public static final int NUM_ROWS = 2;
+
public TopSitesPage(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
- setLayoutManager(new GridLayoutManager(getContext(), ActivityStreamPanel.TOP_SITES_COLUMNS));
+ setLayoutManager(new GridLayoutManager(getContext(), NUM_COLUMNS));
}
public TopSitesPageAdapter getAdapter() {
return (TopSitesPageAdapter) super.getAdapter();
}
}