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.DiscardableReferencePool; |
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 24 matching lines...) Expand all Loading... |
49 private final BottomSheet mBottomSheet; | 50 private final BottomSheet mBottomSheet; |
50 private final BottomSheetObserver mBottomSheetObserver; | 51 private final BottomSheetObserver mBottomSheetObserver; |
51 | 52 |
52 public SuggestionsBottomSheetContent(final ChromeActivity activity, final Bo
ttomSheet sheet, | 53 public SuggestionsBottomSheetContent(final ChromeActivity activity, final Bo
ttomSheet sheet, |
53 TabModelSelector tabModelSelector, SnackbarManager snackbarManager)
{ | 54 TabModelSelector tabModelSelector, SnackbarManager snackbarManager)
{ |
54 Profile profile = Profile.getLastUsedProfile(); | 55 Profile profile = Profile.getLastUsedProfile(); |
55 SuggestionsNavigationDelegate navigationDelegate = | 56 SuggestionsNavigationDelegate navigationDelegate = |
56 new SuggestionsNavigationDelegateImpl(activity, profile, sheet,
tabModelSelector); | 57 new SuggestionsNavigationDelegateImpl(activity, profile, sheet,
tabModelSelector); |
57 mTileGroupDelegate = new TileGroupDelegateImpl( | 58 mTileGroupDelegate = new TileGroupDelegateImpl( |
58 activity, profile, tabModelSelector, navigationDelegate, snackba
rManager); | 59 activity, profile, tabModelSelector, navigationDelegate, snackba
rManager); |
59 mSuggestionsUiDelegate = createSuggestionsDelegate(profile, navigationDe
legate, sheet); | 60 mSuggestionsUiDelegate = createSuggestionsDelegate( |
| 61 profile, navigationDelegate, sheet, activity.getReferencePool())
; |
60 | 62 |
61 mView = LayoutInflater.from(activity).inflate( | 63 mView = LayoutInflater.from(activity).inflate( |
62 R.layout.suggestions_bottom_sheet_content, null); | 64 R.layout.suggestions_bottom_sheet_content, null); |
63 mRecyclerView = (SuggestionsRecyclerView) mView.findViewById(R.id.recycl
er_view); | 65 mRecyclerView = (SuggestionsRecyclerView) mView.findViewById(R.id.recycl
er_view); |
64 | 66 |
65 TouchEnabledDelegate touchEnabledDelegate = new TouchEnabledDelegate() { | 67 TouchEnabledDelegate touchEnabledDelegate = new TouchEnabledDelegate() { |
66 @Override | 68 @Override |
67 public void setTouchEnabled(boolean enabled) { | 69 public void setTouchEnabled(boolean enabled) { |
68 activity.getBottomSheet().setTouchEnabled(enabled); | 70 activity.getBottomSheet().setTouchEnabled(enabled); |
69 } | 71 } |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 | 174 |
173 public static void setSuggestionsSourceForTesting(SuggestionsSource suggesti
onsSource) { | 175 public static void setSuggestionsSourceForTesting(SuggestionsSource suggesti
onsSource) { |
174 sSuggestionsSourceForTesting = suggestionsSource; | 176 sSuggestionsSourceForTesting = suggestionsSource; |
175 } | 177 } |
176 | 178 |
177 public static void setEventReporterForTesting(SuggestionsEventReporter event
Reporter) { | 179 public static void setEventReporterForTesting(SuggestionsEventReporter event
Reporter) { |
178 sEventReporterForTesting = eventReporter; | 180 sEventReporterForTesting = eventReporter; |
179 } | 181 } |
180 | 182 |
181 private static SuggestionsUiDelegateImpl createSuggestionsDelegate(Profile p
rofile, | 183 private static SuggestionsUiDelegateImpl createSuggestionsDelegate(Profile p
rofile, |
182 SuggestionsNavigationDelegate navigationDelegate, NativePageHost hos
t) { | 184 SuggestionsNavigationDelegate navigationDelegate, NativePageHost hos
t, |
| 185 DiscardableReferencePool referencePool) { |
183 SnippetsBridge snippetsBridge = null; | 186 SnippetsBridge snippetsBridge = null; |
184 SuggestionsSource suggestionsSource; | 187 SuggestionsSource suggestionsSource; |
185 SuggestionsEventReporter eventReporter; | 188 SuggestionsEventReporter eventReporter; |
186 | 189 |
187 if (sSuggestionsSourceForTesting == null) { | 190 if (sSuggestionsSourceForTesting == null) { |
188 snippetsBridge = new SnippetsBridge(profile); | 191 snippetsBridge = new SnippetsBridge(profile); |
189 suggestionsSource = snippetsBridge; | 192 suggestionsSource = snippetsBridge; |
190 } else { | 193 } else { |
191 suggestionsSource = sSuggestionsSourceForTesting; | 194 suggestionsSource = sSuggestionsSourceForTesting; |
192 } | 195 } |
193 | 196 |
194 if (sEventReporterForTesting == null) { | 197 if (sEventReporterForTesting == null) { |
195 eventReporter = new SuggestionsEventReporterBridge(); | 198 eventReporter = new SuggestionsEventReporterBridge(); |
196 } else { | 199 } else { |
197 eventReporter = sEventReporterForTesting; | 200 eventReporter = sEventReporterForTesting; |
198 } | 201 } |
199 | 202 |
200 SuggestionsUiDelegateImpl delegate = new SuggestionsUiDelegateImpl( | 203 SuggestionsUiDelegateImpl delegate = new SuggestionsUiDelegateImpl( |
201 suggestionsSource, eventReporter, navigationDelegate, profile, h
ost); | 204 suggestionsSource, eventReporter, navigationDelegate, profile, h
ost, referencePool); |
202 if (snippetsBridge != null) delegate.addDestructionObserver(snippetsBrid
ge); | 205 if (snippetsBridge != null) delegate.addDestructionObserver(snippetsBrid
ge); |
203 | 206 |
204 return delegate; | 207 return delegate; |
205 } | 208 } |
206 } | 209 } |
OLD | NEW |