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

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

Issue 2196273002: Zine: support multiple sections in the ui (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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/cards/SuggestionsSection.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/SuggestionsSection.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/SuggestionsSection.java
new file mode 100644
index 0000000000000000000000000000000000000000..f6ab60b750cff5b81ecee491b9921d3f06664335
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/SuggestionsSection.java
@@ -0,0 +1,68 @@
+// 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.cards;
+
+import org.chromium.chrome.browser.ntp.snippets.SnippetArticleListItem;
+import org.chromium.chrome.browser.ntp.snippets.SnippetHeaderListItem;
+import org.chromium.chrome.browser.ntp.snippets.SuggestionsCategoryStatus;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * A group of suggestions, with a header and a status card.
+ */
+public class SuggestionsSection implements NewTabPageItemGroup {
+ private final List<NewTabPageListItem> mItems;
+ private final SnippetHeaderListItem mHeader;
+ private StatusListItem mStatus;
+
+ SuggestionsSection(List<SnippetArticleListItem> suggestions,
+ @SuggestionsCategoryStatus int status, NewTabPageAdapter adapter) {
+ mItems = new ArrayList<>();
PEConn 2016/08/01 16:26:51 Why ArrayList? The list is going to be kept fairly
Bernhard Bauer 2016/08/02 13:03:27 Plus, purely algorithmically, traversing a linked
PEConn 2016/08/02 15:45:14 Acknowledged.
+
+ // TODO(mvanouwerkerk): Pass in the header text.
+ mHeader = new SnippetHeaderListItem();
+
+ setSuggestions(suggestions, status, adapter);
+ }
+
+ @Override
+ public List<NewTabPageListItem> getItems() {
+ return mItems;
+ }
+
+ public void dismissSuggestion(SnippetArticleListItem suggestion) {
+ mItems.remove(suggestion);
+
+ if (!hasSuggestions() && !mItems.contains(mStatus)) {
+ mItems.add(mStatus);
+ mHeader.setVisible(false);
+ }
+ }
+
+ public boolean hasSuggestions() {
+ for (NewTabPageListItem item : mItems) {
PEConn 2016/08/01 16:26:51 Why do we need to search for the first SnippetArti
Bernhard Bauer 2016/08/02 13:03:27 I slightly prefer this, as it reflects the intent
PEConn 2016/08/02 15:45:14 Acknowledged.
+ if (item instanceof SnippetArticleListItem) return true;
+ }
+ return false;
+ }
+
+ public void setSuggestions(List<SnippetArticleListItem> suggestions,
+ @SuggestionsCategoryStatus int status, NewTabPageAdapter adapter) {
+ mItems.clear();
+
+ mItems.add(mHeader);
+ mHeader.setVisible(!suggestions.isEmpty());
+
+ mStatus = StatusListItem.create(status, adapter);
+
+ if (suggestions.isEmpty()) {
+ mItems.add(mStatus);
+ } else {
+ mItems.addAll(suggestions);
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698