Commit 55584486 authored by gogerald's avatar gogerald Committed by Commit Bot

[StartSurface] Return to home surface when clicking the back button and the...

[StartSurface] Return to home surface when clicking the back button and the explore surface is showing

Bug: 982018
Change-Id: I8d92b1234061869c4fc8c920eb1be8bf2f44db58
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1724659Reviewed-by: default avatarYusuf Ozuysal <yusufo@chromium.org>
Commit-Queue: Ganggui Tang <gogerald@chromium.org>
Auto-Submit: Ganggui Tang <gogerald@chromium.org>
Cr-Commit-Position: refs/heads/master@{#682233}
parent c2b3ac89
......@@ -121,4 +121,15 @@ class BottomBarView extends FrameLayout {
public void setOnClickListener(StartSurfaceProperties.BottomBarClickListener listener) {
mOnClickListener = listener;
}
/**
* Select the Tab at the specified position if needed.
* @param index The specified position.
*/
public void selectTabAt(int index) {
assert index >= 0 && index < mTabLayout.getTabCount();
if (index == mTabLayout.getSelectedTabPosition()) return;
mTabLayout.getTabAt(index).select();
}
}
\ No newline at end of file
......@@ -5,6 +5,7 @@
package org.chromium.chrome.features.start_surface;
import static org.chromium.chrome.features.start_surface.StartSurfaceProperties.BOTTOM_BAR_CLICKLISTENER;
import static org.chromium.chrome.features.start_surface.StartSurfaceProperties.BOTTOM_BAR_SELECTED_TAB_POSITION;
import static org.chromium.chrome.features.start_surface.StartSurfaceProperties.IS_INCOGNITO;
import static org.chromium.chrome.features.start_surface.StartSurfaceProperties.IS_SHOWING_OVERVIEW;
......@@ -14,12 +15,14 @@ import org.chromium.ui.modelutil.PropertyModel;
/** The view binder of the bottom bar. */
class BottomBarViewBinder {
public static void bind(PropertyModel model, BottomBarView view, PropertyKey propertyKey) {
if (IS_INCOGNITO == propertyKey) {
if (BOTTOM_BAR_CLICKLISTENER == propertyKey) {
view.setOnClickListener(model.get(BOTTOM_BAR_CLICKLISTENER));
} else if (BOTTOM_BAR_SELECTED_TAB_POSITION == propertyKey) {
view.selectTabAt(model.get(BOTTOM_BAR_SELECTED_TAB_POSITION));
} else if (IS_INCOGNITO == propertyKey) {
view.setIncognito(model.get(IS_INCOGNITO));
} else if (IS_SHOWING_OVERVIEW == propertyKey) {
view.setVisibility(model.get(IS_SHOWING_OVERVIEW));
} else if (BOTTOM_BAR_CLICKLISTENER == propertyKey) {
view.setOnClickListener(model.get(BOTTOM_BAR_CLICKLISTENER));
}
}
}
\ No newline at end of file
......@@ -5,6 +5,7 @@
package org.chromium.chrome.features.start_surface;
import static org.chromium.chrome.features.start_surface.StartSurfaceProperties.BOTTOM_BAR_CLICKLISTENER;
import static org.chromium.chrome.features.start_surface.StartSurfaceProperties.BOTTOM_BAR_SELECTED_TAB_POSITION;
import static org.chromium.chrome.features.start_surface.StartSurfaceProperties.FEED_SURFACE_COORDINATOR;
import static org.chromium.chrome.features.start_surface.StartSurfaceProperties.IS_EXPLORE_SURFACE_VISIBLE;
import static org.chromium.chrome.features.start_surface.StartSurfaceProperties.IS_INCOGNITO;
......@@ -110,8 +111,10 @@ class StartSurfaceMediator
@Override
public boolean onBackPressed() {
// TODO(crbug.com/982018): Check whether explore surface is shown, if yes, switch back to
// home surface.
if (mPropertyModel != null && mPropertyModel.get(IS_EXPLORE_SURFACE_VISIBLE)) {
setExploreSurfaceVisibility(false);
return true;
}
return mGridController.onBackPressed();
}
......@@ -159,6 +162,10 @@ class StartSurfaceMediator
}
mPropertyModel.set(IS_EXPLORE_SURFACE_VISIBLE, isVisible);
// Update the 'BOTTOM_BAR_SELECTED_TAB_POSITION' property to reflect the change. This is
// needed when clicking back button on the explore surface.
mPropertyModel.set(BOTTOM_BAR_SELECTED_TAB_POSITION, isVisible ? 1 : 0);
}
void updateIncognitoMode(boolean isIncognito) {
......
......@@ -26,6 +26,8 @@ class StartSurfaceProperties {
new PropertyModel.WritableObjectPropertyKey<BottomBarClickListener>();
public static final PropertyModel.WritableIntPropertyKey BOTTOM_BAR_HEIGHT =
new PropertyModel.WritableIntPropertyKey();
public static final PropertyModel.WritableIntPropertyKey BOTTOM_BAR_SELECTED_TAB_POSITION =
new PropertyModel.WritableIntPropertyKey();
public static final PropertyModel.WritableBooleanPropertyKey IS_EXPLORE_SURFACE_VISIBLE =
new PropertyModel.WritableBooleanPropertyKey();
public static final PropertyModel.WritableBooleanPropertyKey IS_INCOGNITO =
......@@ -38,6 +40,6 @@ class StartSurfaceProperties {
public static final PropertyModel.WritableIntPropertyKey TOP_BAR_HEIGHT =
new PropertyModel.WritableIntPropertyKey();
public static final PropertyKey[] ALL_KEYS = new PropertyKey[] {BOTTOM_BAR_CLICKLISTENER,
BOTTOM_BAR_HEIGHT, IS_EXPLORE_SURFACE_VISIBLE, IS_INCOGNITO, IS_SHOWING_OVERVIEW,
FEED_SURFACE_COORDINATOR, TOP_BAR_HEIGHT};
BOTTOM_BAR_HEIGHT, BOTTOM_BAR_SELECTED_TAB_POSITION, IS_EXPLORE_SURFACE_VISIBLE,
IS_INCOGNITO, IS_SHOWING_OVERVIEW, FEED_SURFACE_COORDINATOR, TOP_BAR_HEIGHT};
}
\ No newline at end of file
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