OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.ntp.cards; | 5 package org.chromium.chrome.browser.ntp.cards; |
6 | 6 |
7 import android.support.annotation.IntDef; | 7 import android.support.annotation.IntDef; |
8 import android.view.View; | 8 import android.view.View; |
9 | 9 |
10 import org.chromium.base.VisibleForTesting; | 10 import org.chromium.base.VisibleForTesting; |
11 import org.chromium.chrome.R; | 11 import org.chromium.chrome.R; |
12 import org.chromium.chrome.browser.ntp.ContextMenuManager; | 12 import org.chromium.chrome.browser.ntp.ContextMenuManager; |
13 import org.chromium.chrome.browser.ntp.ContextMenuManager.ContextMenuItemId; | 13 import org.chromium.chrome.browser.ntp.ContextMenuManager.ContextMenuItemId; |
14 import org.chromium.chrome.browser.ntp.ContextMenuManager.Delegate; | 14 import org.chromium.chrome.browser.ntp.ContextMenuManager.Delegate; |
15 import org.chromium.chrome.browser.ntp.NewTabPageView.NewTabPageManager; | |
16 import org.chromium.chrome.browser.ntp.UiConfig; | 15 import org.chromium.chrome.browser.ntp.UiConfig; |
17 import org.chromium.chrome.browser.ntp.snippets.CategoryInt; | 16 import org.chromium.chrome.browser.ntp.snippets.CategoryInt; |
18 import org.chromium.chrome.browser.ntp.snippets.SnippetsConfig; | 17 import org.chromium.chrome.browser.ntp.snippets.SnippetsConfig; |
19 import org.chromium.chrome.browser.suggestions.SuggestionsRanker; | 18 import org.chromium.chrome.browser.suggestions.SuggestionsRanker; |
| 19 import org.chromium.chrome.browser.suggestions.SuggestionsUiDelegate; |
20 | 20 |
21 import java.lang.annotation.Retention; | 21 import java.lang.annotation.Retention; |
22 import java.lang.annotation.RetentionPolicy; | 22 import java.lang.annotation.RetentionPolicy; |
23 | 23 |
24 /** | 24 /** |
25 * Item that allows the user to perform an action on the NTP. | 25 * Item that allows the user to perform an action on the NTP. |
26 * Note: Use {@link #refreshVisibility()} to update the visibility of the button
instead of calling | 26 * Note: Use {@link #refreshVisibility()} to update the visibility of the button
instead of calling |
27 * {@link #setVisible(boolean)} directly. | 27 * {@link #setVisible(boolean)} directly. |
28 */ | 28 */ |
29 public class ActionItem extends OptionalLeaf { | 29 public class ActionItem extends OptionalLeaf { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 | 75 |
76 public void setPerSectionRank(int perSectionRank) { | 76 public void setPerSectionRank(int perSectionRank) { |
77 mPerSectionRank = perSectionRank; | 77 mPerSectionRank = perSectionRank; |
78 } | 78 } |
79 | 79 |
80 public int getPerSectionRank() { | 80 public int getPerSectionRank() { |
81 return mPerSectionRank; | 81 return mPerSectionRank; |
82 } | 82 } |
83 | 83 |
84 @VisibleForTesting | 84 @VisibleForTesting |
85 void performAction(NewTabPageManager manager) { | 85 void performAction(SuggestionsUiDelegate uiDelegate) { |
86 manager.getSuggestionsMetricsReporter().onMoreButtonClicked(this); | 86 uiDelegate.getMetricsReporter().onMoreButtonClicked(this); |
87 | 87 |
88 switch (mCurrentAction) { | 88 switch (mCurrentAction) { |
89 case ACTION_VIEW_ALL: | 89 case ACTION_VIEW_ALL: |
90 mCategoryInfo.performViewAllAction(manager); | 90 mCategoryInfo.performViewAllAction(uiDelegate.getNavigationDeleg
ate()); |
91 return; | 91 return; |
92 case ACTION_FETCH_MORE: | 92 case ACTION_FETCH_MORE: |
93 case ACTION_RELOAD: | 93 case ACTION_RELOAD: |
94 manager.getSuggestionsSource().fetchSuggestions( | 94 uiDelegate.getSuggestionsSource().fetchSuggestions( |
95 mCategoryInfo.getCategory(), mParentSection.getDisplayed
SuggestionIds()); | 95 mCategoryInfo.getCategory(), mParentSection.getDisplayed
SuggestionIds()); |
96 mParentSection.onFetchStarted(); | 96 mParentSection.onFetchStarted(); |
97 return; | 97 return; |
98 case ACTION_NONE: | 98 case ACTION_NONE: |
99 default: | 99 default: |
100 // Should never be reached. | 100 // Should never be reached. |
101 assert false; | 101 assert false; |
102 } | 102 } |
103 } | 103 } |
104 | 104 |
105 @Action | 105 @Action |
106 private int findAppropriateAction() { | 106 private int findAppropriateAction() { |
107 boolean hasSuggestions = mParentSection.hasSuggestions(); | 107 boolean hasSuggestions = mParentSection.hasSuggestions(); |
108 if (mCategoryInfo.hasViewAllAction()) return ACTION_VIEW_ALL; | 108 if (mCategoryInfo.hasViewAllAction()) return ACTION_VIEW_ALL; |
109 if (hasSuggestions && mCategoryInfo.hasFetchMoreAction()) return ACTION_
FETCH_MORE; | 109 if (hasSuggestions && mCategoryInfo.hasFetchMoreAction()) return ACTION_
FETCH_MORE; |
110 if (!hasSuggestions && mCategoryInfo.hasReloadAction()) return ACTION_RE
LOAD; | 110 if (!hasSuggestions && mCategoryInfo.hasReloadAction()) return ACTION_RE
LOAD; |
111 return ACTION_NONE; | 111 return ACTION_NONE; |
112 } | 112 } |
113 | 113 |
114 /** ViewHolder associated to {@link ItemViewType#ACTION}. */ | 114 /** ViewHolder associated to {@link ItemViewType#ACTION}. */ |
115 public static class ViewHolder extends CardViewHolder implements ContextMenu
Manager.Delegate { | 115 public static class ViewHolder extends CardViewHolder implements ContextMenu
Manager.Delegate { |
116 private ActionItem mActionListItem; | 116 private ActionItem mActionListItem; |
117 | 117 |
118 public ViewHolder(final NewTabPageRecyclerView recyclerView, | 118 public ViewHolder(final NewTabPageRecyclerView recyclerView, |
119 final NewTabPageManager manager, UiConfig uiConfig) { | 119 ContextMenuManager contextMenuManager, final SuggestionsUiDelega
te uiDelegate, |
120 super(R.layout.new_tab_page_action_card, recyclerView, uiConfig, man
ager); | 120 UiConfig uiConfig) { |
| 121 super(R.layout.new_tab_page_action_card, recyclerView, uiConfig, con
textMenuManager); |
121 | 122 |
122 itemView.findViewById(R.id.action_button) | 123 itemView.findViewById(R.id.action_button) |
123 .setOnClickListener(new View.OnClickListener() { | 124 .setOnClickListener(new View.OnClickListener() { |
124 @Override | 125 @Override |
125 public void onClick(View v) { | 126 public void onClick(View v) { |
126 mActionListItem.performAction(manager); | 127 mActionListItem.performAction(uiDelegate); |
127 } | 128 } |
128 }); | 129 }); |
129 | 130 |
130 new ImpressionTracker(itemView, new ImpressionTracker.Listener() { | 131 new ImpressionTracker(itemView, new ImpressionTracker.Listener() { |
131 @Override | 132 @Override |
132 public void onImpression() { | 133 public void onImpression() { |
133 if (mActionListItem != null && !mActionListItem.mImpressionT
racked) { | 134 if (mActionListItem != null && !mActionListItem.mImpressionT
racked) { |
134 mActionListItem.mImpressionTracked = true; | 135 mActionListItem.mImpressionTracked = true; |
135 manager.getSuggestionsMetricsReporter().onMoreButtonShow
n(mActionListItem); | 136 uiDelegate.getMetricsReporter().onMoreButtonShown(mActio
nListItem); |
136 } | 137 } |
137 } | 138 } |
138 }); | 139 }); |
139 } | 140 } |
140 | 141 |
141 @Override | 142 @Override |
142 public boolean isDismissable() { | 143 public boolean isDismissable() { |
143 return SnippetsConfig.isSectionDismissalEnabled() | 144 return SnippetsConfig.isSectionDismissalEnabled() |
144 && !mActionListItem.mParentSection.hasSuggestions(); | 145 && !mActionListItem.mParentSection.hasSuggestions(); |
145 } | 146 } |
(...skipping 25 matching lines...) Expand all Loading... |
171 | 172 |
172 @Override | 173 @Override |
173 public void onContextMenuCreated() {} | 174 public void onContextMenuCreated() {} |
174 | 175 |
175 public void onBindViewHolder(ActionItem item) { | 176 public void onBindViewHolder(ActionItem item) { |
176 super.onBindViewHolder(); | 177 super.onBindViewHolder(); |
177 mActionListItem = item; | 178 mActionListItem = item; |
178 } | 179 } |
179 } | 180 } |
180 } | 181 } |
OLD | NEW |