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

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

Issue 2401643004: 📰 [Reland] Use the separate button style for the NoArticles status (Closed)
Patch Set: rebase 😠 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 41f1f884c5ff5d7cbfc9a5902b7cae4173f6fe29..6788fbec22f12ca3f0fde5a2001e44e4b9f9bf4a 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) {

Powered by Google App Engine
This is Rietveld 408576698