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

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

Issue 2860463002: [Suggestions] Remove TreeNode.getSuggestionAt() in favor of a visitor. (Closed)
Patch Set: fix test Created 3 years, 7 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
index 85540c7dfd12a4cb3bf70173fee29b7ce0d345b6..3fd17f42ef0e882b3c4e1ede7af97f5f589ab360 100644
--- 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
@@ -9,6 +9,7 @@ import android.support.annotation.Nullable;
import org.chromium.base.Callback;
import org.chromium.base.Log;
+import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.browser.ntp.NewTabPageUma;
import org.chromium.chrome.browser.ntp.snippets.CategoryInt;
import org.chromium.chrome.browser.ntp.snippets.CategoryStatus;
@@ -101,7 +102,8 @@ public class SuggestionsSection extends InnerNode {
mStatus.setVisible(!hasSuggestions());
}
- private static class SuggestionsList extends ChildNode implements Iterable<SnippetArticle> {
+ @VisibleForTesting
+ static class SuggestionsList extends ChildNode implements Iterable<SnippetArticle> {
private final List<SnippetArticle> mSuggestions = new ArrayList<>();
// TODO(crbug.com/677672): Replace by SuggestionSource when it handles destruction.
@@ -137,7 +139,6 @@ public class SuggestionsSection extends InnerNode {
((SnippetArticleViewHolder) holder).onBindViewHolder(suggestion, mCategoryInfo);
}
- @Override
public SnippetArticle getSuggestionAt(int position) {
return mSuggestions.get(position);
}
@@ -181,6 +182,13 @@ public class SuggestionsSection extends InnerNode {
}
@Override
+ public void visitItems(NodeVisitor visitor) {
+ for (SnippetArticle suggestion : mSuggestions) {
+ visitor.visitSuggestion(suggestion);
+ }
+ }
+
+ @Override
public Set<Integer> getItemDismissalGroup(int position) {
return Collections.singleton(position);
}
@@ -323,7 +331,7 @@ public class SuggestionsSection extends InnerNode {
}
}
- public boolean hasSuggestions() {
+ private boolean hasSuggestions() {
return mSuggestionsList.getItemCount() != 0;
}
@@ -525,6 +533,10 @@ public class SuggestionsSection extends InnerNode {
return mHeader;
}
+ SuggestionsList getSuggestionListForTesting() {
+ return mSuggestionsList;
+ }
+
private class OfflineModelObserver extends SuggestionsOfflineModelObserver<SnippetArticle> {
public OfflineModelObserver(OfflinePageBridge bridge) {
super(bridge);

Powered by Google App Engine
This is Rietveld 408576698