Commit 4723f906 authored by Mia Glaese's avatar Mia Glaese Committed by Commit Bot

[StartSurface] Return to last active pane

Bug: 982018

Change-Id: I28705cff7085007ece4a802e03409f95996c3103
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1745572
Commit-Queue: Mia Glaese <glamia@chromium.org>
Reviewed-by: default avatarWei-Yin Chen (陳威尹) <wychen@chromium.org>
Reviewed-by: default avatarGanggui Tang <gogerald@chromium.org>
Cr-Commit-Position: refs/heads/master@{#689943}
parent 6d2d037d
......@@ -80,6 +80,7 @@ android_library("java") {
"java/src/org/chromium/chrome/features/start_surface/BottomBarCoordinator.java",
"java/src/org/chromium/chrome/features/start_surface/BottomBarView.java",
"java/src/org/chromium/chrome/features/start_surface/BottomBarViewBinder.java",
"java/src/org/chromium/chrome/features/start_surface/ReturnToStartSurfaceUtil.java",
"java/src/org/chromium/chrome/features/start_surface/StartSurfaceCoordinator.java",
"java/src/org/chromium/chrome/features/start_surface/StartSurfaceDelegate.java",
"java/src/org/chromium/chrome/features/start_surface/StartSurfaceLayout.java",
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.features.start_surface;
import android.content.Context;
import android.content.SharedPreferences;
import org.chromium.base.ContextUtils;
/**
* This is a utility class for managing the start surface when returning to Chrome.
*/
public final class ReturnToStartSurfaceUtil {
/** Preference to indicate whether explore pane was visible last in the start surface.*/
private static final String START_SURFACE_PREF_FILE_NAME = "start_surface";
private static final String EXPLORE_SURFACE_VISIBLE_LAST = "explore_surface_visible_last";
private ReturnToStartSurfaceUtil() {}
/**
* Determine if we should show the explore surface on returning to Chrome.
* @return whether the last pane shown in StartSurface was explore
*/
public static boolean shouldShowExploreSurface() {
return getSharedPreferences().getBoolean(EXPLORE_SURFACE_VISIBLE_LAST, false);
}
/**
* Preserve whether last active pane in the start surface was the explore surface.
* @param isVisible whether the explore surface is visible
*/
public static void setExploreSurfaceVisibleLast(boolean isVisible) {
getSharedPreferences().edit().putBoolean(EXPLORE_SURFACE_VISIBLE_LAST, isVisible).apply();
}
private static SharedPreferences getSharedPreferences() {
return ContextUtils.getApplicationContext().getSharedPreferences(
START_SURFACE_PREF_FILE_NAME, Context.MODE_PRIVATE);
}
}
......@@ -101,6 +101,15 @@ class StartSurfaceMediator
// Set the initial state.
updateIncognitoMode(tabModelSelector.isIncognitoSelected());
// Show explore surface if in TWO PANES mode and last visible pane was explore.
if (!onlyShowExploreSurface) {
boolean shouldShowExploreSurface =
ReturnToStartSurfaceUtil.shouldShowExploreSurface();
mPropertyModel.set(IS_EXPLORE_SURFACE_VISIBLE, shouldShowExploreSurface);
mPropertyModel.set(
BOTTOM_BAR_SELECTED_TAB_POSITION, (shouldShowExploreSurface ? 1 : 0));
}
}
mController.addOverviewModeObserver(this);
......@@ -249,6 +258,7 @@ class StartSurfaceMediator
// 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);
ReturnToStartSurfaceUtil.setExploreSurfaceVisibleLast(isVisible);
}
private void updateIncognitoMode(boolean isIncognito) {
......@@ -274,4 +284,4 @@ class StartSurfaceMediator
if (feedSurfaceCoordinator != null) feedSurfaceCoordinator.destroy();
mPropertyModel.set(FEED_SURFACE_COORDINATOR, null);
}
}
\ 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