Commit 4e2f3ad6 authored by Theresa Wellington's avatar Theresa Wellington Committed by Commit Bot

[Home] Select "Home" content when NTP UI shown

Previously if the sheet was open and another BottomSheetContent was
displayed, opening a new tab (e.g. via a launcher shortcut) did not
switch to the "Home" content.

BUG=743066

Change-Id: Ib1dc72c1e301e31685580e334a0b5da0f2719dd5
Reviewed-on: https://chromium-review.googlesource.com/572040Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Commit-Queue: Theresa <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487323}
parent 226c080a
......@@ -778,7 +778,7 @@ public class BottomSheet
mToolbarHolder = (FrameLayout) mControlContainer.findViewById(R.id.toolbar_holder);
mDefaultToolbarView = (BottomToolbarPhone) mControlContainer.findViewById(R.id.toolbar);
mNtpController = new BottomSheetNewTabController(this, mDefaultToolbarView);
mNtpController = new BottomSheetNewTabController(this, mDefaultToolbarView, mActivity);
mActivity.getFullscreenManager().addListener(new FullscreenListener() {
@Override
......
......@@ -223,6 +223,16 @@ public class BottomSheetContentController extends BottomNavigationView
mDefaultContentInitialized = true;
}
/**
* @param itemId The id of the MenuItem to select.
*/
public void selectItem(int itemId) {
// TODO(twellington): A #setSelectedItemId() method was added to the support library
// recently. Replace this custom implementation with that method after
// the support library is rolled.
onNavigationItemSelected(getMenu().findItem(itemId));
}
/**
* Shows the specified {@link BottomSheetContent} and opens the {@link BottomSheet}.
* @param itemId The menu item id of the {@link BottomSheetContent} to show.
......@@ -346,17 +356,6 @@ public class BottomSheetContentController extends BottomNavigationView
setItemTextColor(tint);
}
/**
* @param itemId The id of the MenuItem to select.
*/
@VisibleForTesting
public void selectItem(int itemId) {
// TODO(twellington): A #setSelectedItemId() method was added to the support library
// recently. Replace this custom implementation with that method after
// the support library is rolled.
onNavigationItemSelected(getMenu().findItem(itemId));
}
@VisibleForTesting
public int getSelectedItemIdForTests() {
// TODO(twellington): A #getSelectedItemId() method was added to the support library
......
......@@ -4,6 +4,8 @@
package org.chromium.chrome.browser.widget.bottomsheet;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.compositor.layouts.EmptyOverviewModeObserver;
import org.chromium.chrome.browser.compositor.layouts.LayoutManagerChrome;
import org.chromium.chrome.browser.compositor.layouts.OverviewModeBehavior.OverviewModeObserver;
......@@ -13,12 +15,11 @@ import org.chromium.chrome.browser.toolbar.BottomToolbarPhone;
/**
* A class that handles showing and hiding the Chrome Home new tab UI.
*
* TODO(twellington): Add tests for this class.
*/
public class BottomSheetNewTabController extends EmptyBottomSheetObserver {
private final BottomSheet mBottomSheet;
private final BottomToolbarPhone mToolbar;
private final ChromeActivity mActivity;
private LayoutManagerChrome mLayoutManager;
private OverviewModeObserver mOverviewModeObserver;
......@@ -34,11 +35,14 @@ public class BottomSheetNewTabController extends EmptyBottomSheetObserver {
* @param bottomSheet The {@link BottomSheet} that will be opened as part of the new tab UI.
* @param toolbar The {@link BottomToolbarPhone} that this controller will set state on as part
* of the new tab UI.
* @param activity The {@link ChromeActivity} containing the {@link BottomSheet}.
*/
public BottomSheetNewTabController(BottomSheet bottomSheet, BottomToolbarPhone toolbar) {
public BottomSheetNewTabController(
BottomSheet bottomSheet, BottomToolbarPhone toolbar, ChromeActivity activity) {
mBottomSheet = bottomSheet;
mBottomSheet.addObserver(this);
mToolbar = toolbar;
mActivity = activity;
}
/**
......@@ -92,14 +96,19 @@ public class BottomSheetNewTabController extends EmptyBottomSheetObserver {
// Tell the model that a new tab may be added soon.
mTabModelSelector.getModel(isIncognito).setIsPendingTabAdd(true);
// Select the correct model, immediately ending animations so that the sheet content is not
// in transition while the sheet is opening.
// Select the correct model, immediately ending animations so that the previous sheet
// content is not in use while calling #setIsPendingTabAdd() on previous model.
if (mTabModelSelector.isIncognitoSelected() != isIncognito) {
mTabModelSelector.selectModel(isIncognito);
mBottomSheet.endTransitionAnimations();
mTabModelSelector.getModel(!isIncognito).setIsPendingTabAdd(false);
}
// Select the correct sheet content, immediately ending animations so that the sheet content
// is not in transition while the sheet is opening.
mActivity.getBottomSheetContentController().selectItem(R.id.action_home);
mBottomSheet.endTransitionAnimations();
// Open the sheet if it isn't already open to the desired height.
int sheetState = mTabModelSelector.getCurrentModel().getCount() == 0
? BottomSheet.SHEET_STATE_FULL
......
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