| Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageAdapter.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageAdapter.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageAdapter.java
|
| index 61285b3c01e8f6e5a16645bd3e795654449869e4..78c1b18dedbdccea7d1185e72777e1a1ccec59a3 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageAdapter.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageAdapter.java
|
| @@ -19,15 +19,13 @@ import org.chromium.chrome.browser.ntp.NewTabPageView.NewTabPageManager;
|
| import org.chromium.chrome.browser.ntp.UiConfig;
|
| import org.chromium.chrome.browser.ntp.snippets.CategoryStatus;
|
| import org.chromium.chrome.browser.ntp.snippets.CategoryStatus.CategoryStatusEnum;
|
| -import org.chromium.chrome.browser.ntp.snippets.KnownCategories;
|
| -import org.chromium.chrome.browser.ntp.snippets.KnownCategories.KnownCategoriesEnum;
|
| +import org.chromium.chrome.browser.ntp.snippets.ContentSuggestionsSource;
|
| +import org.chromium.chrome.browser.ntp.snippets.ContentSuggestionsSource.SnippetsObserver;
|
| import org.chromium.chrome.browser.ntp.snippets.SnippetArticleListItem;
|
| import org.chromium.chrome.browser.ntp.snippets.SnippetArticleViewHolder;
|
| import org.chromium.chrome.browser.ntp.snippets.SnippetHeaderListItem;
|
| import org.chromium.chrome.browser.ntp.snippets.SnippetHeaderViewHolder;
|
| import org.chromium.chrome.browser.ntp.snippets.SnippetsBridge;
|
| -import org.chromium.chrome.browser.ntp.snippets.SnippetsSource;
|
| -import org.chromium.chrome.browser.ntp.snippets.SnippetsSource.SnippetsObserver;
|
|
|
| import java.util.ArrayList;
|
| import java.util.Collections;
|
| @@ -46,7 +44,7 @@ public class NewTabPageAdapter extends Adapter<NewTabPageViewHolder> implements
|
|
|
| private final NewTabPageManager mNewTabPageManager;
|
| private final NewTabPageLayout mNewTabPageLayout;
|
| - private SnippetsSource mSnippetsSource;
|
| + private ContentSuggestionsSource mSnippetsSource;
|
| private final UiConfig mUiConfig;
|
| private final ItemTouchCallbacks mItemTouchCallbacks = new ItemTouchCallbacks();
|
| private NewTabPageRecyclerView mRecyclerView;
|
| @@ -120,17 +118,16 @@ public class NewTabPageAdapter extends Adapter<NewTabPageViewHolder> implements
|
| * @param uiConfig the NTP UI configuration, to be passed to created views.
|
| */
|
| public NewTabPageAdapter(NewTabPageManager manager, NewTabPageLayout newTabPageLayout,
|
| - SnippetsSource snippetsSource, UiConfig uiConfig) {
|
| + ContentSuggestionsSource snippetsSource, UiConfig uiConfig) {
|
| mNewTabPageManager = manager;
|
| mNewTabPageLayout = newTabPageLayout;
|
| mSnippetsSource = snippetsSource;
|
| mUiConfig = uiConfig;
|
|
|
| - // TODO(mvanouwerkerk): Do not hard code ARTICLES. Maybe do not initialize an empty
|
| - // section in the constructor.
|
| - setSuggestions(KnownCategories.ARTICLES,
|
| - Collections.<SnippetArticleListItem>emptyList(),
|
| - snippetsSource.getCategoryStatus(KnownCategories.ARTICLES));
|
| + for (int category : mSnippetsSource.getCategories()) {
|
| + setSuggestions(category, snippetsSource.getSuggestionsForCategory(category),
|
| + snippetsSource.getCategoryStatus(category));
|
| + }
|
| snippetsSource.setObserver(this);
|
| }
|
|
|
| @@ -140,8 +137,7 @@ public class NewTabPageAdapter extends Adapter<NewTabPageViewHolder> implements
|
| }
|
|
|
| @Override
|
| - public void onSuggestionsReceived(
|
| - @KnownCategoriesEnum int category, List<SnippetArticleListItem> suggestions) {
|
| + public void onNewSuggestions(int category) {
|
| // We never want to refresh the suggestions if we already have some content.
|
| if (mSections.containsKey(category) && mSections.get(category).hasSuggestions()) return;
|
|
|
| @@ -152,6 +148,9 @@ public class NewTabPageAdapter extends Adapter<NewTabPageViewHolder> implements
|
| return;
|
| }
|
|
|
| + List<SnippetArticleListItem> suggestions =
|
| + mSnippetsSource.getSuggestionsForCategory(category);
|
| +
|
| Log.d(TAG, "Received %d new suggestions for category %d.", suggestions.size(), category);
|
|
|
| // At first, there might be no suggestions available, we wait until they have been fetched.
|
| @@ -163,8 +162,7 @@ public class NewTabPageAdapter extends Adapter<NewTabPageViewHolder> implements
|
| }
|
|
|
| @Override
|
| - public void onCategoryStatusChanged(
|
| - @KnownCategoriesEnum int category, @CategoryStatusEnum int status) {
|
| + public void onCategoryStatusChanged(int category, @CategoryStatusEnum int status) {
|
| // Observers should not be registered for this state.
|
| assert status != CategoryStatus.ALL_SUGGESTIONS_EXPLICITLY_DISABLED;
|
|
|
| @@ -257,14 +255,15 @@ public class NewTabPageAdapter extends Adapter<NewTabPageViewHolder> implements
|
| SnippetsBridge.fetchSnippets(/*forceRequest=*/true);
|
| }
|
|
|
| - private void setSuggestions(@KnownCategoriesEnum int category,
|
| - List<SnippetArticleListItem> suggestions, @CategoryStatusEnum int status) {
|
| + private void setSuggestions(int category, List<SnippetArticleListItem> suggestions,
|
| + @CategoryStatusEnum int status) {
|
| mGroups.clear();
|
| mGroups.add(mAboveTheFold);
|
|
|
| if (!mSections.containsKey(category)) {
|
| - mSections.put(category,
|
| - new SuggestionsSection(suggestions, status, this));
|
| + SuggestionsCategoryInfo info = mSnippetsSource.getCategoryInfo(category);
|
| + if (info == null) return;
|
| + mSections.put(category, new SuggestionsSection(suggestions, status, info, this));
|
| } else {
|
| mSections.get(category).setSuggestions(suggestions, status, this);
|
| }
|
| @@ -297,7 +296,7 @@ public class NewTabPageAdapter extends Adapter<NewTabPageViewHolder> implements
|
| int position = itemViewHolder.getAdapterPosition();
|
| SnippetArticleListItem suggestion = (SnippetArticleListItem) getItems().get(position);
|
|
|
| - mSnippetsSource.getSnippedVisited(suggestion, new Callback<Boolean>() {
|
| + mSnippetsSource.getSuggestionVisited(suggestion, new Callback<Boolean>() {
|
| @Override
|
| public void onResult(Boolean result) {
|
| NewTabPageUma.recordSnippetAction(result
|
| @@ -306,7 +305,7 @@ public class NewTabPageAdapter extends Adapter<NewTabPageViewHolder> implements
|
| }
|
| });
|
|
|
| - mSnippetsSource.discardSnippet(suggestion);
|
| + mSnippetsSource.dismissSuggestion(suggestion);
|
| SuggestionsSection section = (SuggestionsSection) getGroup(position);
|
| section.dismissSuggestion(suggestion);
|
|
|
|
|