[fenix] For https://github.com/mozilla-mobile/fenix/issues/19876 - Part 1: Refactor BrowserToolbarInteractor

- Renames `BrowserInteractor` to `DefaultBrowserTolbarInteractor`
- Renames `BrowserTooolbarViewInteractor` to `BrowserToolbarInteractor`
- Refactors `BrowserToolbarViewInteractor` interface from `BrowserToolbarView.kt` to  `BrowserToolbarInteractor` as `BrowserToolbarInteractor`
pull/600/head
Gabriel Luong 3 years ago
parent 891acbfb74
commit 0e5e244e45

@ -105,9 +105,7 @@ import org.mozilla.fenix.components.StoreProvider
import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.components.toolbar.BrowserFragmentState import org.mozilla.fenix.components.toolbar.BrowserFragmentState
import org.mozilla.fenix.components.toolbar.BrowserFragmentStore import org.mozilla.fenix.components.toolbar.BrowserFragmentStore
import org.mozilla.fenix.components.toolbar.BrowserInteractor
import org.mozilla.fenix.components.toolbar.BrowserToolbarView import org.mozilla.fenix.components.toolbar.BrowserToolbarView
import org.mozilla.fenix.components.toolbar.BrowserToolbarViewInteractor
import org.mozilla.fenix.components.toolbar.DefaultBrowserToolbarController import org.mozilla.fenix.components.toolbar.DefaultBrowserToolbarController
import org.mozilla.fenix.components.toolbar.DefaultBrowserToolbarMenuController import org.mozilla.fenix.components.toolbar.DefaultBrowserToolbarMenuController
import org.mozilla.fenix.components.toolbar.ToolbarIntegration import org.mozilla.fenix.components.toolbar.ToolbarIntegration
@ -137,6 +135,8 @@ import mozilla.components.support.base.feature.ActivityResultHandler
import org.mozilla.fenix.ext.navigateBlockingForAsyncNavGraph import org.mozilla.fenix.ext.navigateBlockingForAsyncNavGraph
import mozilla.components.support.ktx.android.view.enterToImmersiveMode import mozilla.components.support.ktx.android.view.enterToImmersiveMode
import org.mozilla.fenix.GleanMetrics.PerfStartup import org.mozilla.fenix.GleanMetrics.PerfStartup
import org.mozilla.fenix.components.toolbar.interactor.BrowserToolbarInteractor
import org.mozilla.fenix.components.toolbar.interactor.DefaultBrowserToolbarInteractor
import org.mozilla.fenix.ext.measureNoInline import org.mozilla.fenix.ext.measureNoInline
import org.mozilla.fenix.ext.secure import org.mozilla.fenix.ext.secure
import org.mozilla.fenix.settings.biometric.BiometricPromptFeature import org.mozilla.fenix.settings.biometric.BiometricPromptFeature
@ -155,9 +155,9 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
private lateinit var browserFragmentStore: BrowserFragmentStore private lateinit var browserFragmentStore: BrowserFragmentStore
private lateinit var browserAnimator: BrowserAnimator private lateinit var browserAnimator: BrowserAnimator
private var _browserInteractor: BrowserToolbarViewInteractor? = null private var _browserToolbarInteractor: BrowserToolbarInteractor? = null
protected val browserInteractor: BrowserToolbarViewInteractor protected val browserToolbarInteractor: BrowserToolbarInteractor
get() = _browserInteractor!! get() = _browserToolbarInteractor!!
@VisibleForTesting @VisibleForTesting
@Suppress("VariableNaming") @Suppress("VariableNaming")
@ -357,7 +357,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
browserStore = store browserStore = store
) )
_browserInteractor = BrowserInteractor( _browserToolbarInteractor = DefaultBrowserToolbarInteractor(
browserToolbarController, browserToolbarController,
browserToolbarMenuController browserToolbarMenuController
) )
@ -365,7 +365,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
_browserToolbarView = BrowserToolbarView( _browserToolbarView = BrowserToolbarView(
container = view.browserLayout, container = view.browserLayout,
toolbarPosition = context.settings().toolbarPosition, toolbarPosition = context.settings().toolbarPosition,
interactor = browserInteractor, interactor = browserToolbarInteractor,
customTabSession = customTabSessionId?.let { store.state.findCustomTab(it) }, customTabSession = customTabSessionId?.let { store.state.findCustomTab(it) },
lifecycleOwner = viewLifecycleOwner lifecycleOwner = viewLifecycleOwner
) )
@ -1343,7 +1343,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
requireContext().accessibilityManager.removeAccessibilityStateChangeListener(this) requireContext().accessibilityManager.removeAccessibilityStateChangeListener(this)
_browserToolbarView = null _browserToolbarView = null
_browserInteractor = null _browserToolbarInteractor = null
} }
override fun onAttach(context: Context) { override fun onAttach(context: Context) {

@ -89,7 +89,7 @@ class BrowserFragment : BaseBrowserFragment(), UserInteractionHandler {
selected = getCurrentTab()?.let { selected = getCurrentTab()?.let {
activity?.components?.core?.store?.state?.findTab(it.id)?.readerState?.active activity?.components?.core?.store?.state?.findTab(it.id)?.readerState?.active
} ?: false, } ?: false,
listener = browserInteractor::onReaderModePressed listener = browserToolbarInteractor::onReaderModePressed
) )
browserToolbarView.view.addPageAction(readerModeAction) browserToolbarView.view.addPageAction(readerModeAction)

@ -23,8 +23,8 @@ import mozilla.components.browser.toolbar.BrowserToolbar
import mozilla.components.browser.toolbar.behavior.BrowserToolbarBehavior import mozilla.components.browser.toolbar.behavior.BrowserToolbarBehavior
import mozilla.components.browser.toolbar.display.DisplayToolbar import mozilla.components.browser.toolbar.display.DisplayToolbar
import mozilla.components.support.utils.URLStringUtils import mozilla.components.support.utils.URLStringUtils
import mozilla.components.ui.tabcounter.TabCounterMenu
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.components.toolbar.interactor.BrowserToolbarInteractor
import org.mozilla.fenix.customtabs.CustomTabToolbarIntegration import org.mozilla.fenix.customtabs.CustomTabToolbarIntegration
import org.mozilla.fenix.customtabs.CustomTabToolbarMenu import org.mozilla.fenix.customtabs.CustomTabToolbarMenu
import org.mozilla.fenix.ext.bookmarkStorage import org.mozilla.fenix.ext.bookmarkStorage
@ -35,23 +35,12 @@ import org.mozilla.fenix.utils.ToolbarPopupWindow
import java.lang.ref.WeakReference import java.lang.ref.WeakReference
import mozilla.components.browser.toolbar.behavior.ToolbarPosition as MozacToolbarPosition import mozilla.components.browser.toolbar.behavior.ToolbarPosition as MozacToolbarPosition
interface BrowserToolbarViewInteractor {
fun onBrowserToolbarPaste(text: String)
fun onBrowserToolbarPasteAndGo(text: String)
fun onBrowserToolbarClicked()
fun onBrowserToolbarMenuItemTapped(item: ToolbarMenu.Item)
fun onTabCounterClicked()
fun onTabCounterMenuItemTapped(item: TabCounterMenu.Item)
fun onScrolled(offset: Int)
fun onReaderModePressed(enabled: Boolean)
}
@ExperimentalCoroutinesApi @ExperimentalCoroutinesApi
@SuppressWarnings("LargeClass") @SuppressWarnings("LargeClass")
class BrowserToolbarView( class BrowserToolbarView(
private val container: ViewGroup, private val container: ViewGroup,
private val toolbarPosition: ToolbarPosition, private val toolbarPosition: ToolbarPosition,
private val interactor: BrowserToolbarViewInteractor, private val interactor: BrowserToolbarInteractor,
private val customTabSession: CustomTabSessionState?, private val customTabSession: CustomTabSessionState?,
private val lifecycleOwner: LifecycleOwner private val lifecycleOwner: LifecycleOwner
) : LayoutContainer { ) : LayoutContainer {

@ -25,6 +25,7 @@ import mozilla.components.feature.toolbar.ToolbarPresenter
import mozilla.components.support.base.feature.LifecycleAwareFeature import mozilla.components.support.base.feature.LifecycleAwareFeature
import mozilla.components.support.ktx.android.view.hideKeyboard import mozilla.components.support.ktx.android.view.hideKeyboard
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.components.toolbar.interactor.BrowserToolbarInteractor
import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.settings import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.theme.ThemeManager import org.mozilla.fenix.theme.ThemeManager
@ -88,7 +89,7 @@ class DefaultToolbarIntegration(
lifecycleOwner: LifecycleOwner, lifecycleOwner: LifecycleOwner,
sessionId: String? = null, sessionId: String? = null,
isPrivate: Boolean, isPrivate: Boolean,
interactor: BrowserToolbarViewInteractor, interactor: BrowserToolbarInteractor,
engine: Engine engine: Engine
) : ToolbarIntegration( ) : ToolbarIntegration(
context = context, context = context,

@ -2,14 +2,40 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.components.toolbar package org.mozilla.fenix.components.toolbar.interactor
import mozilla.components.ui.tabcounter.TabCounterMenu import mozilla.components.ui.tabcounter.TabCounterMenu
import org.mozilla.fenix.components.toolbar.BrowserToolbarController
import org.mozilla.fenix.components.toolbar.BrowserToolbarMenuController
import org.mozilla.fenix.components.toolbar.ToolbarMenu
open class BrowserInteractor( /**
* Interface for the browser toolbar interactor. This interface is implemented by objects that
* want to respond to user interaction on the browser toolbar.
*/
interface BrowserToolbarInteractor {
fun onBrowserToolbarPaste(text: String)
fun onBrowserToolbarPasteAndGo(text: String)
fun onBrowserToolbarClicked()
fun onBrowserToolbarMenuItemTapped(item: ToolbarMenu.Item)
fun onTabCounterClicked()
fun onTabCounterMenuItemTapped(item: TabCounterMenu.Item)
fun onScrolled(offset: Int)
fun onReaderModePressed(enabled: Boolean)
}
/**
* The default implementation of [BrowserToolbarInteractor].
*
* @property browserToolbarController [BrowserToolbarController] to which user actions can be
* delegated for all interactions on the browser toolbar.
* @property menuController [BrowserToolbarMenuController] to which user actions can be delegated
* for all interactions on the the browser toolbar menu.
*/
class DefaultBrowserToolbarInteractor(
private val browserToolbarController: BrowserToolbarController, private val browserToolbarController: BrowserToolbarController,
private val menuController: BrowserToolbarMenuController private val menuController: BrowserToolbarMenuController
) : BrowserToolbarViewInteractor { ) : BrowserToolbarInteractor {
override fun onTabCounterClicked() { override fun onTabCounterClicked() {
browserToolbarController.handleTabCounterClick() browserToolbarController.handleTabCounterClick()

@ -66,7 +66,7 @@ class ExternalAppBrowserFragment : BaseBrowserFragment(), UserInteractionHandler
toolbar = toolbar, toolbar = toolbar,
sessionId = customTabSessionId, sessionId = customTabSessionId,
activity = activity, activity = activity,
onItemTapped = { browserInteractor.onBrowserToolbarMenuItemTapped(it) }, onItemTapped = { browserToolbarInteractor.onBrowserToolbarMenuItemTapped(it) },
isPrivate = tab.content.private, isPrivate = tab.content.private,
shouldReverseItems = !activity.settings().shouldUseBottomToolbar shouldReverseItems = !activity.settings().shouldUseBottomToolbar
), ),

@ -7,17 +7,18 @@ import io.mockk.verify
import mozilla.components.ui.tabcounter.TabCounterMenu import mozilla.components.ui.tabcounter.TabCounterMenu
import org.junit.Before import org.junit.Before
import org.junit.Test import org.junit.Test
import org.mozilla.fenix.components.toolbar.interactor.DefaultBrowserToolbarInteractor
class BrowserInteractorTest { class DefaultBrowserToolbarInteractorTest {
@RelaxedMockK lateinit var browserToolbarController: BrowserToolbarController @RelaxedMockK lateinit var browserToolbarController: BrowserToolbarController
@RelaxedMockK lateinit var browserToolbarMenuController: BrowserToolbarMenuController @RelaxedMockK lateinit var browserToolbarMenuController: BrowserToolbarMenuController
lateinit var interactor: BrowserInteractor lateinit var interactor: DefaultBrowserToolbarInteractor
@Before @Before
fun setup() { fun setup() {
MockKAnnotations.init(this) MockKAnnotations.init(this)
interactor = BrowserInteractor( interactor = DefaultBrowserToolbarInteractor(
browserToolbarController, browserToolbarController,
browserToolbarMenuController browserToolbarMenuController
) )
Loading…
Cancel
Save