| 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..8aaa9eb31b43c98650db15af85b409ee967a0681 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
|
| @@ -9,37 +9,76 @@
|
| import org.chromium.chrome.R;
|
| import org.chromium.chrome.browser.ntp.NewTabPageView.NewTabPageManager;
|
| import org.chromium.chrome.browser.ntp.UiConfig;
|
| +import org.chromium.chrome.browser.ntp.snippets.SnippetArticle;
|
| import org.chromium.chrome.browser.ntp.snippets.SnippetsConfig;
|
|
|
| /**
|
| * 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;
|
| + private final NewTabPageManager mNewTabPageManager;
|
|
|
| - // 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,
|
| + NewTabPageManager manager) {
|
| + super(section, true);
|
| mCategoryInfo = categoryInfo;
|
| + mParentSection = section;
|
| + mNewTabPageManager = manager;
|
| }
|
|
|
| @Override
|
| - @ItemViewType
|
| - protected int getItemViewType() {
|
| + public int getItemViewType() {
|
| return ItemViewType.ACTION;
|
| }
|
|
|
| - public int getPosition() {
|
| - return mPosition;
|
| + @Override
|
| + public SnippetArticle getSuggestionAt(int position) {
|
| + return null;
|
| }
|
|
|
| - public void setPosition(int position) {
|
| - mPosition = position;
|
| + @Override
|
| + public int getDismissSiblingPosDelta(int position) {
|
| + return 0;
|
| + }
|
| +
|
| + @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();
|
| + }
|
| +
|
| + @Override
|
| + public void onImpression() {
|
| + mNewTabPageManager.trackSnippetCategoryActionImpression(
|
| + mCategoryInfo.getCategory(), getPosition());
|
| + }
|
| +
|
| + 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,35 +92,20 @@ 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());
|
| }
|
| });
|
| -
|
| - new ImpressionTracker(itemView, new ImpressionTracker.Listener() {
|
| - @Override
|
| - public void onImpression() {
|
| - if (mActionListItem != null && !mActionListItem.mImpressionTracked) {
|
| - mActionListItem.mImpressionTracked = true;
|
| - manager.trackSnippetCategoryActionImpression(
|
| - mActionListItem.mCategoryInfo.getCategory(),
|
| - mActionListItem.mPosition);
|
| - }
|
| - }
|
| - });
|
| }
|
|
|
| @Override
|
| public boolean isDismissable() {
|
| - return SnippetsConfig.isSectionDismissalEnabled() && mActionListItem.mDismissable;
|
| + return SnippetsConfig.isSectionDismissalEnabled()
|
| + && !mActionListItem.mParentSection.hasSuggestions();
|
| }
|
|
|
| public void onBindViewHolder(ActionItem item) {
|
| super.onBindViewHolder();
|
| -
|
| mActionListItem = item;
|
| }
|
| }
|
| @@ -91,9 +115,4 @@ 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;
|
| - }
|
| }
|
|
|