| 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 399edd8bae77d67ca562526a5b09b8cbfd242bc6..4d8dee5504b90f1a5b3336fba3a29941a2ba7873 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
|
| @@ -15,6 +15,7 @@ import org.chromium.chrome.browser.ntp.snippets.SectionHeader;
|
| import org.chromium.chrome.browser.ntp.snippets.SnippetArticle;
|
| import org.chromium.chrome.browser.ntp.snippets.SnippetArticleViewHolder;
|
| import org.chromium.chrome.browser.ntp.snippets.SnippetsBridge;
|
| +import org.chromium.chrome.browser.ntp.snippets.SnippetsConfig;
|
| import org.chromium.chrome.browser.ntp.snippets.SuggestionsSource;
|
| import org.chromium.chrome.browser.offlinepages.ClientId;
|
| import org.chromium.chrome.browser.offlinepages.OfflinePageBridge;
|
| @@ -24,8 +25,11 @@ import org.chromium.chrome.browser.suggestions.SuggestionsRanker;
|
| import org.chromium.chrome.browser.suggestions.SuggestionsUiDelegate;
|
|
|
| import java.util.ArrayList;
|
| +import java.util.Collections;
|
| +import java.util.HashSet;
|
| import java.util.Iterator;
|
| import java.util.List;
|
| +import java.util.Set;
|
|
|
| /**
|
| * A group of suggestions, with a header, a status card, and a progress indicator. This is
|
| @@ -34,6 +38,12 @@ import java.util.List;
|
| public class SuggestionsSection extends InnerNode {
|
| private static final String TAG = "NtpCards";
|
|
|
| + private static final Set<Integer> SECTION_DISMISSAL_GROUP = new HashSet<>(2);
|
| + {
|
| + SECTION_DISMISSAL_GROUP.add(1);
|
| + SECTION_DISMISSAL_GROUP.add(2);
|
| + }
|
| +
|
| private final Delegate mDelegate;
|
| private final SuggestionsCategoryInfo mCategoryInfo;
|
| private final OfflinePageBridge mOfflinePageBridge;
|
| @@ -127,12 +137,6 @@ public class SuggestionsSection extends InnerNode {
|
| return mSuggestions.get(position);
|
| }
|
|
|
| - @Override
|
| - public int getDismissSiblingPosDelta(int position) {
|
| - checkIndex(position);
|
| - return 0;
|
| - }
|
| -
|
| public void clear() {
|
| int itemCount = mSuggestions.size();
|
| if (itemCount == 0) return;
|
| @@ -172,6 +176,11 @@ public class SuggestionsSection extends InnerNode {
|
| }
|
|
|
| @Override
|
| + public Set<Integer> getItemDismissalGroup(int position) {
|
| + return Collections.singleton(position);
|
| + }
|
| +
|
| + @Override
|
| public void dismissItem(int position, Callback<String> itemRemovedCallback) {
|
| checkIndex(position);
|
| SuggestionsSource suggestionsSource = mUiDelegate.getSuggestionsSource();
|
| @@ -248,7 +257,7 @@ public class SuggestionsSection extends InnerNode {
|
|
|
| @Override
|
| public void dismissItem(int position, Callback<String> itemRemovedCallback) {
|
| - if (!hasSuggestions()) {
|
| + if (getSectionDismissalRange().contains(position)) {
|
| mDelegate.dismissSection(this);
|
| itemRemovedCallback.onResult(getHeaderText());
|
| return;
|
| @@ -434,23 +443,27 @@ public class SuggestionsSection extends InnerNode {
|
| }
|
|
|
| @Override
|
| - public int getDismissSiblingPosDelta(int position) {
|
| - // The only dismiss siblings we have so far are the More button and the status card.
|
| - // Exit early if there is no More button.
|
| - if (!mMoreButton.isVisible()) return 0;
|
| -
|
| - // When there are suggestions we won't have contiguous status and action items.
|
| - if (hasSuggestions()) return 0;
|
| + public Set<Integer> getItemDismissalGroup(int position) {
|
| + // The section itself can be dismissed via any of the items in the dismissal group,
|
| + // otherwise we fall back to the default implementation, which dispatches to our children.
|
| + Set<Integer> sectionDismissalRange = getSectionDismissalRange();
|
| + if (sectionDismissalRange.contains(position)) return sectionDismissalRange;
|
|
|
| - TreeNode child = getChildForPosition(position);
|
| -
|
| - // The sibling of the more button is the status card, that should be right above.
|
| - if (child == mMoreButton) return -1;
|
| + return super.getItemDismissalGroup(position);
|
| + }
|
|
|
| - // The sibling of the status card is the more button when it exists, should be right below.
|
| - if (child == mStatus) return 1;
|
| + /**
|
| + * @return The set of indices corresponding to items that can dismiss this entire section
|
| + * (as opposed to individual items in it).
|
| + */
|
| + private Set<Integer> getSectionDismissalRange() {
|
| + if (hasSuggestions() || !SnippetsConfig.isSectionDismissalEnabled()) {
|
| + return Collections.emptySet();
|
| + }
|
|
|
| - return 0;
|
| + assert SECTION_DISMISSAL_GROUP.contains(getStartingOffsetForChild(mStatus));
|
| + assert SECTION_DISMISSAL_GROUP.contains(getStartingOffsetForChild(mMoreButton));
|
| + return SECTION_DISMISSAL_GROUP;
|
| }
|
|
|
| public SuggestionsCategoryInfo getCategoryInfo() {
|
|
|