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; |
(...skipping 17 matching lines...) Expand all Loading... | |
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.BottomSheetObserver; |
33 import org.chromium.chrome.browser.widget.bottomsheet.EmptyBottomSheetObserver; | 33 import org.chromium.chrome.browser.widget.bottomsheet.EmptyBottomSheetObserver; |
34 import org.chromium.chrome.browser.widget.displaystyle.UiConfig; | 34 import org.chromium.chrome.browser.widget.displaystyle.UiConfig; |
35 | 35 |
36 /** | 36 /** |
37 * 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. |
38 * | |
39 * TODO(dgn): If the bottom sheet view is not recreated across tab changes, it w ill have to be | |
40 * notified of it, at least when it is pulled up on the new tab. | |
41 */ | 38 */ |
42 public class SuggestionsBottomSheetContent implements BottomSheet.BottomSheetCon tent { | 39 public class SuggestionsBottomSheetContent implements BottomSheet.BottomSheetCon tent { |
43 private static SuggestionsSource sSuggestionsSourceForTesting; | 40 private static SuggestionsSource sSuggestionsSourceForTesting; |
44 private static SuggestionsEventReporter sEventReporterForTesting; | 41 private static SuggestionsEventReporter sEventReporterForTesting; |
45 | 42 |
46 private final View mView; | 43 private final View mView; |
47 private final FadingShadowView mShadowView; | 44 private final FadingShadowView mShadowView; |
48 private final SuggestionsRecyclerView mRecyclerView; | 45 private final SuggestionsRecyclerView mRecyclerView; |
49 private final ContextMenuManager mContextMenuManager; | 46 private final ContextMenuManager mContextMenuManager; |
50 private final SuggestionsUiDelegateImpl mSuggestionsUiDelegate; | 47 private final SuggestionsUiDelegateImpl mSuggestionsUiDelegate; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 final NewTabPageAdapter adapter = new NewTabPageAdapter(mSuggestionsUiDe legate, | 83 final NewTabPageAdapter adapter = new NewTabPageAdapter(mSuggestionsUiDe legate, |
87 /* aboveTheFoldView = */ null, uiConfig, OfflinePageBridge.getFo rProfile(profile), | 84 /* aboveTheFoldView = */ null, uiConfig, OfflinePageBridge.getFo rProfile(profile), |
88 mContextMenuManager, mTileGroupDelegate); | 85 mContextMenuManager, mTileGroupDelegate); |
89 mRecyclerView.init(uiConfig, mContextMenuManager, adapter); | 86 mRecyclerView.init(uiConfig, mContextMenuManager, adapter); |
90 | 87 |
91 mBottomSheetObserver = new EmptyBottomSheetObserver() { | 88 mBottomSheetObserver = new EmptyBottomSheetObserver() { |
92 @Override | 89 @Override |
93 public void onSheetOpened() { | 90 public void onSheetOpened() { |
94 mRecyclerView.scrollToPosition(0); | 91 mRecyclerView.scrollToPosition(0); |
95 | 92 |
96 // TODO(https://crbug.com/689962) Ensure this call does not disc ard all suggestions | |
97 // every time the sheet is opened. | |
98 adapter.refreshSuggestions(); | 93 adapter.refreshSuggestions(); |
99 mSuggestionsUiDelegate.getEventReporter().onSurfaceOpened(); | 94 mSuggestionsUiDelegate.getEventReporter().onSurfaceOpened(); |
95 SuggestionsMetrics.recordSurfaceVisible(); | |
100 } | 96 } |
97 | |
98 @Override | |
99 public void onSheetClosed() { | |
100 SuggestionsMetrics.recordSurfaceHidden(); | |
101 } | |
102 | |
101 }; | 103 }; |
102 mBottomSheet = activity.getBottomSheet(); | 104 mBottomSheet = activity.getBottomSheet(); |
103 mBottomSheet.addObserver(mBottomSheetObserver); | 105 mBottomSheet.addObserver(mBottomSheetObserver); |
104 adapter.refreshSuggestions(); | 106 |
105 mSuggestionsUiDelegate.getEventReporter().onSurfaceOpened(); | 107 if (mBottomSheet.isSheetOpen()) { |
Bernhard Bauer
2017/05/08 13:55:55
Oh, so it can happen that we initialize the sheet
| |
108 adapter.refreshSuggestions(); | |
109 mSuggestionsUiDelegate.getEventReporter().onSurfaceOpened(); | |
110 SuggestionsMetrics.recordSurfaceVisible(); | |
111 } | |
106 | 112 |
107 mShadowView = (FadingShadowView) mView.findViewById(R.id.shadow); | 113 mShadowView = (FadingShadowView) mView.findViewById(R.id.shadow); |
108 mShadowView.init( | 114 mShadowView.init( |
109 ApiCompatibilityUtils.getColor(mView.getResources(), R.color.too lbar_shadow_color), | 115 ApiCompatibilityUtils.getColor(mView.getResources(), R.color.too lbar_shadow_color), |
110 FadingShadow.POSITION_TOP); | 116 FadingShadow.POSITION_TOP); |
111 | 117 |
112 mRecyclerView.addOnScrollListener(new OnScrollListener() { | 118 mRecyclerView.addOnScrollListener(new OnScrollListener() { |
113 @Override | 119 @Override |
114 public void onScrolled(RecyclerView recyclerView, int dx, int dy) { | 120 public void onScrolled(RecyclerView recyclerView, int dx, int dy) { |
115 boolean shadowVisible = mRecyclerView.canScrollVertically(-1); | 121 boolean shadowVisible = mRecyclerView.canScrollVertically(-1); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
191 eventReporter = sEventReporterForTesting; | 197 eventReporter = sEventReporterForTesting; |
192 } | 198 } |
193 | 199 |
194 SuggestionsUiDelegateImpl delegate = new SuggestionsUiDelegateImpl( | 200 SuggestionsUiDelegateImpl delegate = new SuggestionsUiDelegateImpl( |
195 suggestionsSource, eventReporter, navigationDelegate, profile, h ost); | 201 suggestionsSource, eventReporter, navigationDelegate, profile, h ost); |
196 if (snippetsBridge != null) delegate.addDestructionObserver(snippetsBrid ge); | 202 if (snippetsBridge != null) delegate.addDestructionObserver(snippetsBrid ge); |
197 | 203 |
198 return delegate; | 204 return delegate; |
199 } | 205 } |
200 } | 206 } |
OLD | NEW |