Commit 371065d2 authored by Nicolas Dossou-gbete's avatar Nicolas Dossou-gbete Committed by Commit Bot

[Suggestions] Separate init trigger from bottom sheet opening

We want the initialisation of the home sheet to happen when the bottom
sheet opens and shows the home sheet. However, even though it's the
default sheet, the bottom sheet can also open to show omnibox
suggestions. In that case the home sheet is not shown and should not
be loaded.

This CL makes initialisation happen the first time the sheet is shown
since the opening of the bottom sheet.

Making the home sheet not be selected when the omnibox suggestions are
shown is out of scope and tracked in https://crbug.com/731128

Bug: 735945
Change-Id: I61406ea0ff4207370d86d3fd0712e339813b7ff7
Reviewed-on: https://chromium-review.googlesource.com/563309Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Commit-Queue: Nicolas Dossou-Gbété <dgn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#488189}
parent 5c9afa6d
...@@ -93,25 +93,22 @@ public class SuggestionsBottomSheetContent implements BottomSheet.BottomSheetCon ...@@ -93,25 +93,22 @@ public class SuggestionsBottomSheetContent implements BottomSheet.BottomSheetCon
mBottomSheetObserver = new SuggestionsSheetVisibilityChangeObserver(this, activity) { mBottomSheetObserver = new SuggestionsSheetVisibilityChangeObserver(this, activity) {
@Override @Override
public void onSheetOpened() { public void onContentShown(boolean isFirstShown) {
mRecyclerView.setAdapter(adapter); if (isFirstShown) {
mRecyclerView.setAdapter(adapter);
mRecyclerView.scrollToPosition(0);
adapter.refreshSuggestions(); mRecyclerView.scrollToPosition(0);
mSuggestionsUiDelegate.getEventReporter().onSurfaceOpened(); adapter.refreshSuggestions();
mRecyclerView.getScrollEventReporter().reset(); mSuggestionsUiDelegate.getEventReporter().onSurfaceOpened();
mRecyclerView.getScrollEventReporter().reset();
if (ChromeFeatureList.isEnabled(
ChromeFeatureList.CONTEXTUAL_SUGGESTIONS_CAROUSEL) if (ChromeFeatureList.isEnabled(
&& sheet.getActiveTab() != null) { ChromeFeatureList.CONTEXTUAL_SUGGESTIONS_CAROUSEL)
updateContextualSuggestions(sheet.getActiveTab().getUrl()); && sheet.getActiveTab() != null) {
updateContextualSuggestions(sheet.getActiveTab().getUrl());
}
} }
super.onSheetOpened();
}
@Override
public void onContentShown() {
SuggestionsMetrics.recordSurfaceVisible(); SuggestionsMetrics.recordSurfaceVisible();
} }
......
...@@ -23,6 +23,7 @@ public abstract class SuggestionsSheetVisibilityChangeObserver ...@@ -23,6 +23,7 @@ public abstract class SuggestionsSheetVisibilityChangeObserver
@BottomSheet.SheetState @BottomSheet.SheetState
private int mCurrentContentState; private int mCurrentContentState;
private boolean mCurrentVisibility; private boolean mCurrentVisibility;
private boolean mWasShownSinceLastOpen;
private final ChromeActivity mActivity; private final ChromeActivity mActivity;
private final BottomSheet.BottomSheetContent mContentObserved; private final BottomSheet.BottomSheetContent mContentObserved;
...@@ -55,8 +56,11 @@ public abstract class SuggestionsSheetVisibilityChangeObserver ...@@ -55,8 +56,11 @@ public abstract class SuggestionsSheetVisibilityChangeObserver
mBottomSheet.removeObserver(this); mBottomSheet.removeObserver(this);
} }
/** Called when the observed sheet content becomes visible. */ /** Called when the observed sheet content becomes visible.
public abstract void onContentShown(); * @param isFirstShown Only {@code true} the first time suggestions are shown each time the
* sheet is opened.
*/
public abstract void onContentShown(boolean isFirstShown);
/** Called when the observed sheet content becomes invisible. */ /** Called when the observed sheet content becomes invisible. */
public abstract void onContentHidden(); public abstract void onContentHidden();
...@@ -72,6 +76,7 @@ public abstract class SuggestionsSheetVisibilityChangeObserver ...@@ -72,6 +76,7 @@ public abstract class SuggestionsSheetVisibilityChangeObserver
@Override @Override
@CallSuper @CallSuper
public void onSheetOpened() { public void onSheetOpened() {
mWasShownSinceLastOpen = false;
onStateChange(); onStateChange();
} }
...@@ -109,7 +114,7 @@ public abstract class SuggestionsSheetVisibilityChangeObserver ...@@ -109,7 +114,7 @@ public abstract class SuggestionsSheetVisibilityChangeObserver
/** /**
* Compares the current state of the bottom sheet and activity with the ones recorded at the * Compares the current state of the bottom sheet and activity with the ones recorded at the
* previous call and generates events based on the difference. * previous call and generates events based on the difference.
* @see #onContentShown() * @see #onContentShown(boolean)
* @see #onContentHidden() * @see #onContentHidden()
* @see #onContentStateChanged(int) * @see #onContentStateChanged(int)
*/ */
...@@ -132,7 +137,8 @@ public abstract class SuggestionsSheetVisibilityChangeObserver ...@@ -132,7 +137,8 @@ public abstract class SuggestionsSheetVisibilityChangeObserver
if (newVisibility != mCurrentVisibility) { if (newVisibility != mCurrentVisibility) {
if (newVisibility) { if (newVisibility) {
onContentShown(); onContentShown(!mWasShownSinceLastOpen);
mWasShownSinceLastOpen = true;
} else { } else {
onContentHidden(); onContentHidden();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment