| // 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 org.chromium.chrome.browser.compositor.CompositorViewHolder; |
| 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.TabModel; |
| import org.chromium.chrome.browser.tabmodel.TabModelSelector; |
| import org.chromium.chrome.browser.toolbar.ToolbarManager; |
| import org.chromium.ui.modelutil.PropertyModel; |
| import org.chromium.ui.modelutil.PropertyModelChangeProcessor; |
| |
| import javax.inject.Inject; |
| import javax.inject.Named; |
| |
| /** |
| * Parent coordinator that is responsible for showing a grid of tabs for the main TabSwitcher UI. |
| */ |
| @ActivityScope |
| public class GridTabSwitcherCoordinator implements Destroyable { |
| private final PropertyModelChangeProcessor mContainerViewChangeProcessor; |
| private final ActivityLifecycleDispatcher mLifecycleDispatcher; |
| private final TabListCoordinator mTabGridCoordinator; |
| private final GridTabSwitcherMediator mMediator; |
| |
| @Inject |
| public GridTabSwitcherCoordinator(@Named(ACTIVITY_CONTEXT) Context context, |
| ActivityLifecycleDispatcher lifecycleDispatcher, ToolbarManager toolbarManager, |
| TabModelSelector tabModelSelector, TabContentManager tabContentManager, |
| CompositorViewHolder compositorViewHolder) { |
| PropertyModel containerViewModel = new PropertyModel(TabListContainerProperties.ALL_KEYS); |
| |
| mTabGridCoordinator = new TabListCoordinator(TabListCoordinator.TabListMode.GRID, context, |
| tabModelSelector, tabContentManager, compositorViewHolder, true); |
| |
| mContainerViewChangeProcessor = PropertyModelChangeProcessor.create(containerViewModel, |
| mTabGridCoordinator.getContainerView(), TabGridContainerViewBinder::bind); |
| |
| mMediator = new GridTabSwitcherMediator(this, containerViewModel, tabModelSelector); |
| toolbarManager.overrideTabSwitcherBehavior( |
| mMediator.getTabSwitcherButtonClickListener(), mMediator); |
| |
| mLifecycleDispatcher = lifecycleDispatcher; |
| mLifecycleDispatcher.register(this); |
| } |
| |
| /** |
| * Reset the tab grid with the given {@link TabModel}. Can be null. |
| * @param tabModel The current {@link TabModel} to show the tabs for in the grid. |
| */ |
| void resetWithTabModel(TabModel tabModel) { |
| mTabGridCoordinator.resetWithTabModel(tabModel); |
| } |
| |
| @Override |
| public void destroy() { |
| mTabGridCoordinator.destroy(); |
| mContainerViewChangeProcessor.destroy(); |
| mMediator.destroy(); |
| mLifecycleDispatcher.unregister(this); |
| } |
| } |