Commit 6b93bd9a authored by Mia Glaese's avatar Mia Glaese Committed by Commit Bot

[ToolbarManager] Separate ExperimentalButton and IdentityDiscController

Bug: 1041475
Change-Id: I7fcf625aa0d037ebf655fa09170d0681cef8bb98
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2022925Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Reviewed-by: default avatarPatrick Noland <pnoland@chromium.org>
Commit-Queue: Mia Glaese <glamia@chromium.org>
Cr-Commit-Position: refs/heads/master@{#736849}
parent caf8eebf
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
<org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarView <org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarView
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/tab_switcher_toolbar" android:id="@+id/tab_switcher_toolbar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height_no_shadow" android:layout_height="@dimen/toolbar_height_no_shadow"
...@@ -47,12 +48,14 @@ ...@@ -47,12 +48,14 @@
android:paddingEnd="8dp" android:paddingEnd="8dp"
android:contentDescription="@string/accessibility_toolbar_btn_new_tab" /> android:contentDescription="@string/accessibility_toolbar_btn_new_tab" />
<include <org.chromium.ui.widget.ChromeImageButton
layout="@layout/experimental_toolbar_button" android:id="@+id/identity_disc_button"
android:id="@+id/experimental_toolbar_button_start"
android:layout_toStartOf="@+id/menu_anchor" android:layout_toStartOf="@+id/menu_anchor"
android:paddingStart="@dimen/start_surface_toolbar_button_padding_to_button"
android:paddingEnd="@dimen/start_surface_toolbar_button_padding_to_button"
style="@style/ToolbarButton" style="@style/ToolbarButton"
android:visibility="gone" /> android:visibility="gone"
tools:ignore="ContentDescription"/>
<FrameLayout <FrameLayout
android:id="@+id/menu_anchor" android:id="@+id/menu_anchor"
......
...@@ -53,7 +53,7 @@ class IdentityDiscController implements NativeInitObserver, ProfileDataCache.Obs ...@@ -53,7 +53,7 @@ class IdentityDiscController implements NativeInitObserver, ProfileDataCache.Obs
// Context is used for fetching resources and launching preferences page. // Context is used for fetching resources and launching preferences page.
private final Context mContext; private final Context mContext;
// Toolbar manager exposes APIs for manipulating experimental button. // Toolbar manager exposes APIs for manipulating identity disc button.
private final ToolbarManager mToolbarManager; private final ToolbarManager mToolbarManager;
private ActivityLifecycleDispatcher mActivityLifecycleDispatcher; private ActivityLifecycleDispatcher mActivityLifecycleDispatcher;
...@@ -129,10 +129,10 @@ class IdentityDiscController implements NativeInitObserver, ProfileDataCache.Obs ...@@ -129,10 +129,10 @@ class IdentityDiscController implements NativeInitObserver, ProfileDataCache.Obs
showIdentityDisc(accountName); showIdentityDisc(accountName);
maybeShowIPH(); maybeShowIPH();
} else if (mState != oldState) { } else if (mState != oldState) {
mToolbarManager.updateExperimentalButtonImage(getProfileImage(accountName)); mToolbarManager.updateIdentityDiscButtonImage(getProfileImage(accountName));
} }
} else if (oldState != IdentityDiscState.NONE) { } else if (oldState != IdentityDiscState.NONE) {
mToolbarManager.disableExperimentalButton(); mToolbarManager.hideIdentityDiscButton();
} }
} }
...@@ -167,7 +167,7 @@ class IdentityDiscController implements NativeInitObserver, ProfileDataCache.Obs ...@@ -167,7 +167,7 @@ class IdentityDiscController implements NativeInitObserver, ProfileDataCache.Obs
* Triggers profile image fetch and displays Identity Disc on top toolbar. * Triggers profile image fetch and displays Identity Disc on top toolbar.
*/ */
private void showIdentityDisc(String accountName) { private void showIdentityDisc(String accountName) {
mToolbarManager.enableExperimentalButton(view -> { mToolbarManager.showIdentityDiscButton(view -> {
recordIdentityDiscUsed(); recordIdentityDiscUsed();
SettingsLauncher.getInstance().launchSettingsPage( SettingsLauncher.getInstance().launchSettingsPage(
mContext, SyncAndServicesSettings.class); mContext, SyncAndServicesSettings.class);
...@@ -188,7 +188,7 @@ class IdentityDiscController implements NativeInitObserver, ProfileDataCache.Obs ...@@ -188,7 +188,7 @@ class IdentityDiscController implements NativeInitObserver, ProfileDataCache.Obs
} }
if (mState != IdentityDiscState.NONE) { if (mState != IdentityDiscState.NONE) {
mState = IdentityDiscState.NONE; mState = IdentityDiscState.NONE;
mToolbarManager.disableExperimentalButton(); mToolbarManager.hideIdentityDiscButton();
} }
} }
...@@ -202,7 +202,7 @@ class IdentityDiscController implements NativeInitObserver, ProfileDataCache.Obs ...@@ -202,7 +202,7 @@ class IdentityDiscController implements NativeInitObserver, ProfileDataCache.Obs
String accountName = ChromeSigninController.get().getSignedInAccountName(); String accountName = ChromeSigninController.get().getSignedInAccountName();
if (accountId.equals(accountName)) { if (accountId.equals(accountName)) {
mToolbarManager.updateExperimentalButtonImage(getProfileImage(accountName)); mToolbarManager.updateIdentityDiscButtonImage(getProfileImage(accountName));
} }
} }
...@@ -247,7 +247,7 @@ class IdentityDiscController implements NativeInitObserver, ProfileDataCache.Obs ...@@ -247,7 +247,7 @@ class IdentityDiscController implements NativeInitObserver, ProfileDataCache.Obs
Tracker tracker = TrackerFactory.getTrackerForProfile(profile); Tracker tracker = TrackerFactory.getTrackerForProfile(profile);
if (!tracker.shouldTriggerHelpUI(FeatureConstants.IDENTITY_DISC_FEATURE)) return; if (!tracker.shouldTriggerHelpUI(FeatureConstants.IDENTITY_DISC_FEATURE)) return;
mToolbarManager.showIPHOnExperimentalButton(R.string.iph_identity_disc_text, mToolbarManager.showIPHOnIdentityDiscButton(R.string.iph_identity_disc_text,
R.string.iph_identity_disc_accessibility_text, R.string.iph_identity_disc_accessibility_text,
() -> { tracker.dismissed(FeatureConstants.IDENTITY_DISC_FEATURE); }); () -> { tracker.dismissed(FeatureConstants.IDENTITY_DISC_FEATURE); });
} }
......
...@@ -1088,6 +1088,43 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF ...@@ -1088,6 +1088,43 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
mToolbar.showIPHOnExperimentalButton(stringId, accessibilityStringId, dismissedCallback); mToolbar.showIPHOnExperimentalButton(stringId, accessibilityStringId, dismissedCallback);
} }
/**
* Show the identity disc toolbar button.
* @param onClickListener The {@link OnClickListener} to be called when the button is clicked.
* @param image The drawable to display for the button.
* @param contentDescriptionResId The resource id of the content description for the button.
*/
public void showIdentityDiscButton(OnClickListener onClickListener, Drawable image,
@StringRes int contentDescriptionResId) {
mToolbar.showIdentityDiscButton(onClickListener, image, contentDescriptionResId);
}
/**
* Hide the identity disc toolbar button.
*/
public void hideIdentityDiscButton() {
mToolbar.hideIdentityDiscButton();
}
/**
* Updates image displayed on identity disc button.
* @param image The drawable to display for the button.
*/
public void updateIdentityDiscButtonImage(Drawable image) {
mToolbar.updateIdentityDiscButtonImage(image);
}
/**
* Displays in-product help for the identity disc button.
* @param stringId The id of the string resource for the text that should be shown.
* @param accessibilityStringId The id of the string resource of the accessibility text.
* @param dismissedCallback The callback that will be called when in-product help is dismissed.
*/
public void showIPHOnIdentityDiscButton(@StringRes int stringId,
@StringRes int accessibilityStringId, Runnable dismissedCallback) {
mToolbar.showIPHOnIdentityDiscButton(stringId, accessibilityStringId, dismissedCallback);
}
/** /**
* @return The bookmarks bridge. * @return The bookmarks bridge.
*/ */
......
...@@ -118,38 +118,38 @@ class StartSurfaceToolbarCoordinator { ...@@ -118,38 +118,38 @@ class StartSurfaceToolbarCoordinator {
} }
/** /**
* Enable the experimental toolbar button. * Show the identity dics button.
* @param onClickListener The {@link OnClickListener} to be called when the button is clicked. * @param onClickListener The {@link OnClickListener} to be called when the button is clicked.
* @param image The drawable to display for the button. * @param image The drawable to display for the button.
* @param contentDescriptionResId The resource id of the content description for the button. * @param contentDescriptionResId The resource id of the content description for the button.
*/ */
void enableExperimentalButton(View.OnClickListener onClickListener, Drawable image, void showIdentityDiscButton(View.OnClickListener onClickListener, Drawable image,
@StringRes int contentDescriptionResId) { @StringRes int contentDescriptionResId) {
mToolbarMediator.enableIdentityDisc(onClickListener, image, contentDescriptionResId); mToolbarMediator.showIdentityDisc(onClickListener, image, contentDescriptionResId);
} }
/** /**
* Updates image displayed on experimental button. * Updates image displayed on identity disc button.
* @param image The new image for the button. * @param image The new image for the button.
*/ */
void updateExperimentalButtonImage(Drawable image) { void updateIdentityDiscButtonImage(Drawable image) {
mToolbarMediator.updateIdentityDiscImage(image); mToolbarMediator.updateIdentityDiscImage(image);
} }
/** /**
* Disable the experimental toolbar button. * Hide the identity disc button.
*/ */
void disableExperimentalButton() { void hideIdentityDiscButton() {
mToolbarMediator.disableIdentityDisc(); mToolbarMediator.hideIdentityDisc();
} }
/** /**
* Displays in-product help for experimental button. * Displays in-product help for identity disc button.
* @param stringId The id of the string resource for the text that should be shown. * @param stringId The id of the string resource for the text that should be shown.
* @param accessibilityStringId The id of the string resource of the accessibility text. * @param accessibilityStringId The id of the string resource of the accessibility text.
* @param dismissedCallback The callback that will be called when in-product help is dismissed. * @param dismissedCallback The callback that will be called when in-product help is dismissed.
*/ */
void showIPHOnExperimentalButton(@StringRes int stringId, @StringRes int accessibilityStringId, void showIPHOnIdentityDiscButton(@StringRes int stringId, @StringRes int accessibilityStringId,
Runnable dismissedCallback) { Runnable dismissedCallback) {
mToolbarMediator.showIPHOnIdentityDisc(stringId, accessibilityStringId, dismissedCallback); mToolbarMediator.showIPHOnIdentityDisc(stringId, accessibilityStringId, dismissedCallback);
} }
......
...@@ -193,7 +193,7 @@ class StartSurfaceToolbarMediator { ...@@ -193,7 +193,7 @@ class StartSurfaceToolbarMediator {
mPropertyModel.set(LOGO_IS_VISIBLE, shouldShowLogo); mPropertyModel.set(LOGO_IS_VISIBLE, shouldShowLogo);
} }
void enableIdentityDisc(View.OnClickListener onClickListener, Drawable image, void showIdentityDisc(View.OnClickListener onClickListener, Drawable image,
@StringRes int contentDescriptionResId) { @StringRes int contentDescriptionResId) {
mEnableIdentityDisc = true; mEnableIdentityDisc = true;
mPropertyModel.set(IDENTITY_DISC_CLICK_HANDLER, onClickListener); mPropertyModel.set(IDENTITY_DISC_CLICK_HANDLER, onClickListener);
...@@ -206,7 +206,7 @@ class StartSurfaceToolbarMediator { ...@@ -206,7 +206,7 @@ class StartSurfaceToolbarMediator {
mPropertyModel.set(IDENTITY_DISC_IMAGE, image); mPropertyModel.set(IDENTITY_DISC_IMAGE, image);
} }
void disableIdentityDisc() { void hideIdentityDisc() {
mEnableIdentityDisc = false; mEnableIdentityDisc = false;
mPropertyModel.set(IDENTITY_DISC_IS_VISIBLE, false); mPropertyModel.set(IDENTITY_DISC_IS_VISIBLE, false);
} }
......
...@@ -56,13 +56,7 @@ class StartSurfaceToolbarView extends RelativeLayout { ...@@ -56,13 +56,7 @@ class StartSurfaceToolbarView extends RelativeLayout {
mIncognitoSwitch = findViewById(R.id.incognito_switch); mIncognitoSwitch = findViewById(R.id.incognito_switch);
mMenuButton = findViewById(R.id.menu_button_wrapper); mMenuButton = findViewById(R.id.menu_button_wrapper);
mLogo = findViewById(R.id.logo); mLogo = findViewById(R.id.logo);
mIdentityDiscButton = findViewById(R.id.experimental_toolbar_button_start); mIdentityDiscButton = findViewById(R.id.identity_disc_button);
// Change padding in layout file programmatically, since padding in layout file can not be
// changed in ViewStub.
final int buttonPadding = getContext().getResources().getDimensionPixelOffset(
R.dimen.start_surface_toolbar_button_padding_to_button);
mIdentityDiscButton.setPadding(buttonPadding, 0, buttonPadding, 0);
updatePrimaryColorAndTint(false); updatePrimaryColorAndTint(false);
} }
......
...@@ -625,11 +625,6 @@ public class TopToolbarCoordinator implements Toolbar { ...@@ -625,11 +625,6 @@ public class TopToolbarCoordinator implements Toolbar {
*/ */
public void enableExperimentalButton(View.OnClickListener onClickListener, Drawable image, public void enableExperimentalButton(View.OnClickListener onClickListener, Drawable image,
@StringRes int contentDescriptionResId) { @StringRes int contentDescriptionResId) {
if (mStartSurfaceToolbarCoordinator != null
&& FeatureUtilities.isStartSurfaceSinglePaneEnabled()) {
mStartSurfaceToolbarCoordinator.enableExperimentalButton(
onClickListener, image, contentDescriptionResId);
}
mToolbarLayout.enableExperimentalButton(onClickListener, image, contentDescriptionResId); mToolbarLayout.enableExperimentalButton(onClickListener, image, contentDescriptionResId);
} }
...@@ -649,10 +644,6 @@ public class TopToolbarCoordinator implements Toolbar { ...@@ -649,10 +644,6 @@ public class TopToolbarCoordinator implements Toolbar {
* @return The experimental toolbar button if it exists. * @return The experimental toolbar button if it exists.
*/ */
public void updateExperimentalButtonImage(Drawable image) { public void updateExperimentalButtonImage(Drawable image) {
if (mStartSurfaceToolbarCoordinator != null
&& FeatureUtilities.isStartSurfaceSinglePaneEnabled()) {
mStartSurfaceToolbarCoordinator.updateExperimentalButtonImage(image);
}
mToolbarLayout.updateExperimentalButtonImage(image); mToolbarLayout.updateExperimentalButtonImage(image);
} }
...@@ -660,10 +651,6 @@ public class TopToolbarCoordinator implements Toolbar { ...@@ -660,10 +651,6 @@ public class TopToolbarCoordinator implements Toolbar {
* Disable the experimental toolbar button. * Disable the experimental toolbar button.
*/ */
public void disableExperimentalButton() { public void disableExperimentalButton() {
if (mStartSurfaceToolbarCoordinator != null
&& FeatureUtilities.isStartSurfaceSinglePaneEnabled()) {
mStartSurfaceToolbarCoordinator.disableExperimentalButton();
}
mToolbarLayout.disableExperimentalButton(); mToolbarLayout.disableExperimentalButton();
} }
...@@ -675,14 +662,63 @@ public class TopToolbarCoordinator implements Toolbar { ...@@ -675,14 +662,63 @@ public class TopToolbarCoordinator implements Toolbar {
*/ */
public void showIPHOnExperimentalButton(@StringRes int stringId, public void showIPHOnExperimentalButton(@StringRes int stringId,
@StringRes int accessibilityStringId, Runnable dismissedCallback) { @StringRes int accessibilityStringId, Runnable dismissedCallback) {
mToolbarLayout.showIPHOnExperimentalButton(
stringId, accessibilityStringId, dismissedCallback);
}
/**
* Show the identity disc toolbar button.
* @param onClickListener The {@link OnClickListener} to be called when the button is clicked.
* @param image The drawable to display for the button.
* @param contentDescriptionResId The resource id of the content description for the button.
*/
public void showIdentityDiscButton(OnClickListener onClickListener, Drawable image,
@StringRes int contentDescriptionResId) {
if (mStartSurfaceToolbarCoordinator != null
&& FeatureUtilities.isStartSurfaceSinglePaneEnabled()) {
mStartSurfaceToolbarCoordinator.showIdentityDiscButton(
onClickListener, image, contentDescriptionResId);
}
enableExperimentalButton(onClickListener, image, contentDescriptionResId);
}
/**
* Hide the identity disc toolbar button.
*/
public void hideIdentityDiscButton() {
if (mStartSurfaceToolbarCoordinator != null
&& FeatureUtilities.isStartSurfaceSinglePaneEnabled()) {
mStartSurfaceToolbarCoordinator.hideIdentityDiscButton();
}
disableExperimentalButton();
}
/**
* Updates image displayed on identity disc button.
*/
public void updateIdentityDiscButtonImage(Drawable image) {
if (mStartSurfaceToolbarCoordinator != null
&& FeatureUtilities.isStartSurfaceSinglePaneEnabled()) {
mStartSurfaceToolbarCoordinator.updateIdentityDiscButtonImage(image);
}
updateExperimentalButtonImage(image);
}
/**
* Displays in-product help for the identity disc button.
* @param stringId The id of the string resource for the text that should be shown.
* @param accessibilityStringId The id of the string resource of the accessibility text.
* @param dismissedCallback The callback that will be called when in-product help is dismissed.
*/
public void showIPHOnIdentityDiscButton(@StringRes int stringId,
@StringRes int accessibilityStringId, Runnable dismissedCallback) {
if (mStartSurfaceToolbarCoordinator != null if (mStartSurfaceToolbarCoordinator != null
&& mToolbarLayout.getToolbarDataProvider().isInOverviewAndShowingOmnibox()) { && mToolbarLayout.getToolbarDataProvider().isInOverviewAndShowingOmnibox()) {
mStartSurfaceToolbarCoordinator.showIPHOnExperimentalButton( mStartSurfaceToolbarCoordinator.showIPHOnIdentityDiscButton(
stringId, accessibilityStringId, dismissedCallback); stringId, accessibilityStringId, dismissedCallback);
return; return;
} }
mToolbarLayout.showIPHOnExperimentalButton( showIPHOnExperimentalButton(stringId, accessibilityStringId, dismissedCallback);
stringId, accessibilityStringId, dismissedCallback);
} }
@Override @Override
......
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