Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1538)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPageCardsManager.java

Issue 1812293002: Add new NTP layout with snippet cards and hide it behind a flag (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPageCardsManager.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPageCardsManager.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPageCardsManager.java
new file mode 100644
index 0000000000000000000000000000000000000000..9f3d1bce690e311d3d39cf8398a8aae0c6a36bf5
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPageCardsManager.java
@@ -0,0 +1,77 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.ntp;
+
+import org.chromium.chrome.browser.ntp.snippets.NewTabPageAdapter;
+import org.chromium.chrome.browser.ntp.snippets.SnippetsManager;
+
+import java.util.List;
+import java.util.Observable;
+import java.util.Observer;
+
+/**
+ * A class that handles merging above the fold elements and below the fold cards.
+ */
+public class NewTabPageCardsManager implements Observer {
newt (away) 2016/03/23 05:29:38 I'm not convinced this class should exist. Could e
May 2016/03/23 19:22:56 Yeah, I think NewTabPageAdapter could be combined
+ /**
+ * Describes the above the fold item
+ */
+ public static final int SNIPPET_ITEM_ABOVE_THE_FOLD = 1;
+ /**
+ * Describes the header of a group of similar card snippets
+ */
+ public static final int SNIPPET_ITEM_TYPE_HEADER = 2;
+ /**
+ * Describes a single card snippet
+ */
+ public static final int SNIPPET_ITEM_TYPE_SNIPPET = 3;
+
+ /** Base type for anything to add to the new tab page
newt (away) 2016/03/23 05:29:38 fix wrapping, spacing, and indentation in comments
May 2016/03/23 19:22:56 Done.
+ */
+ public interface NewTabPageListItem {
+ /**
+ * Returns the type of this snippet item (SNIPPET_ITEM_TYPE_HEADER or
+ * SNIPPET_ITEM_TYPE_SNIPPET). This is so we can distinguish between different elements
+ * that are held in a single RecyclerView holder.
+ *
+ * @return the type of this list item.
+ */
+ public int getType();
+ }
+
+ /** Represents the data for a header of a group of snippets
newt (away) 2016/03/23 05:29:38 This comment doesn't seem right
May 2016/03/23 19:22:56 Done.
+ */
+ public static class AboveTheFoldListItem implements NewTabPageListItem {
+ public AboveTheFoldListItem() {}
+
+ @Override
+ public int getType() {
+ return NewTabPageCardsManager.SNIPPET_ITEM_ABOVE_THE_FOLD;
+ }
+ }
+
+ private SnippetsManager mSnippetsManager;
+ private NewTabPageAdapter mDataAdapter;
+ private NewTabPageLayout mAboveTheFoldContentsView;
+
+ public NewTabPageCardsManager(SnippetsManager manager, NewTabRecyclerView recyclerView,
newt (away) 2016/03/23 05:29:38 javadoc
May 2016/03/23 19:22:56 Done.
+ NewTabPageLayout aboveTheFoldView) {
+ mSnippetsManager = manager;
+ mAboveTheFoldContentsView = aboveTheFoldView;
+ mDataAdapter = new NewTabPageAdapter(mSnippetsManager, mAboveTheFoldContentsView);
+ mDataAdapter.setAboveTheFoldItem(new AboveTheFoldListItem());
+ recyclerView.setAdapter(mDataAdapter);
+ mSnippetsManager.addObserver(this);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public void update(Observable observable, Object data) {
+ if (data instanceof List) {
newt (away) 2016/03/23 05:29:37 And if this instanceof check fails? Seems like a s
May 2016/03/23 19:22:56 Yeah, I was trying to avoid defining yet another n
+ List<NewTabPageListItem> snippets = (List<NewTabPageListItem>) data;
+ mDataAdapter.setSnippetListItems(snippets);
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698