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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/suggestions/SuggestionsBottomSheetContent.java

Issue 2844993003: [Home] Remove BottomSheetObservers that are no longer used (Closed)
Patch Set: Created 3 years, 7 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
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/widget/bottomsheet/BottomSheet.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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;
(...skipping 11 matching lines...) Expand all
22 import org.chromium.chrome.browser.ntp.snippets.SuggestionsSource; 22 import org.chromium.chrome.browser.ntp.snippets.SuggestionsSource;
23 import org.chromium.chrome.browser.offlinepages.OfflinePageBridge; 23 import org.chromium.chrome.browser.offlinepages.OfflinePageBridge;
24 import org.chromium.chrome.browser.omnibox.LocationBar; 24 import org.chromium.chrome.browser.omnibox.LocationBar;
25 import org.chromium.chrome.browser.profiles.Profile; 25 import org.chromium.chrome.browser.profiles.Profile;
26 import org.chromium.chrome.browser.snackbar.SnackbarManager; 26 import org.chromium.chrome.browser.snackbar.SnackbarManager;
27 import org.chromium.chrome.browser.tabmodel.TabModelSelector; 27 import org.chromium.chrome.browser.tabmodel.TabModelSelector;
28 import org.chromium.chrome.browser.widget.FadingShadow; 28 import org.chromium.chrome.browser.widget.FadingShadow;
29 import org.chromium.chrome.browser.widget.FadingShadowView; 29 import org.chromium.chrome.browser.widget.FadingShadowView;
30 import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet; 30 import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet;
31 import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetContentControll er; 31 import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetContentControll er;
32 import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetObserver;
32 import org.chromium.chrome.browser.widget.bottomsheet.EmptyBottomSheetObserver; 33 import org.chromium.chrome.browser.widget.bottomsheet.EmptyBottomSheetObserver;
33 import org.chromium.chrome.browser.widget.displaystyle.UiConfig; 34 import org.chromium.chrome.browser.widget.displaystyle.UiConfig;
34 35
35 /** 36 /**
36 * Provides content to be displayed inside of the Home tab of bottom sheet. 37 * Provides content to be displayed inside of the Home tab of bottom sheet.
37 * 38 *
38 * TODO(dgn): If the bottom sheet view is not recreated across tab changes, it w ill have to be 39 * TODO(dgn): If the bottom sheet view is not recreated across tab changes, it w ill have to be
39 * notified of it, at least when it is pulled up on the new tab. 40 * notified of it, at least when it is pulled up on the new tab.
40 */ 41 */
41 public class SuggestionsBottomSheetContent implements BottomSheet.BottomSheetCon tent { 42 public class SuggestionsBottomSheetContent implements BottomSheet.BottomSheetCon tent {
42 private static SuggestionsSource sSuggestionsSourceForTesting; 43 private static SuggestionsSource sSuggestionsSourceForTesting;
43 private static SuggestionsMetricsReporter sMetricsReporterForTesting; 44 private static SuggestionsMetricsReporter sMetricsReporterForTesting;
44 45
45 private final View mView; 46 private final View mView;
46 private final FadingShadowView mShadowView; 47 private final FadingShadowView mShadowView;
47 private final SuggestionsRecyclerView mRecyclerView; 48 private final SuggestionsRecyclerView mRecyclerView;
48 private final ContextMenuManager mContextMenuManager; 49 private final ContextMenuManager mContextMenuManager;
49 private final SuggestionsUiDelegateImpl mSuggestionsManager; 50 private final SuggestionsUiDelegateImpl mSuggestionsManager;
50 private final TileGroup.Delegate mTileGroupDelegate; 51 private final TileGroup.Delegate mTileGroupDelegate;
52 private final BottomSheet mBottomSheet;
53 private final BottomSheetObserver mBottomSheetObserver;
51 54
52 public SuggestionsBottomSheetContent(final ChromeActivity activity, final Bo ttomSheet sheet, 55 public SuggestionsBottomSheetContent(final ChromeActivity activity, final Bo ttomSheet sheet,
53 TabModelSelector tabModelSelector, SnackbarManager snackbarManager) { 56 TabModelSelector tabModelSelector, SnackbarManager snackbarManager) {
54 Profile profile = Profile.getLastUsedProfile(); 57 Profile profile = Profile.getLastUsedProfile();
55 SuggestionsNavigationDelegate navigationDelegate = 58 SuggestionsNavigationDelegate navigationDelegate =
56 new SuggestionsNavigationDelegateImpl(activity, profile, sheet, tabModelSelector); 59 new SuggestionsNavigationDelegateImpl(activity, profile, sheet, tabModelSelector);
57 mTileGroupDelegate = new TileGroupDelegateImpl( 60 mTileGroupDelegate = new TileGroupDelegateImpl(
58 activity, profile, tabModelSelector, navigationDelegate, snackba rManager); 61 activity, profile, tabModelSelector, navigationDelegate, snackba rManager);
59 mSuggestionsManager = createSuggestionsDelegate(profile, navigationDeleg ate, sheet); 62 mSuggestionsManager = createSuggestionsDelegate(profile, navigationDeleg ate, sheet);
60 63
(...skipping 18 matching lines...) Expand all
79 }); 82 });
80 83
81 UiConfig uiConfig = new UiConfig(mRecyclerView); 84 UiConfig uiConfig = new UiConfig(mRecyclerView);
82 85
83 final NewTabPageAdapter adapter = new NewTabPageAdapter(mSuggestionsMana ger, 86 final NewTabPageAdapter adapter = new NewTabPageAdapter(mSuggestionsMana ger,
84 /* aboveTheFoldView = */ null, uiConfig, OfflinePageBridge.getFo rProfile(profile), 87 /* aboveTheFoldView = */ null, uiConfig, OfflinePageBridge.getFo rProfile(profile),
85 mContextMenuManager, mTileGroupDelegate); 88 mContextMenuManager, mTileGroupDelegate);
86 mRecyclerView.init(uiConfig, mContextMenuManager, adapter); 89 mRecyclerView.init(uiConfig, mContextMenuManager, adapter);
87 90
88 final SuggestionsSource suggestionsSource = mSuggestionsManager.getSugge stionsSource(); 91 final SuggestionsSource suggestionsSource = mSuggestionsManager.getSugge stionsSource();
89 activity.getBottomSheet().addObserver(new EmptyBottomSheetObserver() { 92 mBottomSheetObserver = new EmptyBottomSheetObserver() {
90 @Override 93 @Override
91 public void onSheetOpened() { 94 public void onSheetOpened() {
92 mRecyclerView.scrollTo(0, 0); 95 mRecyclerView.scrollTo(0, 0);
93 96
94 // TODO(https://crbug.com/689962) Ensure this call does not disc ard all suggestions 97 // TODO(https://crbug.com/689962) Ensure this call does not disc ard all suggestions
95 // every time the sheet is opened. 98 // every time the sheet is opened.
96 adapter.refreshSuggestions(); 99 adapter.refreshSuggestions();
97 suggestionsSource.onNtpInitialized(); 100 suggestionsSource.onNtpInitialized();
98 } 101 }
99 }); 102 };
103 mBottomSheet = activity.getBottomSheet();
104 mBottomSheet.addObserver(mBottomSheetObserver);
100 adapter.refreshSuggestions(); 105 adapter.refreshSuggestions();
101 suggestionsSource.onNtpInitialized(); 106 suggestionsSource.onNtpInitialized();
102 107
103 mShadowView = (FadingShadowView) mView.findViewById(R.id.shadow); 108 mShadowView = (FadingShadowView) mView.findViewById(R.id.shadow);
104 mShadowView.init( 109 mShadowView.init(
105 ApiCompatibilityUtils.getColor(mView.getResources(), R.color.too lbar_shadow_color), 110 ApiCompatibilityUtils.getColor(mView.getResources(), R.color.too lbar_shadow_color),
106 FadingShadow.POSITION_TOP); 111 FadingShadow.POSITION_TOP);
107 112
108 mRecyclerView.addOnScrollListener(new OnScrollListener() { 113 mRecyclerView.addOnScrollListener(new OnScrollListener() {
109 @Override 114 @Override
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 return false; 148 return false;
144 } 149 }
145 150
146 @Override 151 @Override
147 public int getVerticalScrollOffset() { 152 public int getVerticalScrollOffset() {
148 return mRecyclerView.computeVerticalScrollOffset(); 153 return mRecyclerView.computeVerticalScrollOffset();
149 } 154 }
150 155
151 @Override 156 @Override
152 public void destroy() { 157 public void destroy() {
158 mBottomSheet.removeObserver(mBottomSheetObserver);
153 mSuggestionsManager.onDestroy(); 159 mSuggestionsManager.onDestroy();
154 mTileGroupDelegate.destroy(); 160 mTileGroupDelegate.destroy();
155 } 161 }
156 162
157 @Override 163 @Override
158 public int getType() { 164 public int getType() {
159 return BottomSheetContentController.TYPE_SUGGESTIONS; 165 return BottomSheetContentController.TYPE_SUGGESTIONS;
160 } 166 }
161 167
162 public static void setSuggestionsSourceForTesting(SuggestionsSource suggesti onsSource) { 168 public static void setSuggestionsSourceForTesting(SuggestionsSource suggesti onsSource) {
(...skipping 24 matching lines...) Expand all
187 metricsReporter = sMetricsReporterForTesting; 193 metricsReporter = sMetricsReporterForTesting;
188 } 194 }
189 195
190 SuggestionsUiDelegateImpl delegate = new SuggestionsUiDelegateImpl( 196 SuggestionsUiDelegateImpl delegate = new SuggestionsUiDelegateImpl(
191 suggestionsSource, metricsReporter, navigationDelegate, profile, host); 197 suggestionsSource, metricsReporter, navigationDelegate, profile, host);
192 if (snippetsBridge != null) delegate.addDestructionObserver(snippetsBrid ge); 198 if (snippetsBridge != null) delegate.addDestructionObserver(snippetsBrid ge);
193 199
194 return delegate; 200 return delegate;
195 } 201 }
196 } 202 }
OLDNEW
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/widget/bottomsheet/BottomSheet.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698