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

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

Issue 2274293002: 📰 Keep Suggestion sections in declaration order (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix render test Created 4 years, 4 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
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/SuggestionsSection.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageAdapter.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageAdapter.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageAdapter.java
index 9cdb5e68efefda2b8a56a70af0724bceb3c2a3f4..cd1486194e05fe3792de486cfd64da133ca71c68 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageAdapter.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageAdapter.java
@@ -32,9 +32,9 @@
import java.util.ArrayList;
import java.util.Collections;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import java.util.TreeMap;
/**
* A class that handles merging above the fold elements and below the fold cards into an adapter
@@ -62,7 +62,7 @@
private final SpacingItem mBottomSpacer = new SpacingItem();
/** Maps suggestion categories to sections, with stable iteration ordering. */
- private final Map<Integer, SuggestionsSection> mSections = new TreeMap<>();
+ private final Map<Integer, SuggestionsSection> mSections = new LinkedHashMap<>();
private class ItemTouchCallbacks extends ItemTouchHelper.Callback {
@Override
@@ -145,6 +145,13 @@ public NewTabPageAdapter(NewTabPageManager manager, View aboveTheFoldView,
List<SnippetArticle> suggestions =
suggestionsSource.getSuggestionsForCategory(category);
suggestionsPerCategory[i++] = suggestions.size();
+
+ // Create the new section.
+ SuggestionsCategoryInfo info = mSuggestionsSource.getCategoryInfo(category);
+ if (suggestions.isEmpty() && !info.showIfEmpty()) continue;
+ mSections.put(category, new SuggestionsSection(category, info, this));
+
+ // Add the new suggestions.
setSuggestions(category, suggestions, categoryStatus);
}
// |mNewTabPageManager| is null in some tests.
@@ -162,8 +169,11 @@ public NewTabPageAdapter(NewTabPageManager manager, View aboveTheFoldView,
@Override
public void onNewSuggestions(@CategoryInt int category) {
+ // We never want to add suggestions from unknown categories.
+ if (!mSections.containsKey(category)) return;
+
// We never want to refresh the suggestions if we already have some content.
- if (mSections.containsKey(category) && mSections.get(category).hasSuggestions()) return;
+ if (mSections.get(category).hasSuggestions()) return;
// The status may have changed while the suggestions were loading, perhaps they should not
// be displayed any more.
@@ -316,13 +326,6 @@ private void setSuggestions(@CategoryInt int category, List<SnippetArticle> sugg
for (SnippetArticle suggestion : suggestions) {
suggestion.mGlobalPosition = globalPositionOffset + suggestion.mPosition;
}
- // Add the new suggestions.
- if (!mSections.containsKey(category)) {
- SuggestionsCategoryInfo info = mSuggestionsSource.getCategoryInfo(category);
- if (suggestions.isEmpty() && !info.showIfEmpty()) return;
-
- mSections.put(category, new SuggestionsSection(category, info, this));
- }
mSections.get(category).setSuggestions(suggestions, status);
}
@@ -408,6 +411,11 @@ ItemGroup getGroup(int itemPosition) {
return null;
}
+ @VisibleForTesting
+ List<ItemGroup> getGroups() {
+ return Collections.unmodifiableList(mGroups);
+ }
+
private int getGroupPositionOffset(ItemGroup group) {
int positionOffset = 0;
for (ItemGroup candidateGroup : mGroups) {
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/SuggestionsSection.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698