Bug 1857139 - Add translation bottom sheet boilerplate
[gecko.git] / mobile / android / fenix / app / src / main / java / org / mozilla / fenix / components / toolbar / interactor / BrowserToolbarInteractor.kt
blobb452aea40a66249a201c1bddd85cd9f339315aae
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 package org.mozilla.fenix.components.toolbar.interactor
7 import mozilla.components.ui.tabcounter.TabCounterMenu
8 import org.mozilla.fenix.components.toolbar.BrowserToolbarController
9 import org.mozilla.fenix.components.toolbar.BrowserToolbarMenuController
10 import org.mozilla.fenix.components.toolbar.ToolbarMenu
12 /**
13  * Interface for the browser toolbar interactor. This interface is implemented by objects that
14  * want to respond to user interaction on the browser toolbar.
15  */
16 interface BrowserToolbarInteractor {
17     fun onBrowserToolbarPaste(text: String)
18     fun onBrowserToolbarPasteAndGo(text: String)
19     fun onBrowserToolbarClicked()
20     fun onBrowserToolbarMenuItemTapped(item: ToolbarMenu.Item)
21     fun onTabCounterClicked()
22     fun onTabCounterMenuItemTapped(item: TabCounterMenu.Item)
23     fun onScrolled(offset: Int)
24     fun onReaderModePressed(enabled: Boolean)
26     /**
27      * Navigates to the Home screen. Called when a user taps on the Home button.
28      */
29     fun onHomeButtonClicked()
31     /**
32      * Deletes all tabs and navigates to the Home screen. Called when a user taps on the erase button.
33      */
34     fun onEraseButtonClicked()
36     /**
37      * Opens the shopping bottom sheet. Called when the user interacts with the shopping cfr action.
38      */
39     fun onShoppingCfrActionClicked()
41     /**
42      * Updates the settings for the shopping CFR. Called when the user dismisses the shopping cfr action.
43      */
44     fun onShoppingCfrDismiss()
46     /**
47      * Opens the translation bottom sheet. Called when the user interacts with the translation
48      * action.
49      */
50     fun onTranslationsButtonClicked()
53 /**
54  * The default implementation of [BrowserToolbarInteractor].
55  *
56  * @property browserToolbarController [BrowserToolbarController] to which user actions can be
57  * delegated for all interactions on the browser toolbar.
58  * @property menuController [BrowserToolbarMenuController] to which user actions can be delegated
59  * for all interactions on the the browser toolbar menu.
60  */
61 class DefaultBrowserToolbarInteractor(
62     private val browserToolbarController: BrowserToolbarController,
63     private val menuController: BrowserToolbarMenuController,
64 ) : BrowserToolbarInteractor {
66     override fun onTabCounterClicked() {
67         browserToolbarController.handleTabCounterClick()
68     }
70     override fun onTabCounterMenuItemTapped(item: TabCounterMenu.Item) {
71         browserToolbarController.handleTabCounterItemInteraction(item)
72     }
74     override fun onBrowserToolbarPaste(text: String) {
75         browserToolbarController.handleToolbarPaste(text)
76     }
78     override fun onBrowserToolbarPasteAndGo(text: String) {
79         browserToolbarController.handleToolbarPasteAndGo(text)
80     }
82     override fun onBrowserToolbarClicked() {
83         browserToolbarController.handleToolbarClick()
84     }
86     override fun onBrowserToolbarMenuItemTapped(item: ToolbarMenu.Item) {
87         menuController.handleToolbarItemInteraction(item)
88     }
90     override fun onScrolled(offset: Int) {
91         browserToolbarController.handleScroll(offset)
92     }
94     override fun onReaderModePressed(enabled: Boolean) {
95         browserToolbarController.handleReaderModePressed(enabled)
96     }
98     override fun onHomeButtonClicked() {
99         browserToolbarController.handleHomeButtonClick()
100     }
102     override fun onEraseButtonClicked() {
103         browserToolbarController.handleEraseButtonClick()
104     }
106     override fun onShoppingCfrActionClicked() {
107         browserToolbarController.handleShoppingCfrActionClick()
108     }
110     override fun onShoppingCfrDismiss() {
111         browserToolbarController.handleShoppingCfrDismiss()
112     }
114     override fun onTranslationsButtonClicked() {
115         browserToolbarController.handleTranslationsButtonClick()
116     }