For #19876 - Part 1: Refactor BrowserToolbarInteractor

- Renames `BrowserInteractor` to `DefaultBrowserTolbarInteractor`
- Renames `BrowserTooolbarViewInteractor` to `BrowserToolbarInteractor`
- Refactors `BrowserToolbarViewInteractor` interface from `BrowserToolbarView.kt` to  `BrowserToolbarInteractor` as `BrowserToolbarInteractor`
upstream-sync
Gabriel Luong 3 years ago
parent 268df1906a
commit 86a9c56782

@ -105,9 +105,7 @@ import org.mozilla.fenix.components.StoreProvider
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.components.toolbar.BrowserFragmentState
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.BrowserToolbarViewInteractor
import org.mozilla.fenix.components.toolbar.DefaultBrowserToolbarController
import org.mozilla.fenix.components.toolbar.DefaultBrowserToolbarMenuController
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 mozilla.components.support.ktx.android.view.enterToImmersiveMode
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.secure
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 browserAnimator: BrowserAnimator
private var _browserInteractor: BrowserToolbarViewInteractor? = null
protected val browserInteractor: BrowserToolbarViewInteractor
get() = _browserInteractor!!
private var _browserToolbarInteractor: BrowserToolbarInteractor? = null
protected val browserToolbarInteractor: BrowserToolbarInteractor
get() = _browserToolbarInteractor!!
@VisibleForTesting
@Suppress("VariableNaming")
@ -357,7 +357,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
browserStore = store
)
_browserInteractor = BrowserInteractor(
_browserToolbarInteractor = DefaultBrowserToolbarInteractor(
browserToolbarController,
browserToolbarMenuController
)
@ -365,7 +365,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
_browserToolbarView = BrowserToolbarView(
container = view.browserLayout,
toolbarPosition = context.settings().toolbarPosition,
interactor = browserInteractor,
interactor = browserToolbarInteractor,
customTabSession = customTabSessionId?.let { store.state.findCustomTab(it) },
lifecycleOwner = viewLifecycleOwner
)
@ -1343,7 +1343,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
requireContext().accessibilityManager.removeAccessibilityStateChangeListener(this)
_browserToolbarView = null
_browserInteractor = null
_browserToolbarInteractor = null
}
override fun onAttach(context: Context) {

@ -89,7 +89,7 @@ class BrowserFragment : BaseBrowserFragment(), UserInteractionHandler {
selected = getCurrentTab()?.let {
activity?.components?.core?.store?.state?.findTab(it.id)?.readerState?.active
} ?: false,
listener = browserInteractor::onReaderModePressed
listener = browserToolbarInteractor::onReaderModePressed
)
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.display.DisplayToolbar
import mozilla.components.support.utils.URLStringUtils
import mozilla.components.ui.tabcounter.TabCounterMenu
import org.mozilla.fenix.R
import org.mozilla.fenix.components.toolbar.interactor.BrowserToolbarInteractor
import org.mozilla.fenix.customtabs.CustomTabToolbarIntegration
import org.mozilla.fenix.customtabs.CustomTabToolbarMenu
import org.mozilla.fenix.ext.bookmarkStorage
@ -35,23 +35,12 @@ import org.mozilla.fenix.utils.ToolbarPopupWindow
import java.lang.ref.WeakReference
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
@SuppressWarnings("LargeClass")
class BrowserToolbarView(
private val container: ViewGroup,
private val toolbarPosition: ToolbarPosition,
private val interactor: BrowserToolbarViewInteractor,
private val interactor: BrowserToolbarInteractor,
private val customTabSession: CustomTabSessionState?,
private val lifecycleOwner: LifecycleOwner
) : LayoutContainer {

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

@ -2,14 +2,40 @@
* 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/. */
package org.mozilla.fenix.components.toolbar
package org.mozilla.fenix.components.toolbar.interactor
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 menuController: BrowserToolbarMenuController
) : BrowserToolbarViewInteractor {
) : BrowserToolbarInteractor {
override fun onTabCounterClicked() {
browserToolbarController.handleTabCounterClick()

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

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