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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageAdapter.java

Issue 2623993007: 🏠 Extract the ContentSuggestionManager interface from NTP (Closed)
Patch Set: aaaand rebase again Created 3 years, 11 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 unified diff | Download patch
OLDNEW
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.Nullable; 7 import android.support.annotation.Nullable;
8 import android.support.v7.widget.RecyclerView; 8 import android.support.v7.widget.RecyclerView;
9 import android.support.v7.widget.RecyclerView.Adapter; 9 import android.support.v7.widget.RecyclerView.Adapter;
10 import android.support.v7.widget.RecyclerView.ViewHolder; 10 import android.support.v7.widget.RecyclerView.ViewHolder;
11 import android.view.View; 11 import android.view.View;
12 import android.view.ViewGroup; 12 import android.view.ViewGroup;
13 13
14 import org.chromium.base.Callback; 14 import org.chromium.base.Callback;
15 import org.chromium.base.VisibleForTesting; 15 import org.chromium.base.VisibleForTesting;
16 import org.chromium.chrome.browser.ntp.NewTabPageView.NewTabPageManager; 16 import org.chromium.chrome.browser.ntp.ContextMenuManager;
17 import org.chromium.chrome.browser.ntp.UiConfig; 17 import org.chromium.chrome.browser.ntp.UiConfig;
18 import org.chromium.chrome.browser.ntp.snippets.SectionHeaderViewHolder; 18 import org.chromium.chrome.browser.ntp.snippets.SectionHeaderViewHolder;
19 import org.chromium.chrome.browser.ntp.snippets.SnippetArticle; 19 import org.chromium.chrome.browser.ntp.snippets.SnippetArticle;
20 import org.chromium.chrome.browser.ntp.snippets.SnippetArticleViewHolder; 20 import org.chromium.chrome.browser.ntp.snippets.SnippetArticleViewHolder;
21 import org.chromium.chrome.browser.offlinepages.OfflinePageBridge; 21 import org.chromium.chrome.browser.offlinepages.OfflinePageBridge;
22 import org.chromium.chrome.browser.suggestions.SuggestionsUiDelegate;
22 23
23 import java.util.Collections; 24 import java.util.Collections;
24 import java.util.List; 25 import java.util.List;
25 26
26 /** 27 /**
27 * A class that handles merging above the fold elements and below the fold cards into an adapter 28 * A class that handles merging above the fold elements and below the fold cards into an adapter
28 * that will be used to back the NTP RecyclerView. The first element in the adap ter should always be 29 * that will be used to back the NTP RecyclerView. The first element in the adap ter should always be
29 * the above-the-fold view (containing the logo, search box, and most visited ti les) and subsequent 30 * the above-the-fold view (containing the logo, search box, and most visited ti les) and subsequent
30 * elements will be the cards shown to the user 31 * elements will be the cards shown to the user
31 */ 32 */
32 public class NewTabPageAdapter extends Adapter<NewTabPageViewHolder> implements NodeParent { 33 public class NewTabPageAdapter extends Adapter<NewTabPageViewHolder> implements NodeParent {
33 private final NewTabPageManager mNewTabPageManager; 34 private final SuggestionsUiDelegate mUiDelegate;
35 private final ContextMenuManager mContextMenuManager;
36
34 @Nullable 37 @Nullable
35 private final View mAboveTheFoldView; 38 private final View mAboveTheFoldView;
36 private final UiConfig mUiConfig; 39 private final UiConfig mUiConfig;
37 private NewTabPageRecyclerView mRecyclerView; 40 private NewTabPageRecyclerView mRecyclerView;
38 41
39 private final InnerNode mRoot; 42 private final InnerNode mRoot;
40 43
41 @Nullable 44 @Nullable
42 private final AboveTheFoldItem mAboveTheFold; 45 private final AboveTheFoldItem mAboveTheFold;
43 private final SectionList mSections; 46 private final SectionList mSections;
44 private final SignInPromo mSigninPromo; 47 private final SignInPromo mSigninPromo;
45 private final AllDismissedItem mAllDismissed; 48 private final AllDismissedItem mAllDismissed;
46 private final Footer mFooter; 49 private final Footer mFooter;
47 private final SpacingItem mBottomSpacer; 50 private final SpacingItem mBottomSpacer;
48 51
49 /** 52 /**
50 * Creates the adapter that will manage all the cards to display on the NTP. 53 * Creates the adapter that will manage all the cards to display on the NTP.
51 * 54 * @param uiDelegate used to interact with the rest of the system.
52 * @param manager the NewTabPageManager to use to interact with the rest of the system.
53 * @param aboveTheFoldView the layout encapsulating all the above-the-fold e lements 55 * @param aboveTheFoldView the layout encapsulating all the above-the-fold e lements
54 * (logo, search box, most visited tiles), or null if only suggestio ns should 56 * (logo, search box, most visited tiles), or null if only suggestio ns should
55 * be displayed. 57 * be displayed.
56 * @param uiConfig the NTP UI configuration, to be passed to created views. 58 * @param uiConfig the NTP UI configuration, to be passed to created views.
57 * @param offlinePageBridge the OfflinePageBridge used to determine if artic les are available 59 * @param offlinePageBridge used to determine if articles are available.
58 * offline. 60 * @param contextMenuManager used to build context menus.
59 */ 61 */
60 public NewTabPageAdapter(NewTabPageManager manager, @Nullable View aboveTheF oldView, 62 public NewTabPageAdapter(SuggestionsUiDelegate uiDelegate, @Nullable View ab oveTheFoldView,
61 UiConfig uiConfig, OfflinePageBridge offlinePageBridge) { 63 UiConfig uiConfig, OfflinePageBridge offlinePageBridge,
62 mNewTabPageManager = manager; 64 ContextMenuManager contextMenuManager) {
65 mUiDelegate = uiDelegate;
66 mContextMenuManager = contextMenuManager;
67
63 mAboveTheFoldView = aboveTheFoldView; 68 mAboveTheFoldView = aboveTheFoldView;
64 mUiConfig = uiConfig; 69 mUiConfig = uiConfig;
65 mRoot = new InnerNode(); 70 mRoot = new InnerNode();
66 71
67 mSections = new SectionList(mNewTabPageManager, offlinePageBridge); 72 mSections = new SectionList(mUiDelegate, offlinePageBridge);
68 mSigninPromo = new SignInPromo(mNewTabPageManager); 73 mSigninPromo = new SignInPromo(mUiDelegate);
69 mAllDismissed = new AllDismissedItem(); 74 mAllDismissed = new AllDismissedItem();
70 mFooter = new Footer(); 75 mFooter = new Footer();
71 76
72 if (mAboveTheFoldView == null) { 77 if (mAboveTheFoldView == null) {
73 mAboveTheFold = null; 78 mAboveTheFold = null;
74 } else { 79 } else {
75 mAboveTheFold = new AboveTheFoldItem(); 80 mAboveTheFold = new AboveTheFoldItem();
76 mRoot.addChild(mAboveTheFold); 81 mRoot.addChild(mAboveTheFold);
77 } 82 }
78 mRoot.addChildren(mSections, mSigninPromo, mAllDismissed, mFooter); 83 mRoot.addChildren(mSections, mSigninPromo, mAllDismissed, mFooter);
(...skipping 19 matching lines...) Expand all
98 assert parent == mRecyclerView; 103 assert parent == mRecyclerView;
99 104
100 switch (viewType) { 105 switch (viewType) {
101 case ItemViewType.ABOVE_THE_FOLD: 106 case ItemViewType.ABOVE_THE_FOLD:
102 return new NewTabPageViewHolder(mAboveTheFoldView); 107 return new NewTabPageViewHolder(mAboveTheFoldView);
103 108
104 case ItemViewType.HEADER: 109 case ItemViewType.HEADER:
105 return new SectionHeaderViewHolder(mRecyclerView, mUiConfig); 110 return new SectionHeaderViewHolder(mRecyclerView, mUiConfig);
106 111
107 case ItemViewType.SNIPPET: 112 case ItemViewType.SNIPPET:
108 return new SnippetArticleViewHolder(mRecyclerView, mNewTabPageMa nager, mUiConfig); 113 return new SnippetArticleViewHolder(
114 mRecyclerView, mContextMenuManager, mUiDelegate, mUiConf ig);
109 115
110 case ItemViewType.SPACING: 116 case ItemViewType.SPACING:
111 return new NewTabPageViewHolder(SpacingItem.createView(parent)); 117 return new NewTabPageViewHolder(SpacingItem.createView(parent));
112 118
113 case ItemViewType.STATUS: 119 case ItemViewType.STATUS:
114 return new StatusCardViewHolder(mRecyclerView, mNewTabPageManage r, mUiConfig); 120 return new StatusCardViewHolder(mRecyclerView, mContextMenuManag er, mUiConfig);
115 121
116 case ItemViewType.PROGRESS: 122 case ItemViewType.PROGRESS:
117 return new ProgressViewHolder(mRecyclerView); 123 return new ProgressViewHolder(mRecyclerView);
118 124
119 case ItemViewType.ACTION: 125 case ItemViewType.ACTION:
120 return new ActionItem.ViewHolder(mRecyclerView, mNewTabPageManag er, mUiConfig); 126 return new ActionItem.ViewHolder(
127 mRecyclerView, mContextMenuManager, mUiDelegate, mUiConf ig);
121 128
122 case ItemViewType.PROMO: 129 case ItemViewType.PROMO:
123 return new SignInPromo.ViewHolder(mRecyclerView, mNewTabPageMana ger, mUiConfig); 130 return new SignInPromo.ViewHolder(mRecyclerView, mContextMenuMan ager, mUiConfig);
124 131
125 case ItemViewType.FOOTER: 132 case ItemViewType.FOOTER:
126 return new Footer.ViewHolder(mRecyclerView, mNewTabPageManager); 133 return new Footer.ViewHolder(mRecyclerView, mUiDelegate.getNavig ationDelegate());
127 134
128 case ItemViewType.ALL_DISMISSED: 135 case ItemViewType.ALL_DISMISSED:
129 return new AllDismissedItem.ViewHolder(mRecyclerView, mSections) ; 136 return new AllDismissedItem.ViewHolder(mRecyclerView, mSections) ;
130 } 137 }
131 138
132 assert false : viewType; 139 assert false : viewType;
133 return null; 140 return null;
134 } 141 }
135 142
136 @Override 143 @Override
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 } 270 }
264 271
265 SectionList getSectionListForTesting() { 272 SectionList getSectionListForTesting() {
266 return mSections; 273 return mSections;
267 } 274 }
268 275
269 InnerNode getRootForTesting() { 276 InnerNode getRootForTesting() {
270 return mRoot; 277 return mRoot;
271 } 278 }
272 } 279 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698