Bug 1873260 - Move Behavior classes to ui-widget component

fenix/124.1.0
mike a 6 months ago committed by mergify[bot]
parent 48df9bb6bf
commit 45238224b3

@ -91,7 +91,6 @@ import mozilla.components.feature.session.PictureInPictureFeature
import mozilla.components.feature.session.ScreenOrientationFeature import mozilla.components.feature.session.ScreenOrientationFeature
import mozilla.components.feature.session.SessionFeature import mozilla.components.feature.session.SessionFeature
import mozilla.components.feature.session.SwipeRefreshFeature import mozilla.components.feature.session.SwipeRefreshFeature
import mozilla.components.feature.session.behavior.EngineViewBrowserToolbarBehavior
import mozilla.components.feature.sitepermissions.SitePermissionsFeature import mozilla.components.feature.sitepermissions.SitePermissionsFeature
import mozilla.components.feature.webauthn.WebAuthnFeature import mozilla.components.feature.webauthn.WebAuthnFeature
import mozilla.components.lib.state.ext.consumeFlow import mozilla.components.lib.state.ext.consumeFlow
@ -111,6 +110,7 @@ import mozilla.components.support.ktx.android.view.hideKeyboard
import mozilla.components.support.ktx.kotlin.getOrigin import mozilla.components.support.ktx.kotlin.getOrigin
import mozilla.components.support.ktx.kotlinx.coroutines.flow.ifAnyChanged import mozilla.components.support.ktx.kotlinx.coroutines.flow.ifAnyChanged
import mozilla.components.support.locale.ActivityContextWrapper import mozilla.components.support.locale.ActivityContextWrapper
import mozilla.components.ui.widgets.behavior.EngineViewClippingBehavior
import mozilla.components.ui.widgets.withCenterAlignedButtons import mozilla.components.ui.widgets.withCenterAlignedButtons
import org.mozilla.fenix.BuildConfig import org.mozilla.fenix.BuildConfig
import org.mozilla.fenix.FeatureFlags import org.mozilla.fenix.FeatureFlags
@ -168,7 +168,7 @@ import org.mozilla.fenix.utils.allowUndo
import org.mozilla.fenix.wifi.SitePermissionsWifiIntegration import org.mozilla.fenix.wifi.SitePermissionsWifiIntegration
import java.lang.ref.WeakReference import java.lang.ref.WeakReference
import kotlin.coroutines.cancellation.CancellationException import kotlin.coroutines.cancellation.CancellationException
import mozilla.components.feature.session.behavior.ToolbarPosition as MozacToolbarPosition import mozilla.components.ui.widgets.behavior.ToolbarPosition as MozacToolbarPosition
/** /**
* Base fragment extended by [BrowserFragment]. * Base fragment extended by [BrowserFragment].
@ -1154,7 +1154,7 @@ abstract class BaseBrowserFragment :
MozacToolbarPosition.TOP MozacToolbarPosition.TOP
} }
(getSwipeRefreshLayout().layoutParams as CoordinatorLayout.LayoutParams).behavior = (getSwipeRefreshLayout().layoutParams as CoordinatorLayout.LayoutParams).behavior =
EngineViewBrowserToolbarBehavior( EngineViewClippingBehavior(
context, context,
null, null,
getSwipeRefreshLayout(), getSwipeRefreshLayout(),

@ -19,9 +19,9 @@ import mozilla.components.browser.state.selector.selectedTab
import mozilla.components.browser.state.state.CustomTabSessionState import mozilla.components.browser.state.state.CustomTabSessionState
import mozilla.components.browser.state.state.ExternalAppType import mozilla.components.browser.state.state.ExternalAppType
import mozilla.components.browser.toolbar.BrowserToolbar import mozilla.components.browser.toolbar.BrowserToolbar
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.ktx.util.URLStringUtils import mozilla.components.support.ktx.util.URLStringUtils
import mozilla.components.ui.widgets.behavior.EngineViewScrollingBehavior
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.components.toolbar.interactor.BrowserToolbarInteractor import org.mozilla.fenix.components.toolbar.interactor.BrowserToolbarInteractor
import org.mozilla.fenix.customtabs.CustomTabToolbarIntegration import org.mozilla.fenix.customtabs.CustomTabToolbarIntegration
@ -32,7 +32,7 @@ import org.mozilla.fenix.theme.ThemeManager
import org.mozilla.fenix.utils.Settings import org.mozilla.fenix.utils.Settings
import org.mozilla.fenix.utils.ToolbarPopupWindow 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.ui.widgets.behavior.ViewPosition as MozacToolbarPosition
@SuppressWarnings("LargeClass") @SuppressWarnings("LargeClass")
class BrowserToolbarView( class BrowserToolbarView(
@ -53,8 +53,7 @@ class BrowserToolbarView(
private val layout = LayoutInflater.from(context) private val layout = LayoutInflater.from(context)
.inflate(toolbarLayout, container, true) .inflate(toolbarLayout, container, true)
@VisibleForTesting var view: BrowserToolbar = layout
internal var view: BrowserToolbar = layout
.findViewById(R.id.toolbar) .findViewById(R.id.toolbar)
val toolbarIntegration: ToolbarIntegration val toolbarIntegration: ToolbarIntegration
@ -191,7 +190,7 @@ class BrowserToolbarView(
} }
(view.layoutParams as? CoordinatorLayout.LayoutParams)?.apply { (view.layoutParams as? CoordinatorLayout.LayoutParams)?.apply {
(behavior as? BrowserToolbarBehavior)?.forceExpand(view) (behavior as? EngineViewScrollingBehavior)?.forceExpand(view)
} }
} }
@ -202,7 +201,7 @@ class BrowserToolbarView(
} }
(view.layoutParams as? CoordinatorLayout.LayoutParams)?.apply { (view.layoutParams as? CoordinatorLayout.LayoutParams)?.apply {
(behavior as? BrowserToolbarBehavior)?.forceCollapse(view) (behavior as? EngineViewScrollingBehavior)?.forceCollapse(view)
} }
} }
@ -255,7 +254,7 @@ class BrowserToolbarView(
@VisibleForTesting @VisibleForTesting
internal fun setDynamicToolbarBehavior(toolbarPosition: MozacToolbarPosition) { internal fun setDynamicToolbarBehavior(toolbarPosition: MozacToolbarPosition) {
(view.layoutParams as? CoordinatorLayout.LayoutParams)?.apply { (view.layoutParams as? CoordinatorLayout.LayoutParams)?.apply {
behavior = BrowserToolbarBehavior(view.context, null, toolbarPosition) behavior = EngineViewScrollingBehavior(view.context, null, toolbarPosition)
} }
} }

@ -16,8 +16,8 @@ import mozilla.components.browser.state.state.SessionState
import mozilla.components.concept.engine.EngineView import mozilla.components.concept.engine.EngineView
import mozilla.components.concept.engine.permission.SitePermissions import mozilla.components.concept.engine.permission.SitePermissions
import mozilla.components.feature.contextmenu.ContextMenuCandidate import mozilla.components.feature.contextmenu.ContextMenuCandidate
import mozilla.components.feature.session.behavior.EngineViewBrowserToolbarBehavior
import mozilla.components.ui.widgets.VerticalSwipeRefreshLayout import mozilla.components.ui.widgets.VerticalSwipeRefreshLayout
import mozilla.components.ui.widgets.behavior.EngineViewClippingBehavior
import org.junit.Before import org.junit.Before
import org.junit.Test import org.junit.Test
import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.components
@ -88,17 +88,17 @@ class BaseBrowserFragmentTest {
} }
@Test @Test
fun `initializeEngineView should set EngineViewBrowserToolbarBehavior when dynamic toolbar is enabled`() { fun `initializeEngineView should set EngineViewClippingBehavior when dynamic toolbar is enabled`() {
every { settings.shouldUseFixedTopToolbar } returns false every { settings.shouldUseFixedTopToolbar } returns false
every { settings.isDynamicToolbarEnabled } returns true every { settings.isDynamicToolbarEnabled } returns true
val params: CoordinatorLayout.LayoutParams = mockk(relaxed = true) val params: CoordinatorLayout.LayoutParams = mockk(relaxed = true)
every { params.behavior } returns mockk(relaxed = true) every { params.behavior } returns mockk(relaxed = true)
every { swipeRefreshLayout.layoutParams } returns params every { swipeRefreshLayout.layoutParams } returns params
val behavior = slot<EngineViewBrowserToolbarBehavior>() val behavior = slot<EngineViewClippingBehavior>()
fragment.initializeEngineView(13) fragment.initializeEngineView(13)
// EngineViewBrowserToolbarBehavior constructor parameters are not properties, we cannot check them. // EngineViewClippingBehavior constructor parameters are not properties, we cannot check them.
// Ensure just that the right behavior is set. // Ensure just that the right behavior is set.
verify { params.behavior = capture(behavior) } verify { params.behavior = capture(behavior) }
} }

@ -11,9 +11,9 @@ import io.mockk.mockk
import io.mockk.spyk import io.mockk.spyk
import io.mockk.verify import io.mockk.verify
import mozilla.components.browser.toolbar.BrowserToolbar import mozilla.components.browser.toolbar.BrowserToolbar
import mozilla.components.browser.toolbar.behavior.BrowserToolbarBehavior
import mozilla.components.lib.publicsuffixlist.PublicSuffixList import mozilla.components.lib.publicsuffixlist.PublicSuffixList
import mozilla.components.support.test.robolectric.testContext import mozilla.components.support.test.robolectric.testContext
import mozilla.components.ui.widgets.behavior.EngineViewScrollingBehavior
import org.junit.Assert.assertNotNull import org.junit.Assert.assertNotNull
import org.junit.Assert.assertNull import org.junit.Assert.assertNull
import org.junit.Before import org.junit.Before
@ -22,20 +22,20 @@ import org.junit.runner.RunWith
import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.components
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
import org.mozilla.fenix.utils.Settings import org.mozilla.fenix.utils.Settings
import mozilla.components.browser.toolbar.behavior.ToolbarPosition as MozacToolbarPosition import mozilla.components.ui.widgets.behavior.ViewPosition as MozacToolbarPosition
@RunWith(FenixRobolectricTestRunner::class) @RunWith(FenixRobolectricTestRunner::class)
class BrowserToolbarViewTest { class BrowserToolbarViewTest {
private lateinit var toolbarView: BrowserToolbarView private lateinit var toolbarView: BrowserToolbarView
private lateinit var toolbar: BrowserToolbar private lateinit var toolbar: BrowserToolbar
private lateinit var behavior: BrowserToolbarBehavior private lateinit var behavior: EngineViewScrollingBehavior
private lateinit var settings: Settings private lateinit var settings: Settings
@Before @Before
fun setup() { fun setup() {
toolbar = BrowserToolbar(testContext) toolbar = BrowserToolbar(testContext)
toolbar.layoutParams = CoordinatorLayout.LayoutParams(100, 100) toolbar.layoutParams = CoordinatorLayout.LayoutParams(100, 100)
behavior = spyk(BrowserToolbarBehavior(testContext, null, MozacToolbarPosition.BOTTOM)) behavior = spyk(EngineViewScrollingBehavior(testContext, null, MozacToolbarPosition.BOTTOM))
(toolbar.layoutParams as CoordinatorLayout.LayoutParams).behavior = behavior (toolbar.layoutParams as CoordinatorLayout.LayoutParams).behavior = behavior
settings = mockk(relaxed = true) settings = mockk(relaxed = true)
every { testContext.components.useCases } returns mockk(relaxed = true) every { testContext.components.useCases } returns mockk(relaxed = true)
@ -217,7 +217,7 @@ class BrowserToolbarViewTest {
} }
@Test @Test
fun `setDynamicToolbarBehavior should set a BrowserToolbarBehavior for the bottom toolbar`() { fun `setDynamicToolbarBehavior should set a ViewHideOnScrollBehavior for the bottom toolbar`() {
val toolbarViewSpy = spyk(toolbarView) val toolbarViewSpy = spyk(toolbarView)
(toolbar.layoutParams as CoordinatorLayout.LayoutParams).behavior = null (toolbar.layoutParams as CoordinatorLayout.LayoutParams).behavior = null
@ -227,7 +227,7 @@ class BrowserToolbarViewTest {
} }
@Test @Test
fun `setDynamicToolbarBehavior should set a BrowserToolbarBehavior for the top toolbar`() { fun `setDynamicToolbarBehavior should set a ViewHideOnScrollBehavior for the top toolbar`() {
val toolbarViewSpy = spyk(toolbarView) val toolbarViewSpy = spyk(toolbarView)
(toolbar.layoutParams as CoordinatorLayout.LayoutParams).behavior = null (toolbar.layoutParams as CoordinatorLayout.LayoutParams).behavior = null

Loading…
Cancel
Save