| 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.support.v7.widget.RecyclerView; |
| 8 import android.support.v7.widget.RecyclerView.OnScrollListener; |
| 9 import android.view.LayoutInflater; |
| 7 import android.view.View; | 10 import android.view.View; |
| 8 | 11 |
| 12 import org.chromium.base.ApiCompatibilityUtils; |
| 13 import org.chromium.chrome.R; |
| 9 import org.chromium.chrome.browser.ChromeActivity; | 14 import org.chromium.chrome.browser.ChromeActivity; |
| 10 import org.chromium.chrome.browser.NativePageHost; | 15 import org.chromium.chrome.browser.NativePageHost; |
| 11 import org.chromium.chrome.browser.ntp.ContextMenuManager; | 16 import org.chromium.chrome.browser.ntp.ContextMenuManager; |
| 12 import org.chromium.chrome.browser.ntp.cards.NewTabPageAdapter; | 17 import org.chromium.chrome.browser.ntp.cards.NewTabPageAdapter; |
| 13 import org.chromium.chrome.browser.ntp.snippets.SnippetsBridge; | 18 import org.chromium.chrome.browser.ntp.snippets.SnippetsBridge; |
| 14 import org.chromium.chrome.browser.ntp.snippets.SuggestionsSource; | 19 import org.chromium.chrome.browser.ntp.snippets.SuggestionsSource; |
| 15 import org.chromium.chrome.browser.offlinepages.OfflinePageBridge; | 20 import org.chromium.chrome.browser.offlinepages.OfflinePageBridge; |
| 16 import org.chromium.chrome.browser.profiles.Profile; | 21 import org.chromium.chrome.browser.profiles.Profile; |
| 17 import org.chromium.chrome.browser.tabmodel.TabModelSelector; | 22 import org.chromium.chrome.browser.tabmodel.TabModelSelector; |
| 23 import org.chromium.chrome.browser.widget.FadingShadow; |
| 24 import org.chromium.chrome.browser.widget.FadingShadowView; |
| 18 import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet; | 25 import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet; |
| 19 import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetContentControll
er; | 26 import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetContentControll
er; |
| 20 import org.chromium.chrome.browser.widget.bottomsheet.EmptyBottomSheetObserver; | 27 import org.chromium.chrome.browser.widget.bottomsheet.EmptyBottomSheetObserver; |
| 21 import org.chromium.chrome.browser.widget.displaystyle.UiConfig; | 28 import org.chromium.chrome.browser.widget.displaystyle.UiConfig; |
| 22 | 29 |
| 23 /** | 30 /** |
| 24 * Provides content to be displayed inside of the Home tab of bottom sheet. | 31 * Provides content to be displayed inside of the Home tab of bottom sheet. |
| 25 * | 32 * |
| 26 * TODO(dgn): If the bottom sheet view is not recreated across tab changes, it w
ill have to be | 33 * TODO(dgn): If the bottom sheet view is not recreated across tab changes, it w
ill have to be |
| 27 * notified of it, at least when it is pulled up on the new tab. | 34 * notified of it, at least when it is pulled up on the new tab. |
| 28 */ | 35 */ |
| 29 public class SuggestionsBottomSheetContent implements BottomSheet.BottomSheetCon
tent { | 36 public class SuggestionsBottomSheetContent implements BottomSheet.BottomSheetCon
tent { |
| 30 private static SuggestionsSource sSuggestionsSourceForTesting; | 37 private static SuggestionsSource sSuggestionsSourceForTesting; |
| 31 private static SuggestionsMetricsReporter sMetricsReporterForTesting; | 38 private static SuggestionsMetricsReporter sMetricsReporterForTesting; |
| 32 | 39 |
| 40 private final View mView; |
| 41 private final FadingShadowView mShadowView; |
| 33 private final SuggestionsRecyclerView mRecyclerView; | 42 private final SuggestionsRecyclerView mRecyclerView; |
| 34 private final ContextMenuManager mContextMenuManager; | 43 private final ContextMenuManager mContextMenuManager; |
| 35 private final SuggestionsUiDelegateImpl mSuggestionsManager; | 44 private final SuggestionsUiDelegateImpl mSuggestionsManager; |
| 36 private final TileGroup.Delegate mTileGroupDelegate; | 45 private final TileGroup.Delegate mTileGroupDelegate; |
| 37 | 46 |
| 38 public SuggestionsBottomSheetContent( | 47 public SuggestionsBottomSheetContent( |
| 39 final ChromeActivity activity, NativePageHost host, TabModelSelector
tabModelSelector) { | 48 final ChromeActivity activity, NativePageHost host, TabModelSelector
tabModelSelector) { |
| 40 | 49 |
| 41 Profile profile = Profile.getLastUsedProfile(); | 50 Profile profile = Profile.getLastUsedProfile(); |
| 42 SuggestionsNavigationDelegate navigationDelegate = | 51 SuggestionsNavigationDelegate navigationDelegate = |
| 43 new SuggestionsNavigationDelegateImpl(activity, profile, host, t
abModelSelector); | 52 new SuggestionsNavigationDelegateImpl(activity, profile, host, t
abModelSelector); |
| 44 mTileGroupDelegate = | 53 mTileGroupDelegate = |
| 45 new TileGroupDelegateImpl(activity, profile, tabModelSelector, n
avigationDelegate); | 54 new TileGroupDelegateImpl(activity, profile, tabModelSelector, n
avigationDelegate); |
| 46 mSuggestionsManager = createSuggestionsDelegate(profile, navigationDeleg
ate, host); | 55 mSuggestionsManager = createSuggestionsDelegate(profile, navigationDeleg
ate, host); |
| 47 | 56 |
| 48 mRecyclerView = new SuggestionsRecyclerView(activity); | 57 mView = LayoutInflater.from(activity).inflate( |
| 58 R.layout.suggestions_bottom_sheet_content, null); |
| 59 mRecyclerView = (SuggestionsRecyclerView) mView.findViewById(R.id.recycl
er_view); |
| 49 mContextMenuManager = new ContextMenuManager(activity, navigationDelegat
e, mRecyclerView); | 60 mContextMenuManager = new ContextMenuManager(activity, navigationDelegat
e, mRecyclerView); |
| 50 activity.getWindowAndroid().addContextMenuCloseListener(mContextMenuMana
ger); | 61 activity.getWindowAndroid().addContextMenuCloseListener(mContextMenuMana
ger); |
| 51 mSuggestionsManager.addDestructionObserver(new DestructionObserver() { | 62 mSuggestionsManager.addDestructionObserver(new DestructionObserver() { |
| 52 @Override | 63 @Override |
| 53 public void onDestroy() { | 64 public void onDestroy() { |
| 54 activity.getWindowAndroid().removeContextMenuCloseListener(mCont
extMenuManager); | 65 activity.getWindowAndroid().removeContextMenuCloseListener(mCont
extMenuManager); |
| 55 } | 66 } |
| 56 }); | 67 }); |
| 57 | 68 |
| 58 UiConfig uiConfig = new UiConfig(mRecyclerView); | 69 UiConfig uiConfig = new UiConfig(mRecyclerView); |
| 59 | 70 |
| 60 // This mAdapter does not fetch until later requested, when the sheet is
opened. | 71 // This mAdapter does not fetch until later requested, when the sheet is
opened. |
| 61 final NewTabPageAdapter adapter = new NewTabPageAdapter(mSuggestionsMana
ger, | 72 final NewTabPageAdapter adapter = new NewTabPageAdapter(mSuggestionsMana
ger, |
| 62 /* aboveTheFoldView = */ null, uiConfig, OfflinePageBridge.getFo
rProfile(profile), | 73 /* aboveTheFoldView = */ null, uiConfig, OfflinePageBridge.getFo
rProfile(profile), |
| 63 mContextMenuManager, mTileGroupDelegate); | 74 mContextMenuManager, mTileGroupDelegate); |
| 64 mRecyclerView.setAdapter(adapter); | 75 mRecyclerView.setAdapter(adapter); |
| 65 | 76 |
| 66 activity.getBottomSheet().addObserver(new EmptyBottomSheetObserver() { | 77 activity.getBottomSheet().addObserver(new EmptyBottomSheetObserver() { |
| 67 @Override | 78 @Override |
| 68 public void onSheetOpened() { | 79 public void onSheetOpened() { |
| 69 adapter.refreshSuggestions(); | 80 adapter.refreshSuggestions(); |
| 70 } | 81 } |
| 71 }); | 82 }); |
| 72 | 83 |
| 73 if (activity.getBottomSheet().getSheetState() != BottomSheet.SHEET_STATE
_PEEK) { | 84 if (activity.getBottomSheet().getSheetState() != BottomSheet.SHEET_STATE
_PEEK) { |
| 74 adapter.refreshSuggestions(); | 85 adapter.refreshSuggestions(); |
| 75 } | 86 } |
| 87 |
| 88 mShadowView = (FadingShadowView) mView.findViewById(R.id.shadow); |
| 89 mShadowView.init( |
| 90 ApiCompatibilityUtils.getColor(mView.getResources(), R.color.too
lbar_shadow_color), |
| 91 FadingShadow.POSITION_TOP); |
| 92 |
| 93 mRecyclerView.addOnScrollListener(new OnScrollListener() { |
| 94 @Override |
| 95 public void onScrolled(RecyclerView recyclerView, int dx, int dy) { |
| 96 boolean shadowVisible = mRecyclerView.canScrollVertically(-1); |
| 97 mShadowView.setVisibility(shadowVisible ? View.VISIBLE : View.GO
NE); |
| 98 } |
| 99 }); |
| 76 } | 100 } |
| 77 | 101 |
| 78 @Override | 102 @Override |
| 79 public View getContentView() { | 103 public View getContentView() { |
| 80 return mRecyclerView; | 104 return mView; |
| 81 } | 105 } |
| 82 | 106 |
| 83 @Override | 107 @Override |
| 84 public View getToolbarView() { | 108 public View getToolbarView() { |
| 85 return null; | 109 return null; |
| 86 } | 110 } |
| 87 | 111 |
| 88 @Override | 112 @Override |
| 89 public int getVerticalScrollOffset() { | 113 public int getVerticalScrollOffset() { |
| 90 return mRecyclerView.computeVerticalScrollOffset(); | 114 return mRecyclerView.computeVerticalScrollOffset(); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 metricsReporter = sMetricsReporterForTesting; | 157 metricsReporter = sMetricsReporterForTesting; |
| 134 } | 158 } |
| 135 | 159 |
| 136 SuggestionsUiDelegateImpl delegate = new SuggestionsUiDelegateImpl( | 160 SuggestionsUiDelegateImpl delegate = new SuggestionsUiDelegateImpl( |
| 137 suggestionsSource, metricsReporter, navigationDelegate, profile,
host); | 161 suggestionsSource, metricsReporter, navigationDelegate, profile,
host); |
| 138 if (snippetsBridge != null) delegate.addDestructionObserver(snippetsBrid
ge); | 162 if (snippetsBridge != null) delegate.addDestructionObserver(snippetsBrid
ge); |
| 139 | 163 |
| 140 return delegate; | 164 return delegate; |
| 141 } | 165 } |
| 142 } | 166 } |
| OLD | NEW |