For #355 - re-adds the request desktop functionality
parent
98a1ae578e
commit
b8ab51318e
|
@ -32,6 +32,7 @@ import org.mozilla.fenix.ext.requireComponents
|
||||||
import mozilla.components.feature.prompts.PromptFeature
|
import mozilla.components.feature.prompts.PromptFeature
|
||||||
import org.mozilla.fenix.BackHandler
|
import org.mozilla.fenix.BackHandler
|
||||||
import org.mozilla.fenix.components.FindInPageIntegration
|
import org.mozilla.fenix.components.FindInPageIntegration
|
||||||
|
import org.mozilla.fenix.ext.share
|
||||||
import org.mozilla.fenix.mvi.ActionBusFactory
|
import org.mozilla.fenix.mvi.ActionBusFactory
|
||||||
import org.mozilla.fenix.mvi.getSafeManagedObservable
|
import org.mozilla.fenix.mvi.getSafeManagedObservable
|
||||||
import org.mozilla.fenix.search.toolbar.SearchAction
|
import org.mozilla.fenix.search.toolbar.SearchAction
|
||||||
|
@ -184,6 +185,8 @@ class BrowserFragment : Fragment(), BackHandler {
|
||||||
promptsFeature.onActivityResult(requestCode, resultCode, data)
|
promptsFeature.onActivityResult(requestCode, resultCode, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This method triggers the complexity warning. However it's actually not that hard to understand.
|
||||||
|
@SuppressWarnings("ComplexMethod")
|
||||||
private fun handleToolbarItemInteraction(action: SearchAction.ToolbarMenuItemTapped) {
|
private fun handleToolbarItemInteraction(action: SearchAction.ToolbarMenuItemTapped) {
|
||||||
val sessionUseCases = requireComponents.useCases.sessionUseCases
|
val sessionUseCases = requireComponents.useCases.sessionUseCases
|
||||||
when (action.item) {
|
when (action.item) {
|
||||||
|
@ -194,7 +197,9 @@ class BrowserFragment : Fragment(), BackHandler {
|
||||||
.navigate(R.id.action_browserFragment_to_settingsActivity, null, null)
|
.navigate(R.id.action_browserFragment_to_settingsActivity, null, null)
|
||||||
is ToolbarMenu.Item.Library -> Navigation.findNavController(toolbar)
|
is ToolbarMenu.Item.Library -> Navigation.findNavController(toolbar)
|
||||||
.navigate(R.id.action_browserFragment_to_libraryFragment, null, null)
|
.navigate(R.id.action_browserFragment_to_libraryFragment, null, null)
|
||||||
else -> return
|
is ToolbarMenu.Item.RequestDesktop -> sessionUseCases.requestDesktopSite.invoke(action.item.isChecked)
|
||||||
|
is ToolbarMenu.Item.Share -> requireComponents.core.sessionManager
|
||||||
|
.selectedSession?.url?.apply { requireContext().share(this) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,11 @@ import mozilla.components.browser.menu.item.BrowserMenuItemToolbar
|
||||||
import mozilla.components.browser.menu.item.BrowserMenuSwitch
|
import mozilla.components.browser.menu.item.BrowserMenuSwitch
|
||||||
import org.mozilla.fenix.R
|
import org.mozilla.fenix.R
|
||||||
|
|
||||||
class ToolbarMenu(private val context: Context, private val onItemTapped: (Item) -> Unit = {}) {
|
class ToolbarMenu(
|
||||||
|
private val context: Context,
|
||||||
|
private val requestDesktopStateProvider: () -> Boolean = { false },
|
||||||
|
private val onItemTapped: (Item) -> Unit = {}
|
||||||
|
) {
|
||||||
sealed class Item {
|
sealed class Item {
|
||||||
object Help : Item()
|
object Help : Item()
|
||||||
object Settings : Item()
|
object Settings : Item()
|
||||||
|
@ -88,11 +92,10 @@ class ToolbarMenu(private val context: Context, private val onItemTapped: (Item)
|
||||||
|
|
||||||
BrowserMenuDivider(),
|
BrowserMenuDivider(),
|
||||||
|
|
||||||
BrowserMenuSwitch(context.getString(R.string.browser_menu_desktop_site), {
|
BrowserMenuSwitch(context.getString(R.string.browser_menu_desktop_site),
|
||||||
false
|
requestDesktopStateProvider, { checked ->
|
||||||
}) { checked ->
|
onItemTapped.invoke(Item.RequestDesktop(checked))
|
||||||
onItemTapped.invoke(Item.RequestDesktop(checked))
|
}),
|
||||||
},
|
|
||||||
|
|
||||||
BrowserMenuImageText(
|
BrowserMenuImageText(
|
||||||
context.getString(R.string.browser_menu_find_in_page),
|
context.getString(R.string.browser_menu_find_in_page),
|
||||||
|
|
|
@ -64,7 +64,10 @@ class ToolbarUIView(
|
||||||
toolbarIntegration = ToolbarIntegration(
|
toolbarIntegration = ToolbarIntegration(
|
||||||
this,
|
this,
|
||||||
view,
|
view,
|
||||||
ToolbarMenu(this) { actionEmitter.onNext(SearchAction.ToolbarMenuItemTapped(it)) },
|
ToolbarMenu(this,
|
||||||
|
requestDesktopStateProvider = { components.core.sessionManager.selectedSessionOrThrow.desktopMode },
|
||||||
|
onItemTapped = { actionEmitter.onNext(SearchAction.ToolbarMenuItemTapped(it)) }
|
||||||
|
),
|
||||||
ShippedDomainsProvider().also { it.initialize(this) },
|
ShippedDomainsProvider().also { it.initialize(this) },
|
||||||
components.core.historyStorage,
|
components.core.historyStorage,
|
||||||
components.core.sessionManager,
|
components.core.sessionManager,
|
||||||
|
|
Loading…
Reference in New Issue