mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-17 15:26:23 +00:00
[fenix] For https://github.com/mozilla-mobile/fenix/issues/19886 - Improve quick setting dialogs navigation
This commit is contained in:
parent
c9575d0d62
commit
39dc0701a8
@ -9,10 +9,8 @@ import androidx.fragment.app.Fragment
|
|||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import mozilla.components.browser.state.state.SessionState
|
import mozilla.components.browser.state.state.SessionState
|
||||||
import mozilla.components.concept.engine.permission.SitePermissions
|
import mozilla.components.concept.engine.permission.SitePermissions
|
||||||
import org.mozilla.fenix.R
|
|
||||||
import org.mozilla.fenix.browser.BrowserFragmentDirections
|
import org.mozilla.fenix.browser.BrowserFragmentDirections
|
||||||
import org.mozilla.fenix.ext.components
|
import org.mozilla.fenix.ext.components
|
||||||
import org.mozilla.fenix.ext.nav
|
|
||||||
import org.mozilla.fenix.ext.runIfFragmentIsAttached
|
import org.mozilla.fenix.ext.runIfFragmentIsAttached
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,7 +34,7 @@ interface ConnectionDetailsController {
|
|||||||
class DefaultConnectionDetailsController(
|
class DefaultConnectionDetailsController(
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
private val fragment: Fragment,
|
private val fragment: Fragment,
|
||||||
private val navController: NavController,
|
private val navController: () -> NavController,
|
||||||
internal var sitePermissions: SitePermissions?,
|
internal var sitePermissions: SitePermissions?,
|
||||||
private val gravity: Int,
|
private val gravity: Int,
|
||||||
private val getCurrentTab: () -> SessionState?,
|
private val getCurrentTab: () -> SessionState?,
|
||||||
@ -46,7 +44,7 @@ class DefaultConnectionDetailsController(
|
|||||||
getCurrentTab()?.let { tab ->
|
getCurrentTab()?.let { tab ->
|
||||||
context.components.useCases.trackingProtectionUseCases.containsException(tab.id) { contains ->
|
context.components.useCases.trackingProtectionUseCases.containsException(tab.id) { contains ->
|
||||||
fragment.runIfFragmentIsAttached {
|
fragment.runIfFragmentIsAttached {
|
||||||
dismiss()
|
navController().popBackStack()
|
||||||
val isTrackingProtectionEnabled = tab.trackingProtection.enabled && !contains
|
val isTrackingProtectionEnabled = tab.trackingProtection.enabled && !contains
|
||||||
val directions =
|
val directions =
|
||||||
BrowserFragmentDirections.actionGlobalQuickSettingsSheetDialogFragment(
|
BrowserFragmentDirections.actionGlobalQuickSettingsSheetDialogFragment(
|
||||||
@ -60,7 +58,7 @@ class DefaultConnectionDetailsController(
|
|||||||
permissionHighlights = tab.content.permissionHighlights,
|
permissionHighlights = tab.content.permissionHighlights,
|
||||||
isTrackingProtectionEnabled = isTrackingProtectionEnabled
|
isTrackingProtectionEnabled = isTrackingProtectionEnabled
|
||||||
)
|
)
|
||||||
navController.nav(R.id.quickSettingsSheetDialogFragment, directions)
|
navController().navigate(directions)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ class ConnectionPanelDialogFragment : FenixDialogFragment() {
|
|||||||
val controller = DefaultConnectionDetailsController(
|
val controller = DefaultConnectionDetailsController(
|
||||||
context = requireContext(),
|
context = requireContext(),
|
||||||
fragment = this,
|
fragment = this,
|
||||||
navController = findNavController(),
|
navController = { findNavController() },
|
||||||
sitePermissions = args.sitePermissions,
|
sitePermissions = args.sitePermissions,
|
||||||
gravity = args.gravity,
|
gravity = args.gravity,
|
||||||
getCurrentTab = ::getCurrentTab,
|
getCurrentTab = ::getCurrentTab,
|
||||||
|
@ -16,12 +16,11 @@ import mozilla.components.feature.session.SessionUseCases.ReloadUrlUseCase
|
|||||||
import mozilla.components.feature.tabs.TabsUseCases.AddNewTabUseCase
|
import mozilla.components.feature.tabs.TabsUseCases.AddNewTabUseCase
|
||||||
import mozilla.components.support.base.feature.OnNeedToRequestPermissions
|
import mozilla.components.support.base.feature.OnNeedToRequestPermissions
|
||||||
import mozilla.components.support.ktx.kotlin.getOrigin
|
import mozilla.components.support.ktx.kotlin.getOrigin
|
||||||
import org.mozilla.fenix.R
|
import org.mozilla.fenix.NavGraphDirections
|
||||||
import org.mozilla.fenix.components.PermissionStorage
|
import org.mozilla.fenix.components.PermissionStorage
|
||||||
import org.mozilla.fenix.components.metrics.Event
|
import org.mozilla.fenix.components.metrics.Event
|
||||||
import org.mozilla.fenix.ext.components
|
import org.mozilla.fenix.ext.components
|
||||||
import org.mozilla.fenix.ext.metrics
|
import org.mozilla.fenix.ext.metrics
|
||||||
import org.mozilla.fenix.ext.nav
|
|
||||||
import org.mozilla.fenix.settings.PhoneFeature
|
import org.mozilla.fenix.settings.PhoneFeature
|
||||||
import org.mozilla.fenix.settings.quicksettings.ext.shouldBeEnabled
|
import org.mozilla.fenix.settings.quicksettings.ext.shouldBeEnabled
|
||||||
import org.mozilla.fenix.settings.toggle
|
import org.mozilla.fenix.settings.toggle
|
||||||
@ -101,7 +100,7 @@ class DefaultQuickSettingsController(
|
|||||||
private val quickSettingsStore: QuickSettingsFragmentStore,
|
private val quickSettingsStore: QuickSettingsFragmentStore,
|
||||||
private val browserStore: BrowserStore,
|
private val browserStore: BrowserStore,
|
||||||
private val ioScope: CoroutineScope,
|
private val ioScope: CoroutineScope,
|
||||||
private val navController: NavController,
|
private val navController: () -> NavController,
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
internal val sessionId: String,
|
internal val sessionId: String,
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@ -198,21 +197,21 @@ class DefaultQuickSettingsController(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun handleBlockedItemsClicked() {
|
override fun handleBlockedItemsClicked() {
|
||||||
dismiss.invoke()
|
navController().popBackStack()
|
||||||
|
|
||||||
val state = quickSettingsStore.state.trackingProtectionState
|
val state = quickSettingsStore.state.trackingProtectionState
|
||||||
val directions = QuickSettingsSheetDialogFragmentDirections
|
val directions = NavGraphDirections
|
||||||
.actionGlobalTrackingProtectionPanelDialogFragment(
|
.actionGlobalTrackingProtectionPanelDialogFragment(
|
||||||
sessionId = sessionId,
|
sessionId = sessionId,
|
||||||
url = state.url,
|
url = state.url,
|
||||||
trackingProtectionEnabled = state.isTrackingProtectionEnabled,
|
trackingProtectionEnabled = state.isTrackingProtectionEnabled,
|
||||||
gravity = context.components.settings.toolbarPosition.androidGravity
|
gravity = context.components.settings.toolbarPosition.androidGravity
|
||||||
)
|
)
|
||||||
navController.nav(R.id.quickSettingsSheetDialogFragment, directions)
|
navController().navigate(directions)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun handleConnectionDetailsClicked() {
|
override fun handleConnectionDetailsClicked() {
|
||||||
dismiss.invoke()
|
navController().popBackStack()
|
||||||
|
|
||||||
val state = quickSettingsStore.state.webInfoState
|
val state = quickSettingsStore.state.webInfoState
|
||||||
val directions = ConnectionPanelDialogFragmentDirections
|
val directions = ConnectionPanelDialogFragmentDirections
|
||||||
@ -225,7 +224,7 @@ class DefaultQuickSettingsController(
|
|||||||
gravity = context.components.settings.toolbarPosition.androidGravity,
|
gravity = context.components.settings.toolbarPosition.androidGravity,
|
||||||
sitePermissions = sitePermissions
|
sitePermissions = sitePermissions
|
||||||
)
|
)
|
||||||
navController.nav(R.id.quickSettingsSheetDialogFragment, directions)
|
navController().navigate(directions)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -270,6 +269,6 @@ class DefaultQuickSettingsController(
|
|||||||
private fun navigateToManagePhoneFeature(phoneFeature: PhoneFeature) {
|
private fun navigateToManagePhoneFeature(phoneFeature: PhoneFeature) {
|
||||||
val directions = QuickSettingsSheetDialogFragmentDirections
|
val directions = QuickSettingsSheetDialogFragmentDirections
|
||||||
.actionGlobalSitePermissionsManagePhoneFeature(phoneFeature)
|
.actionGlobalSitePermissionsManagePhoneFeature(phoneFeature)
|
||||||
navController.navigate(directions)
|
navController().navigate(directions)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ class QuickSettingsSheetDialogFragment : FenixDialogFragment() {
|
|||||||
quickSettingsStore = quickSettingsStore,
|
quickSettingsStore = quickSettingsStore,
|
||||||
browserStore = components.core.store,
|
browserStore = components.core.store,
|
||||||
ioScope = viewLifecycleOwner.lifecycleScope + Dispatchers.IO,
|
ioScope = viewLifecycleOwner.lifecycleScope + Dispatchers.IO,
|
||||||
navController = findNavController(),
|
navController = { findNavController() },
|
||||||
sessionId = args.sessionId,
|
sessionId = args.sessionId,
|
||||||
sitePermissions = args.sitePermissions,
|
sitePermissions = args.sitePermissions,
|
||||||
settings = components.settings,
|
settings = components.settings,
|
||||||
|
@ -208,9 +208,6 @@
|
|||||||
<action
|
<action
|
||||||
android:id="@+id/action_browserFragment_to_quickSettingsSheetDialogFragment"
|
android:id="@+id/action_browserFragment_to_quickSettingsSheetDialogFragment"
|
||||||
app:destination="@id/quickSettingsSheetDialogFragment" />
|
app:destination="@id/quickSettingsSheetDialogFragment" />
|
||||||
<action
|
|
||||||
android:id="@+id/action_browserFragment_to_trackingProtectionPanelDialogFragment"
|
|
||||||
app:destination="@id/trackingProtectionPanelDialogFragment" />
|
|
||||||
</fragment>
|
</fragment>
|
||||||
|
|
||||||
<fragment
|
<fragment
|
||||||
|
@ -7,6 +7,7 @@ package org.mozilla.fenix.settings.quicksettings
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
|
import androidx.navigation.NavDirections
|
||||||
import io.mockk.MockKAnnotations
|
import io.mockk.MockKAnnotations
|
||||||
import io.mockk.every
|
import io.mockk.every
|
||||||
import io.mockk.impl.annotations.MockK
|
import io.mockk.impl.annotations.MockK
|
||||||
@ -23,10 +24,8 @@ import mozilla.components.support.test.robolectric.testContext
|
|||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
import org.mozilla.fenix.R
|
|
||||||
import org.mozilla.fenix.browser.BrowserFragmentDirections
|
|
||||||
import org.mozilla.fenix.ext.components
|
import org.mozilla.fenix.ext.components
|
||||||
import org.mozilla.fenix.ext.nav
|
import org.mozilla.fenix.ext.navigateBlockingForAsyncNavGraph
|
||||||
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
|
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
|
||||||
|
|
||||||
@ExperimentalCoroutinesApi
|
@ExperimentalCoroutinesApi
|
||||||
@ -62,7 +61,7 @@ class DefaultConnectionDetailsControllerTest {
|
|||||||
controller = DefaultConnectionDetailsController(
|
controller = DefaultConnectionDetailsController(
|
||||||
fragment = fragment,
|
fragment = fragment,
|
||||||
context = context,
|
context = context,
|
||||||
navController = navController,
|
navController = { navController },
|
||||||
sitePermissions = sitePermissions,
|
sitePermissions = sitePermissions,
|
||||||
gravity = gravity,
|
gravity = gravity,
|
||||||
getCurrentTab = { tab },
|
getCurrentTab = { tab },
|
||||||
@ -82,25 +81,13 @@ class DefaultConnectionDetailsControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `WHEN handleBackPressed is called THEN should call dismiss and navigate`() {
|
fun `WHEN handleBackPressed is called THEN should call popBackStack and navigate`() {
|
||||||
controller.handleBackPressed()
|
controller.handleBackPressed()
|
||||||
|
|
||||||
verify {
|
verify {
|
||||||
dismiss.invoke()
|
navController.popBackStack()
|
||||||
|
|
||||||
navController.nav(
|
navController.navigateBlockingForAsyncNavGraph(any<NavDirections>())
|
||||||
R.id.quickSettingsSheetDialogFragment,
|
|
||||||
BrowserFragmentDirections.actionGlobalQuickSettingsSheetDialogFragment(
|
|
||||||
sessionId = tab.id,
|
|
||||||
url = tab.content.url,
|
|
||||||
title = tab.content.title,
|
|
||||||
isSecured = tab.content.securityInfo.secure,
|
|
||||||
sitePermissions = sitePermissions,
|
|
||||||
certificateName = tab.content.securityInfo.issuer,
|
|
||||||
permissionHighlights = tab.content.permissionHighlights,
|
|
||||||
isTrackingProtectionEnabled = true
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,14 +37,13 @@ import org.junit.Assert.assertTrue
|
|||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
import org.mozilla.fenix.R
|
|
||||||
import org.mozilla.fenix.components.PermissionStorage
|
import org.mozilla.fenix.components.PermissionStorage
|
||||||
import org.mozilla.fenix.components.metrics.Event
|
import org.mozilla.fenix.components.metrics.Event
|
||||||
import org.mozilla.fenix.components.metrics.MetricController
|
import org.mozilla.fenix.components.metrics.MetricController
|
||||||
import org.mozilla.fenix.ext.components
|
import org.mozilla.fenix.ext.components
|
||||||
import org.mozilla.fenix.ext.directionsEq
|
import org.mozilla.fenix.ext.directionsEq
|
||||||
import org.mozilla.fenix.ext.metrics
|
import org.mozilla.fenix.ext.metrics
|
||||||
import org.mozilla.fenix.ext.nav
|
import org.mozilla.fenix.ext.navigateBlockingForAsyncNavGraph
|
||||||
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
|
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
|
||||||
import org.mozilla.fenix.settings.PhoneFeature
|
import org.mozilla.fenix.settings.PhoneFeature
|
||||||
import org.mozilla.fenix.settings.quicksettings.ext.shouldBeEnabled
|
import org.mozilla.fenix.settings.quicksettings.ext.shouldBeEnabled
|
||||||
@ -101,7 +100,7 @@ class DefaultQuickSettingsControllerTest {
|
|||||||
browserStore = browserStore,
|
browserStore = browserStore,
|
||||||
sessionId = tab.id,
|
sessionId = tab.id,
|
||||||
ioScope = coroutinesScope,
|
ioScope = coroutinesScope,
|
||||||
navController = navController,
|
navController = { navController },
|
||||||
sitePermissions = sitePermissions,
|
sitePermissions = sitePermissions,
|
||||||
settings = appSettings,
|
settings = appSettings,
|
||||||
permissionStorage = permissionStorage,
|
permissionStorage = permissionStorage,
|
||||||
@ -177,7 +176,7 @@ class DefaultQuickSettingsControllerTest {
|
|||||||
quickSettingsStore = store,
|
quickSettingsStore = store,
|
||||||
browserStore = BrowserStore(),
|
browserStore = BrowserStore(),
|
||||||
ioScope = coroutinesScope,
|
ioScope = coroutinesScope,
|
||||||
navController = navController,
|
navController = { navController },
|
||||||
sessionId = "123",
|
sessionId = "123",
|
||||||
sitePermissions = null,
|
sitePermissions = null,
|
||||||
settings = appSettings,
|
settings = appSettings,
|
||||||
@ -357,7 +356,7 @@ class DefaultQuickSettingsControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `handleBlockedItemsClicked should call dismiss and navigate to the tracking protection panel dialog`() {
|
fun `handleBlockedItemsClicked should call popBackStack and navigate to the tracking protection panel dialog`() {
|
||||||
every { context.components.core.store } returns browserStore
|
every { context.components.core.store } returns browserStore
|
||||||
every { context.components.settings } returns appSettings
|
every { context.components.settings } returns appSettings
|
||||||
every { context.components.settings.toolbarPosition.androidGravity } returns mockk(relaxed = true)
|
every { context.components.settings.toolbarPosition.androidGravity } returns mockk(relaxed = true)
|
||||||
@ -375,22 +374,14 @@ class DefaultQuickSettingsControllerTest {
|
|||||||
controller.handleBlockedItemsClicked()
|
controller.handleBlockedItemsClicked()
|
||||||
|
|
||||||
verify {
|
verify {
|
||||||
dismiss.invoke()
|
navController.popBackStack()
|
||||||
|
|
||||||
navController.nav(
|
navController.navigateBlockingForAsyncNavGraph(any<NavDirections>())
|
||||||
R.id.quickSettingsSheetDialogFragment,
|
|
||||||
QuickSettingsSheetDialogFragmentDirections.actionGlobalTrackingProtectionPanelDialogFragment(
|
|
||||||
sessionId = tab.id,
|
|
||||||
url = state.url,
|
|
||||||
trackingProtectionEnabled = state.isTrackingProtectionEnabled,
|
|
||||||
gravity = context.components.settings.toolbarPosition.androidGravity
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `WHEN handleConnectionDetailsClicked THEN call dismiss and navigate to the connection details dialog`() {
|
fun `WHEN handleConnectionDetailsClicked THEN call popBackStack and navigate to the connection details dialog`() {
|
||||||
every { context.components.core.store } returns browserStore
|
every { context.components.core.store } returns browserStore
|
||||||
every { context.components.settings } returns appSettings
|
every { context.components.settings } returns appSettings
|
||||||
every { context.components.settings.toolbarPosition.androidGravity } returns mockk(relaxed = true)
|
every { context.components.settings.toolbarPosition.androidGravity } returns mockk(relaxed = true)
|
||||||
@ -407,19 +398,9 @@ class DefaultQuickSettingsControllerTest {
|
|||||||
controller.handleConnectionDetailsClicked()
|
controller.handleConnectionDetailsClicked()
|
||||||
|
|
||||||
verify {
|
verify {
|
||||||
dismiss.invoke()
|
navController.popBackStack()
|
||||||
|
|
||||||
navController.nav(
|
navController.navigateBlockingForAsyncNavGraph(any<NavDirections>())
|
||||||
R.id.quickSettingsSheetDialogFragment,
|
|
||||||
QuickSettingsSheetDialogFragmentDirections.actionGlobalConnectionDetailsDialogFragment(
|
|
||||||
sessionId = tab.id,
|
|
||||||
url = state.websiteUrl,
|
|
||||||
title = state.websiteTitle,
|
|
||||||
isSecured = true,
|
|
||||||
sitePermissions = sitePermissions,
|
|
||||||
gravity = context.components.settings.toolbarPosition.androidGravity
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@ class WebsiteInfoViewTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `WHEN updating on not detailed mode THEN only connection details listener should be binded`() {
|
fun `WHEN updating on not detailed mode THEN only connection details listener should be binded`() {
|
||||||
val view = WebsiteInfoView(FrameLayout(testContext), icons, interactor, isDetailsMode = false)
|
val view = spyk(WebsiteInfoView(FrameLayout(testContext), icons, interactor, isDetailsMode = false))
|
||||||
|
|
||||||
view.update(WebsiteInfoState(
|
view.update(WebsiteInfoState(
|
||||||
websiteUrl = "https://mozilla.org",
|
websiteUrl = "https://mozilla.org",
|
||||||
|
Loading…
Reference in New Issue
Block a user