| 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 31e695dae97b62ff54281cb2ee162594e586654e..5263e29a98d095ce7f3354b0107adde1369a1c67 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
|
| @@ -5,7 +5,6 @@
|
| package org.chromium.chrome.browser.ntp.cards;
|
|
|
| import org.chromium.base.VisibleForTesting;
|
| -import org.chromium.chrome.browser.ntp.cards.StatusItem.ActionDelegate;
|
| import org.chromium.chrome.browser.ntp.snippets.CategoryInt;
|
| import org.chromium.chrome.browser.ntp.snippets.CategoryStatus.CategoryStatusEnum;
|
| import org.chromium.chrome.browser.ntp.snippets.SectionHeader;
|
| @@ -22,39 +21,18 @@
|
| public class SuggestionsSection implements ItemGroup {
|
| private final List<SnippetArticle> mSuggestions = new ArrayList<>();
|
| private final SectionHeader mHeader;
|
| - private StatusItem mStatus;
|
| + private final StatusItem mStatus;
|
| private final ProgressItem mProgressIndicator = new ProgressItem();
|
| - private final ActionDelegate mActionDelegate;
|
| private final ActionItem mMoreButton;
|
| - @CategoryInt
|
| - private final int mCategory;
|
| private final Observer mObserver;
|
| + private final SuggestionsCategoryInfo mCategoryInfo;
|
|
|
| - public SuggestionsSection(@CategoryInt int category, SuggestionsCategoryInfo info,
|
| - final NewTabPageAdapter adapter) {
|
| - this(category, info, adapter, new ActionDelegate() {
|
| - @Override
|
| - public void onButtonTapped() {
|
| - adapter.reloadSnippets();
|
| - }
|
| - });
|
| - }
|
| -
|
| - @VisibleForTesting
|
| - SuggestionsSection(@CategoryInt int category, SuggestionsCategoryInfo info, Observer observer,
|
| - ActionDelegate actionDelegate) {
|
| + public SuggestionsSection(SuggestionsCategoryInfo info, Observer observer) {
|
| mHeader = new SectionHeader(info.getTitle());
|
| - mCategory = category;
|
| + mCategoryInfo = info;
|
| mObserver = observer;
|
| -
|
| - // TODO(dgn): Properly define strings, actions, etc. for each section and category type.
|
| - if (info.hasMoreButton()) {
|
| - mMoreButton = new ActionItem(category);
|
| - mActionDelegate = null;
|
| - } else {
|
| - mMoreButton = null;
|
| - mActionDelegate = actionDelegate;
|
| - }
|
| + mMoreButton = new ActionItem(info);
|
| + mStatus = StatusItem.createNoSuggestionsItem(info);
|
| }
|
|
|
| @Override
|
| @@ -65,7 +43,7 @@ public void onButtonTapped() {
|
| items.addAll(mSuggestions);
|
|
|
| if (mSuggestions.isEmpty()) items.add(mStatus);
|
| - if (mMoreButton != null) items.add(mMoreButton);
|
| + if (mCategoryInfo.hasMoreButton() || mSuggestions.isEmpty()) items.add(mMoreButton);
|
| if (mSuggestions.isEmpty()) items.add(mProgressIndicator);
|
|
|
| return Collections.unmodifiableList(items);
|
| @@ -82,12 +60,14 @@ public void removeSuggestion(SnippetArticle suggestion) {
|
| int globalRemovedIndex = removedIndex + 1; // Header has index 0 in the section.
|
| mObserver.notifyItemRemoved(this, globalRemovedIndex);
|
|
|
| - if (!hasSuggestions()) {
|
| - // When the last suggestion is removed, we insert other items to display the status,
|
| - // notify about them too.
|
| - mObserver.notifyItemInserted(this, globalRemovedIndex);
|
| - mObserver.notifyItemInserted(this, globalRemovedIndex + (mMoreButton == null ? 1 : 2));
|
| + // If we still have some suggestions, we are done. Otherwise, we'll have to notify about the
|
| + // status-related items that are now present.
|
| + if (hasSuggestions()) return;
|
| + mObserver.notifyItemInserted(this, globalRemovedIndex); // Status card.
|
| + if (!mCategoryInfo.hasMoreButton()) {
|
| + mObserver.notifyItemInserted(this, globalRemovedIndex + 1); // Action card.
|
| }
|
| + mObserver.notifyItemInserted(this, globalRemovedIndex + 2); // Progress indicator.
|
| }
|
|
|
| public void removeSuggestionById(String idWithinCategory) {
|
| @@ -118,6 +98,7 @@ public void setSuggestions(List<SnippetArticle> suggestions, @CategoryStatusEnum
|
|
|
| if (mMoreButton != null) {
|
| mMoreButton.setPosition(mSuggestions.size());
|
| + mMoreButton.setDismissable(mSuggestions.isEmpty());
|
| }
|
| mObserver.notifyGroupChanged(this, itemCountBefore, getItems().size());
|
| }
|
| @@ -130,15 +111,14 @@ public void setStatus(@CategoryStatusEnum int status) {
|
| }
|
|
|
| private void setStatusInternal(@CategoryStatusEnum int status) {
|
| - mStatus = StatusItem.create(status, mActionDelegate);
|
| -
|
| if (!SnippetsBridge.isCategoryStatusAvailable(status)) mSuggestions.clear();
|
|
|
| mProgressIndicator.setVisible(SnippetsBridge.isCategoryLoading(status));
|
| }
|
|
|
| + @CategoryInt
|
| public int getCategory() {
|
| - return mCategory;
|
| + return mCategoryInfo.getCategory();
|
| }
|
|
|
| private void copyThumbnails(List<SnippetArticle> suggestions) {
|
|
|