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

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

Issue 2430743002: [Android NTP] Cache children in SuggestionsSection. (Closed)
Patch Set: review Created 4 years, 2 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 | no next file » | 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/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 48a787a86f117c290a96706c56ddbd07e128807c..ebad44ea6e30d2bf89d3dc9f47b0f2180b3a9760 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
@@ -12,13 +12,13 @@ import org.chromium.chrome.browser.ntp.snippets.SnippetArticle;
import org.chromium.chrome.browser.ntp.snippets.SnippetsBridge;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
/**
* A group of suggestions, with a header, a status card, and a progress indicator.
*/
public class SuggestionsSection extends InnerNode {
+ private final List<TreeNode> mChildren = new ArrayList<>();
private final List<SnippetArticle> mSuggestions = new ArrayList<>();
private final SectionHeader mHeader;
private final StatusItem mStatus;
@@ -32,20 +32,22 @@ public class SuggestionsSection extends InnerNode {
mCategoryInfo = info;
mMoreButton = new ActionItem(info);
mStatus = StatusItem.createNoSuggestionsItem(info);
+ resetChildren();
}
@Override
public List<TreeNode> getChildren() {
- // Note: Keep this coherent with the various notify** calls on ItemGroup.Observer
- List<TreeNode> items = new ArrayList<>();
- items.add(mHeader);
- items.addAll(mSuggestions);
+ return mChildren;
+ }
- if (mSuggestions.isEmpty()) items.add(mStatus);
- if (mCategoryInfo.hasMoreButton() || mSuggestions.isEmpty()) items.add(mMoreButton);
- if (mSuggestions.isEmpty()) items.add(mProgressIndicator);
+ private void resetChildren() {
+ mChildren.clear();
+ mChildren.add(mHeader);
+ mChildren.addAll(mSuggestions);
- return Collections.unmodifiableList(items);
+ if (mSuggestions.isEmpty()) mChildren.add(mStatus);
+ if (mCategoryInfo.hasMoreButton() || mSuggestions.isEmpty()) mChildren.add(mMoreButton);
+ if (mSuggestions.isEmpty()) mChildren.add(mProgressIndicator);
}
public void removeSuggestion(SnippetArticle suggestion) {
@@ -55,6 +57,8 @@ public class SuggestionsSection extends InnerNode {
mSuggestions.remove(removedIndex);
if (mMoreButton != null) mMoreButton.setDismissable(!hasSuggestions());
+ resetChildren();
+
// Note: Keep this coherent with getItems()
int globalRemovedIndex = removedIndex + 1; // Header has index 0 in the section.
notifyItemRemoved(globalRemovedIndex);
@@ -99,6 +103,7 @@ public class SuggestionsSection extends InnerNode {
mMoreButton.setPosition(mSuggestions.size());
mMoreButton.setDismissable(mSuggestions.isEmpty());
}
+ resetChildren();
notifySectionChanged(itemCountBefore);
}
@@ -106,6 +111,7 @@ public class SuggestionsSection extends InnerNode {
public void setStatus(@CategoryStatusEnum int status) {
int itemCountBefore = getItemCount();
setStatusInternal(status);
+ resetChildren();
notifySectionChanged(itemCountBefore);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698