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

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

Issue 2463133002: 📰 Make the MORE button more configurable (Closed)
Patch Set: rebase Created 4 years, 1 month 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 | chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/Leaf.java » ('j') | 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/ActionItem.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/ActionItem.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/ActionItem.java
index dc8795f4f51c1381c18320d82423362bb61fb066..5e4bd74206326994a877d2268fde7c77b4c16a6d 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/ActionItem.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/ActionItem.java
@@ -14,32 +14,59 @@
/**
* Item that allows the user to perform an action on the NTP.
*/
-class ActionItem extends Leaf {
- private static final String TAG = "NtpCards";
-
+class ActionItem extends OptionalLeaf {
private final SuggestionsCategoryInfo mCategoryInfo;
+ private final SuggestionsSection mParentSection;
- // The position (index) of this item within its section, for logging purposes.
- private int mPosition;
private boolean mImpressionTracked = false;
- private boolean mDismissable;
- public ActionItem(SuggestionsCategoryInfo categoryInfo) {
+ public ActionItem(SuggestionsCategoryInfo categoryInfo, SuggestionsSection section) {
+ super(section);
mCategoryInfo = categoryInfo;
+ mParentSection = section;
}
@Override
- @ItemViewType
- protected int getItemViewType() {
+ public int getItemViewType() {
return ItemViewType.ACTION;
}
- public int getPosition() {
- return mPosition;
+ @Override
+ protected void onBindViewHolder(NewTabPageViewHolder holder) {
+ assert holder instanceof ViewHolder;
+ ((ViewHolder) holder).onBindViewHolder(this);
}
- public void setPosition(int position) {
- mPosition = position;
+ @Override
+ public boolean isShown() {
+ return mCategoryInfo.hasMoreButton(mParentSection.hasSuggestions());
+ }
+
+ private int getPosition() {
+ // TODO(dgn): looks dodgy. Confirm that's what we want.
+ return mParentSection.getSuggestionsCount();
+ }
+
+ private void performAction(NewTabPageManager manager, NewTabPageAdapter adapter) {
+ manager.trackSnippetCategoryActionClick(mCategoryInfo.getCategory(), getPosition());
+
+ if (mCategoryInfo.hasViewAllAction()) {
+ mCategoryInfo.performViewAllAction(manager);
+ return;
+ }
+
+ if (mCategoryInfo.hasMoreAction() && mParentSection.hasSuggestions()) {
+ // TODO(dgn): Implement fetch more. https://crbug.com/634892
+ throw new UnsupportedOperationException("Fetch more not implemented yet");
+ }
+
+ if (mCategoryInfo.hasReloadAction()) {
+ // TODO(dgn): reload only the current section. https://crbug.com/634892
+ adapter.reloadSnippets();
+ }
+
+ // Should not be reached. Otherwise the action item was shown at an inappropriate moment.
+ assert false;
}
public static class ViewHolder extends CardViewHolder {
@@ -53,10 +80,7 @@ public ViewHolder(final NewTabPageRecyclerView recyclerView,
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- int category = mActionListItem.mCategoryInfo.getCategory();
- manager.trackSnippetCategoryActionClick(
- category, mActionListItem.mPosition);
- mActionListItem.mCategoryInfo.performEmptyStateAction(
+ mActionListItem.performAction(
manager, recyclerView.getNewTabPageAdapter());
}
});
@@ -68,7 +92,7 @@ public void onImpression() {
mActionListItem.mImpressionTracked = true;
manager.trackSnippetCategoryActionImpression(
mActionListItem.mCategoryInfo.getCategory(),
- mActionListItem.mPosition);
+ mActionListItem.getPosition());
}
}
});
@@ -76,24 +100,13 @@ public void onImpression() {
@Override
public boolean isDismissable() {
- return SnippetsConfig.isSectionDismissalEnabled() && mActionListItem.mDismissable;
+ return SnippetsConfig.isSectionDismissalEnabled()
+ && !mActionListItem.mParentSection.hasSuggestions();
}
public void onBindViewHolder(ActionItem item) {
super.onBindViewHolder();
-
mActionListItem = item;
}
}
-
- @Override
- protected void onBindViewHolder(NewTabPageViewHolder holder) {
- assert holder instanceof ViewHolder;
- ((ViewHolder) holder).onBindViewHolder(this);
- }
-
- /** Set whether this item can be dismissed.*/
- public void setDismissable(boolean dismissable) {
- this.mDismissable = dismissable;
- }
}
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/Leaf.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698