Commit df625483 authored by Ayman Almadhoun's avatar Ayman Almadhoun Committed by Commit Bot

Initial changes for Bottom Toolbar Compoenent.

This change contains the following:
1) Adds TabStripToolbarCoordinator/Mediator component.
2) Updates existing BottomTabGridCoordinator.
3) Replaces BottomTabGridSheetToolbarView with a generic BottomToolbarView.

Change-Id: I7687eb7cb69ca89656a7f85e2dc993ed23b9f508
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1500876
Commit-Queue: Ayman Almadhoun <ayman@chromium.org>
Auto-Submit: Ayman Almadhoun <ayman@chromium.org>
Reviewed-by: default avatarYusuf Ozuysal <yusufo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#637952}
parent 098f6d08
...@@ -293,3 +293,6 @@ vs-chromium-project.txt ...@@ -293,3 +293,6 @@ vs-chromium-project.txt
# Ignore any Android RenderTest goldens # Ignore any Android RenderTest goldens
**/render_tests/*.png **/render_tests/*.png
# Ignore IntelliJ files.
.idea/
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
Use of this source code is governed by a BSD-style license that can be Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. --> found in the LICENSE file. -->
<org.chromium.chrome.browser.tasks.tab_list_ui.BottomTabGridSheetToolbarView <org.chromium.chrome.browser.tasks.tab_list_ui.BottomTabToolbarView
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" xmlns:tools="http://schemas.android.com/tools"
...@@ -17,11 +17,12 @@ ...@@ -17,11 +17,12 @@
android:gravity="center_vertical" android:gravity="center_vertical"
android:background="@color/modern_primary_color"> android:background="@color/modern_primary_color">
<org.chromium.chrome.browser.widget.ListMenuButton <org.chromium.chrome.browser.widget.ListMenuButton
android:id="@+id/collapse" android:id="@+id/toolbar_left_button"
android:layout_width="@dimen/bottom_tab_grid_toolbar_icon_size" android:layout_width="@dimen/bottom_tab_grid_toolbar_icon_size"
android:layout_height="match_parent" android:layout_height="match_parent"
android:src="@drawable/ic_expand_more_black_24dp" android:src="@drawable/ic_expand_more_black_24dp"
app:tint="@color/standard_mode_tint" app:tint="@color/standard_mode_tint"
android:background="?attr/selectableItemBackground"
android:contentDescription="@string/accessibility_collapse_section_header" /> android:contentDescription="@string/accessibility_collapse_section_header" />
<TextView <TextView
android:id="@+id/title" android:id="@+id/title"
...@@ -34,11 +35,12 @@ ...@@ -34,11 +35,12 @@
android:gravity="center" android:gravity="center"
android:focusableInTouchMode="true" /> android:focusableInTouchMode="true" />
<org.chromium.chrome.browser.widget.ListMenuButton <org.chromium.chrome.browser.widget.ListMenuButton
android:id="@+id/add" android:id="@+id/toolbar_right_button"
android:layout_width="@dimen/bottom_tab_grid_toolbar_icon_size" android:layout_width="@dimen/bottom_tab_grid_toolbar_icon_size"
android:layout_height="match_parent" android:layout_height="match_parent"
android:src="@drawable/plus" android:src="@drawable/plus"
app:tint="@color/standard_mode_tint" app:tint="@color/standard_mode_tint"
android:background="?attr/selectableItemBackground"
android:contentDescription="@string/bottom_tab_grid_new_tab" /> android:contentDescription="@string/bottom_tab_grid_new_tab" />
</LinearLayout> </LinearLayout>
</org.chromium.chrome.browser.tasks.tab_list_ui.BottomTabGridSheetToolbarView> </org.chromium.chrome.browser.tasks.tab_list_ui.BottomTabToolbarView>
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2018 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. -->
<org.chromium.chrome.browser.tasks.tab_list_ui.BottomTabToolbarView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_peek_height"
android:orientation="horizontal"
android:gravity="center_vertical"
android:background="@color/modern_primary_color">
<org.chromium.chrome.browser.widget.ListMenuButton
android:id="@+id/toolbar_left_button"
android:layout_width="@dimen/bottom_tab_grid_toolbar_icon_size"
android:layout_height="match_parent"
android:src="@drawable/ic_expand_less_black_24dp"
app:tint="@color/standard_mode_tint"
android:background="?attr/selectableItemBackground"
android:contentDescription="@string/accessibility_expand_section_header" />
<FrameLayout
android:id="@+id/toolbar_container_view"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/holo_orange_dark"
android:orientation="horizontal" />
<org.chromium.chrome.browser.widget.ListMenuButton
android:id="@+id/toolbar_right_button"
android:layout_width="@dimen/bottom_tab_grid_toolbar_icon_size"
android:layout_height="match_parent"
android:src="@drawable/plus"
app:tint="@color/standard_mode_tint"
android:background="?attr/selectableItemBackground"
android:contentDescription="@string/bottom_tab_grid_new_tab" />
</LinearLayout>
</org.chromium.chrome.browser.tasks.tab_list_ui.BottomTabToolbarView>
...@@ -4,13 +4,10 @@ ...@@ -4,13 +4,10 @@
package org.chromium.chrome.browser.tasks.tab_list_ui; package org.chromium.chrome.browser.tasks.tab_list_ui;
import static org.chromium.chrome.browser.dependency_injection.ChromeCommonQualifiers.ACTIVITY_CONTEXT;
import android.content.Context; import android.content.Context;
import org.chromium.chrome.browser.compositor.layouts.content.TabContentManager; import org.chromium.chrome.browser.compositor.layouts.content.TabContentManager;
import org.chromium.chrome.browser.dependency_injection.ActivityScope; import org.chromium.chrome.browser.dependency_injection.ActivityScope;
import org.chromium.chrome.browser.init.ActivityLifecycleDispatcher;
import org.chromium.chrome.browser.lifecycle.Destroyable; import org.chromium.chrome.browser.lifecycle.Destroyable;
import org.chromium.chrome.browser.tabmodel.TabCreatorManager; import org.chromium.chrome.browser.tabmodel.TabCreatorManager;
import org.chromium.chrome.browser.tabmodel.TabModel; import org.chromium.chrome.browser.tabmodel.TabModel;
...@@ -18,9 +15,6 @@ import org.chromium.chrome.browser.tabmodel.TabModelSelector; ...@@ -18,9 +15,6 @@ import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetController; import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetController;
import org.chromium.ui.modelutil.PropertyModel; import org.chromium.ui.modelutil.PropertyModel;
import javax.inject.Inject;
import javax.inject.Named;
/** /**
* A coordinator for BottomTabGrid component. Manages the communication with * A coordinator for BottomTabGrid component. Manages the communication with
* {@link TabListCoordinator} as well as the life-cycle of shared component * {@link TabListCoordinator} as well as the life-cycle of shared component
...@@ -29,17 +23,14 @@ import javax.inject.Named; ...@@ -29,17 +23,14 @@ import javax.inject.Named;
@ActivityScope @ActivityScope
public class BottomTabGridCoordinator implements Destroyable { public class BottomTabGridCoordinator implements Destroyable {
private final Context mContext; private final Context mContext;
private final ActivityLifecycleDispatcher mLifecycleDispatcher;
private final TabListCoordinator mTabGridCoordinator; private final TabListCoordinator mTabGridCoordinator;
private final BottomTabGridMediator mMediator; private final BottomTabGridMediator mMediator;
private BottomTabGridSheetContent mBottomSheetContent; private BottomTabGridSheetContent mBottomSheetContent;
private BottomTabGridSheetToolbarCoordinator mToolbarCoordinator; private BottomTabGridSheetToolbarCoordinator mToolbarCoordinator;
private final PropertyModel mToolbarPropertyModel; private final PropertyModel mToolbarPropertyModel;
@Inject BottomTabGridCoordinator(Context context, BottomSheetController bottomSheetController,
BottomTabGridCoordinator(@Named(ACTIVITY_CONTEXT) Context context, TabModelSelector tabModelSelector, TabContentManager tabContentManager,
BottomSheetController bottomSheetController, TabModelSelector tabModelSelector,
TabContentManager tabContentManager, ActivityLifecycleDispatcher lifecycleDispatcher,
TabCreatorManager tabCreatorManager) { TabCreatorManager tabCreatorManager) {
mContext = context; mContext = context;
...@@ -51,9 +42,6 @@ public class BottomTabGridCoordinator implements Destroyable { ...@@ -51,9 +42,6 @@ public class BottomTabGridCoordinator implements Destroyable {
mMediator = mMediator =
new BottomTabGridMediator(mContext, bottomSheetController, this::resetWithTabModel, new BottomTabGridMediator(mContext, bottomSheetController, this::resetWithTabModel,
mToolbarPropertyModel, tabModelSelector, tabCreatorManager); mToolbarPropertyModel, tabModelSelector, tabCreatorManager);
mLifecycleDispatcher = lifecycleDispatcher;
mLifecycleDispatcher.register(this);
} }
/** /**
...@@ -71,8 +59,6 @@ public class BottomTabGridCoordinator implements Destroyable { ...@@ -71,8 +59,6 @@ public class BottomTabGridCoordinator implements Destroyable {
if (mToolbarCoordinator != null) { if (mToolbarCoordinator != null) {
mToolbarCoordinator.destroy(); mToolbarCoordinator.destroy();
} }
mLifecycleDispatcher.unregister(this);
} }
/** /**
......
...@@ -19,7 +19,7 @@ import org.chromium.ui.modelutil.PropertyModelChangeProcessor; ...@@ -19,7 +19,7 @@ import org.chromium.ui.modelutil.PropertyModelChangeProcessor;
* grid when presented inside the bottom sheet. {@link BottomTabGridCoordinator} * grid when presented inside the bottom sheet. {@link BottomTabGridCoordinator}
*/ */
class BottomTabGridSheetToolbarCoordinator implements Destroyable { class BottomTabGridSheetToolbarCoordinator implements Destroyable {
private final BottomTabGridSheetToolbarView mToolbarView; private final BottomTabListToolbarView mToolbarView;
private final PropertyModelChangeProcessor mModelChangeProcessor; private final PropertyModelChangeProcessor mModelChangeProcessor;
/** /**
...@@ -33,7 +33,7 @@ class BottomTabGridSheetToolbarCoordinator implements Destroyable { ...@@ -33,7 +33,7 @@ class BottomTabGridSheetToolbarCoordinator implements Destroyable {
*/ */
BottomTabGridSheetToolbarCoordinator( BottomTabGridSheetToolbarCoordinator(
Context context, ViewGroup parentView, PropertyModel toolbarPropertyModel) { Context context, ViewGroup parentView, PropertyModel toolbarPropertyModel) {
mToolbarView = (BottomTabGridSheetToolbarView) LayoutInflater.from(context).inflate( mToolbarView = (BottomTabListToolbarView) LayoutInflater.from(context).inflate(
R.layout.bottom_tab_grid_toolbar, parentView, false); R.layout.bottom_tab_grid_toolbar, parentView, false);
mModelChangeProcessor = PropertyModelChangeProcessor.create( mModelChangeProcessor = PropertyModelChangeProcessor.create(
toolbarPropertyModel, mToolbarView, BottomTabGridSheetToolbarViewBinder::bind); toolbarPropertyModel, mToolbarView, BottomTabGridSheetToolbarViewBinder::bind);
......
...@@ -22,11 +22,11 @@ class BottomTabGridSheetToolbarViewBinder { ...@@ -22,11 +22,11 @@ class BottomTabGridSheetToolbarViewBinder {
* @param propertyKey The key for the property to update for. * @param propertyKey The key for the property to update for.
*/ */
public static void bind( public static void bind(
PropertyModel model, BottomTabGridSheetToolbarView view, PropertyKey propertyKey) { PropertyModel model, BottomTabListToolbarView view, PropertyKey propertyKey) {
if (COLLAPSE_CLICK_LISTENER == propertyKey) { if (COLLAPSE_CLICK_LISTENER == propertyKey) {
view.setCollapseButtonOnClickListener(model.get(COLLAPSE_CLICK_LISTENER)); view.setLeftButtonOnClickListener(model.get(COLLAPSE_CLICK_LISTENER));
} else if (ADD_CLICK_LISTENER == propertyKey) { } else if (ADD_CLICK_LISTENER == propertyKey) {
view.setAddButtonOnClickListener(model.get(ADD_CLICK_LISTENER)); view.setRightButtonOnClickListener(model.get(ADD_CLICK_LISTENER));
} else if (HEADER_TITLE == propertyKey) { } else if (HEADER_TITLE == propertyKey) {
view.setTitle(model.get(HEADER_TITLE)); view.setTitle(model.get(HEADER_TITLE));
} }
......
...@@ -6,6 +6,8 @@ package org.chromium.chrome.browser.tasks.tab_list_ui; ...@@ -6,6 +6,8 @@ package org.chromium.chrome.browser.tasks.tab_list_ui;
import android.content.Context; import android.content.Context;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.TextView; import android.widget.TextView;
...@@ -13,15 +15,16 @@ import org.chromium.chrome.R; ...@@ -13,15 +15,16 @@ import org.chromium.chrome.R;
import org.chromium.chrome.browser.widget.ListMenuButton; import org.chromium.chrome.browser.widget.ListMenuButton;
/** /**
* Represents the toolbar in bottom tab grid sheet. * Represents a generic toolbar used in the bottom strip/grid component.
* {@link BottomTabGridSheetToolbarCoordinator} * {@link BottomTabGridSheetToolbarCoordinator}
*/ */
public class BottomTabGridSheetToolbarView extends FrameLayout { public class BottomTabListToolbarView extends FrameLayout {
private ListMenuButton mCollapseButton; private ListMenuButton mRightButton;
private ListMenuButton mAddButton; private ListMenuButton mLeftButton;
private TextView mTitle; private ViewGroup mContainerView;
private TextView mTitleTextView;
public BottomTabGridSheetToolbarView(Context context, AttributeSet attrs) { public BottomTabListToolbarView(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
} }
...@@ -29,20 +32,38 @@ public class BottomTabGridSheetToolbarView extends FrameLayout { ...@@ -29,20 +32,38 @@ public class BottomTabGridSheetToolbarView extends FrameLayout {
protected void onFinishInflate() { protected void onFinishInflate() {
super.onFinishInflate(); super.onFinishInflate();
mAddButton = findViewById(R.id.add); mLeftButton = findViewById(R.id.toolbar_left_button);
mCollapseButton = findViewById(R.id.collapse); mRightButton = findViewById(R.id.toolbar_right_button);
mTitle = (TextView) findViewById(R.id.title); mContainerView = (ViewGroup) findViewById(R.id.toolbar_container_view);
mTitleTextView = (TextView) findViewById(R.id.title);
} }
void setCollapseButtonOnClickListener(OnClickListener listener) { void setLeftButtonOnClickListener(OnClickListener listener) {
mCollapseButton.setOnClickListener(listener); mLeftButton.setOnClickListener(listener);
} }
void setAddButtonOnClickListener(OnClickListener listener) { void setRightButtonOnClickListener(OnClickListener listener) {
mAddButton.setOnClickListener(listener); mRightButton.setOnClickListener(listener);
}
ViewGroup getViewContainer() {
return mContainerView;
}
void setMainContentVisibility(boolean isVisible) {
if (mContainerView == null)
throw new IllegalStateException("Current Toolbar doesn't have a container view");
for (int i = 0; i < ((ViewGroup) mContainerView).getChildCount(); i++) {
View child = ((ViewGroup) mContainerView).getChildAt(i);
child.setVisibility(isVisible ? View.VISIBLE : View.INVISIBLE);
}
} }
void setTitle(String title) { void setTitle(String title) {
mTitle.setText(title); if (mTitleTextView == null)
throw new IllegalStateException("Current Toolbar doesn't have a title text view");
mTitleTextView.setText(title);
} }
} }
// Copyright 2018 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.browser.tasks.tab_list_ui;
import static org.chromium.chrome.browser.tasks.tab_list_ui.TabStripToolbarViewProperties.ADD_CLICK_LISTENER;
import static org.chromium.chrome.browser.tasks.tab_list_ui.TabStripToolbarViewProperties.EXPAND_CLICK_LISTENER;
import static org.chromium.chrome.browser.tasks.tab_list_ui.TabStripToolbarViewProperties.IS_MAIN_CONTENT_VISIBLE;
import org.chromium.ui.modelutil.PropertyKey;
import org.chromium.ui.modelutil.PropertyModel;
/**
* ViewBinder for BottomTabStripToolbar.
*/
class BottomTabStripToolbarViewBinder {
/**
* Binds the given model to the given view, updating the payload in propertyKey.
*
* @param model The model to use.
* @param view The view to use.
* @param propertyKey The key for the property to update for.
*/
public static void bind(
PropertyModel model, BottomTabListToolbarView view, PropertyKey propertyKey) {
if (EXPAND_CLICK_LISTENER == propertyKey) {
view.setLeftButtonOnClickListener(model.get(EXPAND_CLICK_LISTENER));
} else if (ADD_CLICK_LISTENER == propertyKey) {
view.setRightButtonOnClickListener(model.get(ADD_CLICK_LISTENER));
} else if (IS_MAIN_CONTENT_VISIBLE == propertyKey) {
view.setMainContentVisibility(model.get(IS_MAIN_CONTENT_VISIBLE));
}
}
}
// 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.browser.tasks.tab_list_ui;
import static org.chromium.chrome.browser.dependency_injection.ChromeCommonQualifiers.ACTIVITY_CONTEXT;
import android.content.Context;
import android.view.ViewGroup;
import android.view.ViewStub;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.compositor.layouts.content.TabContentManager;
import org.chromium.chrome.browser.dependency_injection.ActivityScope;
import org.chromium.chrome.browser.init.ActivityLifecycleDispatcher;
import org.chromium.chrome.browser.lifecycle.Destroyable;
import org.chromium.chrome.browser.tabmodel.TabCreatorManager;
import org.chromium.chrome.browser.tabmodel.TabModel;
import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetController;
import org.chromium.ui.modelutil.PropertyModel;
import javax.inject.Inject;
import javax.inject.Named;
/**
* A coordinator for BottomTabStrip component. Manages the communication with
* {@link TabListCoordinator} & @{link BottomTabGridCoordinator} as well as the
* life-cycle of shared component objects.
*/
@ActivityScope
public class TabStripBottomToolbarCoordinator
implements Destroyable, TabStripBottomToolbarMediator.ResetHandler {
private final ActivityLifecycleDispatcher mLifecycleDispatcher;
private final Context mContext;
private final PropertyModel mTabStripToolbarModel;
private BottomSheetController mBottomSheetController;
private BottomTabGridCoordinator mBottomTabGridCoordinator;
private TabContentManager mTabContentManager;
private TabCreatorManager mTabCreatorManager;
private TabListCoordinator mTabStripCoordinator;
private TabModelSelector mTabModelSelector;
private TabStripBottomToolbarMediator mMediator;
private TabStripToolbarCoordinator mTabStripToolbarCoordinator;
/**
* Creates a new {@link TabStripBottomToolbarCoordinator}
*/
@Inject
public TabStripBottomToolbarCoordinator(@Named(ACTIVITY_CONTEXT) Context context,
ChromeActivity activity, ActivityLifecycleDispatcher lifecycleDispatcher) {
mContext = context;
mLifecycleDispatcher = lifecycleDispatcher;
mTabStripToolbarModel = new PropertyModel(TabStripToolbarViewProperties.ALL_KEYS);
ViewStub stub = activity.findViewById(R.id.bottom_toolbar_stub);
mTabStripToolbarCoordinator = new TabStripToolbarCoordinator(
mContext, (ViewGroup) stub.inflate(), mTabStripToolbarModel);
mLifecycleDispatcher.register(this);
}
/**
* Handle any initialization that occurs once native has been loaded.
*/
public void initializeWithNative(TabModelSelector tabModelSelector,
TabContentManager tabContentManager, TabCreatorManager tabCreatorManager,
BottomSheetController bottomSheetController) {
mTabModelSelector = tabModelSelector;
mTabContentManager = tabContentManager;
mTabCreatorManager = tabCreatorManager;
mBottomSheetController = bottomSheetController;
mTabStripCoordinator = new TabListCoordinator(TabListCoordinator.TabListMode.STRIP,
mContext, mTabModelSelector, mTabContentManager,
mTabStripToolbarCoordinator.getTabListContainerView(), true);
mBottomTabGridCoordinator = new BottomTabGridCoordinator(mContext, mBottomSheetController,
mTabModelSelector, mTabContentManager, mTabCreatorManager);
mMediator = new TabStripBottomToolbarMediator(
this, mTabStripToolbarModel, mTabModelSelector, mTabCreatorManager);
}
/**
* Handles a reset event originated from {@link TabStripBottomToolbarMediator}
* when the bottom sheet is collaped.
*
* @param tabModel current {@link TabModel} instance.
*/
@Override
public void resetStripWithTabModel(TabModel tabModel) {
mTabStripCoordinator.resetWithTabModel(tabModel);
mMediator.resetWithTabModel(tabModel);
}
/**
* Handles a reset event originated from {@link TabStripBottomToolbarMediator}
* when the bottom sheet is expanded and the component.
*
* @param tabModel current {@link TabModel} instance.
*/
@Override
public void resetSheetWithTabModel(TabModel tabModel) {
mBottomTabGridCoordinator.resetWithTabModel(tabModel);
}
/**
* Destroy any members that needs clean up.
*/
@Override
public void destroy() {
mTabStripCoordinator.destroy();
mBottomTabGridCoordinator.destroy();
mMediator.destroy();
mLifecycleDispatcher.unregister(this);
}
}
// 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.browser.tasks.tab_list_ui;
import android.view.View.OnClickListener;
import org.chromium.chrome.browser.UrlConstants;
import org.chromium.chrome.browser.lifecycle.Destroyable;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tabmodel.TabCreatorManager;
import org.chromium.chrome.browser.tabmodel.TabLaunchType;
import org.chromium.chrome.browser.tabmodel.TabModel;
import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.tabmodel.TabModelSelectorTabModelObserver;
import org.chromium.chrome.browser.tabmodel.TabModelUtils;
import org.chromium.chrome.browser.tabmodel.TabSelectionType;
import org.chromium.content_public.browser.LoadUrlParams;
import org.chromium.ui.modelutil.PropertyModel;
/**
* A mediator for the TabStripBottomToolbar. Responsible for managing the
* internal state of the component.
*/
public class TabStripBottomToolbarMediator implements Destroyable {
/**
* Defines an interface for a {@link TabStripBottomToolbarMediator} reset event
* handler.
*/
interface ResetHandler {
/**
* Handles a reset event originated from {@link TabStripBottomToolbarMediator}
* when the bottom sheet is collaped.
*
* @param tabModel current {@link TabModel} instance.
*/
void resetStripWithTabModel(TabModel tabModel);
/**
* Handles a reset event originated from {@link TabStripBottomToolbarMediator}
* when the bottom sheet is expanded and the component.
*
* @param tabModel current {@link TabModel} instance.
*/
void resetSheetWithTabModel(TabModel tabModel);
}
private final PropertyModel mToolbarPropertyModel;
private final TabModelSelectorTabModelObserver mTabModelObserver;
private final ResetHandler mResetHandler;
private final TabModelSelector mTabModelSelector;
private final TabCreatorManager mTabCreatorManager;
TabStripBottomToolbarMediator(ResetHandler resetHandler, PropertyModel toolbarPropertyModel,
TabModelSelector tabModelSelector, TabCreatorManager tabCreatorManager) {
mResetHandler = resetHandler;
mToolbarPropertyModel = toolbarPropertyModel;
mTabModelSelector = tabModelSelector;
mTabCreatorManager = tabCreatorManager;
// register for tab model
mTabModelObserver = new TabModelSelectorTabModelObserver(tabModelSelector) {
@Override
public void didSelectTab(Tab tab, @TabSelectionType int type, int lastId) {
if (TabModelUtils.getTabById(tabModelSelector.getCurrentModel(), lastId) != null)
return;
mResetHandler.resetStripWithTabModel(tabModelSelector.getCurrentModel());
}
};
setupToolbarClickHandlers();
mResetHandler.resetStripWithTabModel(tabModelSelector.getCurrentModel());
}
void resetWithTabModel(TabModel tabModel) {
mToolbarPropertyModel.set(TabStripToolbarViewProperties.IS_MAIN_CONTENT_VISIBLE, true);
}
private void setupToolbarClickHandlers() {
mToolbarPropertyModel.set(TabStripToolbarViewProperties.EXPAND_CLICK_LISTENER, view -> {
mResetHandler.resetSheetWithTabModel(mTabModelSelector.getCurrentModel());
});
mToolbarPropertyModel.set(TabStripToolbarViewProperties.ADD_CLICK_LISTENER, view -> {
Tab currentTab = mTabModelSelector.getCurrentTab();
mTabCreatorManager.getTabCreator(currentTab.isIncognito())
.createNewTab(new LoadUrlParams(UrlConstants.NTP_URL), TabLaunchType.FROM_LINK,
currentTab);
});
}
private OnClickListener getExpandButtonClickListener() {
return view -> {
mResetHandler.resetSheetWithTabModel(mTabModelSelector.getCurrentModel());
};
}
private OnClickListener getAddButtonClickListener() {
return view -> {
Tab currentTab = mTabModelSelector.getCurrentTab();
mTabCreatorManager.getTabCreator(currentTab.isIncognito())
.createNewTab(new LoadUrlParams(UrlConstants.NTP_URL), TabLaunchType.FROM_LINK,
currentTab);
};
}
@Override
public void destroy() {
mTabModelObserver.destroy();
}
}
// 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.browser.tasks.tab_list_ui;
import static org.chromium.chrome.browser.dependency_injection.ChromeCommonQualifiers.ACTIVITY_CONTEXT;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.lifecycle.Destroyable;
import org.chromium.ui.modelutil.PropertyModel;
import org.chromium.ui.modelutil.PropertyModelChangeProcessor;
import javax.inject.Named;
/**
* A coordinator for BottomTabStripToolbar component.
*/
public class TabStripToolbarCoordinator implements Destroyable {
private final BottomTabListToolbarView mToolbarView;
private final PropertyModel mModel;
private final PropertyModelChangeProcessor mModelChangeProcessor;
TabStripToolbarCoordinator(
@Named(ACTIVITY_CONTEXT) Context context, ViewGroup parentView, PropertyModel model) {
mModel = model;
mToolbarView = (BottomTabListToolbarView) LayoutInflater.from(context).inflate(
R.layout.bottom_tab_strip_toolbar, parentView, false);
parentView.addView(mToolbarView);
mModelChangeProcessor = PropertyModelChangeProcessor.create(
model, mToolbarView, BottomTabStripToolbarViewBinder::bind);
}
View getView() {
return mToolbarView;
}
ViewGroup getTabListContainerView() {
return mToolbarView.getViewContainer();
}
/**
* Destroy any members that needs clean up.
*/
@Override
public void destroy() {
mModelChangeProcessor.destroy();
}
}
// 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.browser.tasks.tab_list_ui;
import android.view.View.OnClickListener;
import org.chromium.ui.modelutil.PropertyKey;
import org.chromium.ui.modelutil.PropertyModel;
class TabStripToolbarViewProperties {
public static final PropertyModel
.WritableObjectPropertyKey<OnClickListener> EXPAND_CLICK_LISTENER =
new PropertyModel.WritableObjectPropertyKey<OnClickListener>();
public static final PropertyModel
.WritableObjectPropertyKey<OnClickListener> ADD_CLICK_LISTENER =
new PropertyModel.WritableObjectPropertyKey<OnClickListener>();
public static final PropertyModel.WritableBooleanPropertyKey IS_MAIN_CONTENT_VISIBLE =
new PropertyModel.WritableBooleanPropertyKey();
public static final PropertyKey[] ALL_KEYS =
new PropertyKey[] {EXPAND_CLICK_LISTENER, ADD_CLICK_LISTENER, IS_MAIN_CONTENT_VISIBLE};
}
...@@ -1590,9 +1590,14 @@ chrome_java_sources = [ ...@@ -1590,9 +1590,14 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/tabmodel/document/TabDelegate.java", "java/src/org/chromium/chrome/browser/tabmodel/document/TabDelegate.java",
"java/src/org/chromium/chrome/browser/tasks/TasksUma.java", "java/src/org/chromium/chrome/browser/tasks/TasksUma.java",
"java/src/org/chromium/chrome/browser/tasks/tab_groups/TabGroupUtils.java", "java/src/org/chromium/chrome/browser/tasks/tab_groups/TabGroupUtils.java",
"java/src/org/chromium/chrome/browser/tasks/tab_list_ui/TabStripToolbarViewProperties.java",
"java/src/org/chromium/chrome/browser/tasks/tab_list_ui/BottomTabListToolbarView.java",
"java/src/org/chromium/chrome/browser/tasks/tab_list_ui/BottomTabStripToolbarViewBinder.java",
"java/src/org/chromium/chrome/browser/tasks/tab_list_ui/TabStripBottomToolbarMediator.java",
"java/src/org/chromium/chrome/browser/tasks/tab_list_ui/TabStripToolbarCoordinator.java",
"java/src/org/chromium/chrome/browser/tasks/tab_list_ui/TabStripBottomToolbarCoordinator.java",
"java/src/org/chromium/chrome/browser/tasks/tab_list_ui/BottomTabGridSheetToolbarProperties.java", "java/src/org/chromium/chrome/browser/tasks/tab_list_ui/BottomTabGridSheetToolbarProperties.java",
"java/src/org/chromium/chrome/browser/tasks/tab_list_ui/BottomTabGridSheetToolbarViewBinder.java", "java/src/org/chromium/chrome/browser/tasks/tab_list_ui/BottomTabGridSheetToolbarViewBinder.java",
"java/src/org/chromium/chrome/browser/tasks/tab_list_ui/BottomTabGridSheetToolbarView.java",
"java/src/org/chromium/chrome/browser/tasks/tab_list_ui/BottomTabGridSheetToolbarCoordinator.java", "java/src/org/chromium/chrome/browser/tasks/tab_list_ui/BottomTabGridSheetToolbarCoordinator.java",
"java/src/org/chromium/chrome/browser/tasks/tab_list_ui/BottomTabGridCoordinator.java", "java/src/org/chromium/chrome/browser/tasks/tab_list_ui/BottomTabGridCoordinator.java",
"java/src/org/chromium/chrome/browser/tasks/tab_list_ui/BottomTabGridMediator.java", "java/src/org/chromium/chrome/browser/tasks/tab_list_ui/BottomTabGridMediator.java",
......
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