OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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.suggestions; | 5 package org.chromium.chrome.browser.suggestions; |
6 | 6 |
7 import android.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
8 import android.support.v7.widget.RecyclerView; | 8 import android.support.v7.widget.RecyclerView; |
9 import android.support.v7.widget.RecyclerView.OnScrollListener; | 9 import android.support.v7.widget.RecyclerView.OnScrollListener; |
10 import android.view.LayoutInflater; | 10 import android.view.LayoutInflater; |
11 import android.view.MotionEvent; | 11 import android.view.MotionEvent; |
12 import android.view.View; | 12 import android.view.View; |
13 | 13 |
14 import org.chromium.base.ApiCompatibilityUtils; | 14 import org.chromium.base.ApiCompatibilityUtils; |
| 15 import org.chromium.base.ReferencePool; |
15 import org.chromium.chrome.R; | 16 import org.chromium.chrome.R; |
16 import org.chromium.chrome.browser.ChromeActivity; | 17 import org.chromium.chrome.browser.ChromeActivity; |
17 import org.chromium.chrome.browser.NativePageHost; | 18 import org.chromium.chrome.browser.NativePageHost; |
18 import org.chromium.chrome.browser.ntp.ContextMenuManager; | 19 import org.chromium.chrome.browser.ntp.ContextMenuManager; |
19 import org.chromium.chrome.browser.ntp.ContextMenuManager.TouchEnabledDelegate; | 20 import org.chromium.chrome.browser.ntp.ContextMenuManager.TouchEnabledDelegate; |
20 import org.chromium.chrome.browser.ntp.cards.NewTabPageAdapter; | 21 import org.chromium.chrome.browser.ntp.cards.NewTabPageAdapter; |
21 import org.chromium.chrome.browser.ntp.snippets.SnippetsBridge; | 22 import org.chromium.chrome.browser.ntp.snippets.SnippetsBridge; |
22 import org.chromium.chrome.browser.ntp.snippets.SuggestionsSource; | 23 import org.chromium.chrome.browser.ntp.snippets.SuggestionsSource; |
23 import org.chromium.chrome.browser.offlinepages.OfflinePageBridge; | 24 import org.chromium.chrome.browser.offlinepages.OfflinePageBridge; |
24 import org.chromium.chrome.browser.omnibox.LocationBar; | 25 import org.chromium.chrome.browser.omnibox.LocationBar; |
(...skipping 27 matching lines...) Expand all Loading... |
52 private final BottomSheet mBottomSheet; | 53 private final BottomSheet mBottomSheet; |
53 private final BottomSheetObserver mBottomSheetObserver; | 54 private final BottomSheetObserver mBottomSheetObserver; |
54 | 55 |
55 public SuggestionsBottomSheetContent(final ChromeActivity activity, final Bo
ttomSheet sheet, | 56 public SuggestionsBottomSheetContent(final ChromeActivity activity, final Bo
ttomSheet sheet, |
56 TabModelSelector tabModelSelector, SnackbarManager snackbarManager)
{ | 57 TabModelSelector tabModelSelector, SnackbarManager snackbarManager)
{ |
57 Profile profile = Profile.getLastUsedProfile(); | 58 Profile profile = Profile.getLastUsedProfile(); |
58 SuggestionsNavigationDelegate navigationDelegate = | 59 SuggestionsNavigationDelegate navigationDelegate = |
59 new SuggestionsNavigationDelegateImpl(activity, profile, sheet,
tabModelSelector); | 60 new SuggestionsNavigationDelegateImpl(activity, profile, sheet,
tabModelSelector); |
60 mTileGroupDelegate = new TileGroupDelegateImpl( | 61 mTileGroupDelegate = new TileGroupDelegateImpl( |
61 activity, profile, tabModelSelector, navigationDelegate, snackba
rManager); | 62 activity, profile, tabModelSelector, navigationDelegate, snackba
rManager); |
62 mSuggestionsUiDelegate = createSuggestionsDelegate(profile, navigationDe
legate, sheet); | 63 mSuggestionsUiDelegate = createSuggestionsDelegate( |
| 64 profile, navigationDelegate, sheet, activity.getReferencePool())
; |
63 | 65 |
64 mView = LayoutInflater.from(activity).inflate( | 66 mView = LayoutInflater.from(activity).inflate( |
65 R.layout.suggestions_bottom_sheet_content, null); | 67 R.layout.suggestions_bottom_sheet_content, null); |
66 mRecyclerView = (SuggestionsRecyclerView) mView.findViewById(R.id.recycl
er_view); | 68 mRecyclerView = (SuggestionsRecyclerView) mView.findViewById(R.id.recycl
er_view); |
67 | 69 |
68 TouchEnabledDelegate touchEnabledDelegate = new TouchEnabledDelegate() { | 70 TouchEnabledDelegate touchEnabledDelegate = new TouchEnabledDelegate() { |
69 @Override | 71 @Override |
70 public void setTouchEnabled(boolean enabled) { | 72 public void setTouchEnabled(boolean enabled) { |
71 activity.getBottomSheet().setTouchEnabled(enabled); | 73 activity.getBottomSheet().setTouchEnabled(enabled); |
72 } | 74 } |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 | 168 |
167 public static void setSuggestionsSourceForTesting(SuggestionsSource suggesti
onsSource) { | 169 public static void setSuggestionsSourceForTesting(SuggestionsSource suggesti
onsSource) { |
168 sSuggestionsSourceForTesting = suggestionsSource; | 170 sSuggestionsSourceForTesting = suggestionsSource; |
169 } | 171 } |
170 | 172 |
171 public static void setEventReporterForTesting(SuggestionsEventReporter event
Reporter) { | 173 public static void setEventReporterForTesting(SuggestionsEventReporter event
Reporter) { |
172 sEventReporterForTesting = eventReporter; | 174 sEventReporterForTesting = eventReporter; |
173 } | 175 } |
174 | 176 |
175 private static SuggestionsUiDelegateImpl createSuggestionsDelegate(Profile p
rofile, | 177 private static SuggestionsUiDelegateImpl createSuggestionsDelegate(Profile p
rofile, |
176 SuggestionsNavigationDelegate navigationDelegate, NativePageHost hos
t) { | 178 SuggestionsNavigationDelegate navigationDelegate, NativePageHost hos
t, |
| 179 ReferencePool referencePool) { |
177 SnippetsBridge snippetsBridge = null; | 180 SnippetsBridge snippetsBridge = null; |
178 SuggestionsSource suggestionsSource; | 181 SuggestionsSource suggestionsSource; |
179 SuggestionsEventReporter eventReporter; | 182 SuggestionsEventReporter eventReporter; |
180 | 183 |
181 if (sSuggestionsSourceForTesting == null) { | 184 if (sSuggestionsSourceForTesting == null) { |
182 snippetsBridge = new SnippetsBridge(profile); | 185 snippetsBridge = new SnippetsBridge(profile); |
183 suggestionsSource = snippetsBridge; | 186 suggestionsSource = snippetsBridge; |
184 } else { | 187 } else { |
185 suggestionsSource = sSuggestionsSourceForTesting; | 188 suggestionsSource = sSuggestionsSourceForTesting; |
186 } | 189 } |
187 | 190 |
188 if (sEventReporterForTesting == null) { | 191 if (sEventReporterForTesting == null) { |
189 eventReporter = new SuggestionsEventReporterBridge(); | 192 eventReporter = new SuggestionsEventReporterBridge(); |
190 } else { | 193 } else { |
191 eventReporter = sEventReporterForTesting; | 194 eventReporter = sEventReporterForTesting; |
192 } | 195 } |
193 | 196 |
194 SuggestionsUiDelegateImpl delegate = new SuggestionsUiDelegateImpl( | 197 SuggestionsUiDelegateImpl delegate = new SuggestionsUiDelegateImpl( |
195 suggestionsSource, eventReporter, navigationDelegate, profile, h
ost); | 198 suggestionsSource, eventReporter, navigationDelegate, profile, h
ost, referencePool); |
196 if (snippetsBridge != null) delegate.addDestructionObserver(snippetsBrid
ge); | 199 if (snippetsBridge != null) delegate.addDestructionObserver(snippetsBrid
ge); |
197 | 200 |
198 return delegate; | 201 return delegate; |
199 } | 202 } |
200 } | 203 } |
OLD | NEW |