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

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

Issue 2398463005: Revert of 📰 Use the separate button style for the NoArticles status (Closed)
Patch Set: 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
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 5263e29a98d095ce7f3354b0107adde1369a1c67..31e695dae97b62ff54281cb2ee162594e586654e 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,6 +5,7 @@
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;
@@ -21,18 +22,39 @@
public class SuggestionsSection implements ItemGroup {
private final List<SnippetArticle> mSuggestions = new ArrayList<>();
private final SectionHeader mHeader;
- private final StatusItem mStatus;
+ private 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(SuggestionsCategoryInfo info, Observer observer) {
+ 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) {
mHeader = new SectionHeader(info.getTitle());
- mCategoryInfo = info;
+ mCategory = category;
mObserver = observer;
- mMoreButton = new ActionItem(info);
- mStatus = StatusItem.createNoSuggestionsItem(info);
+
+ // 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;
+ }
}
@Override
@@ -43,7 +65,7 @@
items.addAll(mSuggestions);
if (mSuggestions.isEmpty()) items.add(mStatus);
- if (mCategoryInfo.hasMoreButton() || mSuggestions.isEmpty()) items.add(mMoreButton);
+ if (mMoreButton != null) items.add(mMoreButton);
if (mSuggestions.isEmpty()) items.add(mProgressIndicator);
return Collections.unmodifiableList(items);
@@ -60,14 +82,12 @@
int globalRemovedIndex = removedIndex + 1; // Header has index 0 in the section.
mObserver.notifyItemRemoved(this, globalRemovedIndex);
- // 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.
+ 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));
}
- mObserver.notifyItemInserted(this, globalRemovedIndex + 2); // Progress indicator.
}
public void removeSuggestionById(String idWithinCategory) {
@@ -98,7 +118,6 @@
if (mMoreButton != null) {
mMoreButton.setPosition(mSuggestions.size());
- mMoreButton.setDismissable(mSuggestions.isEmpty());
}
mObserver.notifyGroupChanged(this, itemCountBefore, getItems().size());
}
@@ -111,14 +130,15 @@
}
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 mCategoryInfo.getCategory();
+ return mCategory;
}
private void copyThumbnails(List<SnippetArticle> suggestions) {

Powered by Google App Engine
This is Rietveld 408576698