Skip to content

Commit

Permalink
Closes mozilla-mobile#832 & For mozilla-mobile#222: Adds basic custom…
Browse files Browse the repository at this point in the history
… tab integration
  • Loading branch information
sblatz committed Mar 15, 2019
1 parent e1ebd2d commit e6b9e69
Show file tree
Hide file tree
Showing 4 changed files with 258 additions and 125 deletions.
19 changes: 19 additions & 0 deletions app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import org.mozilla.fenix.components.toolbar.ToolbarComponent
import org.mozilla.fenix.components.toolbar.ToolbarIntegration
import org.mozilla.fenix.components.toolbar.ToolbarMenu
import org.mozilla.fenix.components.toolbar.ToolbarUIView
import org.mozilla.fenix.customtabs.CustomTabsIntegration
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.ext.share
Expand All @@ -68,6 +69,8 @@ class BrowserFragment : Fragment(), BackHandler, ComponentCallbacks2 {
private val sitePermissionsFeature = ViewBoundFeatureWrapper<SitePermissionsFeature>()
private val fullScreenFeature = ViewBoundFeatureWrapper<FullScreenFeature>()
private val thumbnailsFeature = ViewBoundFeatureWrapper<ThumbnailsFeature>()
private val customTabsIntegration = ViewBoundFeatureWrapper<CustomTabsIntegration>()

var sessionId: String? = null

override fun onCreateView(
Expand Down Expand Up @@ -216,6 +219,22 @@ class BrowserFragment : Fragment(), BackHandler, ComponentCallbacks2 {
owner = this,
view = view
)

val actionEmitter = ActionBusFactory.get(this).getManagedEmitter(SearchAction::class.java)
sessionId?.let { id ->
customTabsIntegration.set(
feature = CustomTabsIntegration(
requireContext(),
requireComponents.core.sessionManager,
toolbar,
id,
requireActivity(),
onItemTapped = { actionEmitter.onNext(SearchAction.ToolbarMenuItemTapped(it)) }
),
owner = this,
view = view
)
}
}

override fun onResume() {
Expand Down
199 changes: 76 additions & 123 deletions app/src/main/java/org/mozilla/fenix/components/toolbar/ToolbarMenu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import mozilla.components.browser.menu.item.BrowserMenuDivider
import mozilla.components.browser.menu.item.BrowserMenuImageText
import mozilla.components.browser.menu.item.BrowserMenuItemToolbar
import mozilla.components.browser.menu.item.BrowserMenuSwitch
import mozilla.components.browser.menu.item.SimpleBrowserMenuItem
import mozilla.components.browser.session.runWithSession
import org.mozilla.fenix.DefaultThemeManager
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.components
Expand Down Expand Up @@ -109,128 +107,83 @@ class ToolbarMenu(
BrowserMenuItemToolbar(listOf(back, forward, refresh))
}

private val isCustomTab by lazy {
context.components.core.sessionManager.runWithSession(sessionId) {
it.isCustomTabSession()
}
}

private val menuItems by lazy {
if (isCustomTab) {
listOf(
SimpleBrowserMenuItem(
context.getString(R.string.browser_menu_powered_by),
CAPTION_TEXT_SIZE,
DefaultThemeManager.resolveAttribute(R.attr.browserToolbarMenuIcons, context)
),
BrowserMenuDivider(),
SimpleBrowserMenuItem(
context.getString(R.string.browser_menu_open_in_fenix),
textColorResource = DefaultThemeManager.resolveAttribute(
R.attr.browserToolbarMenuIcons,
context
)
) {
onItemTapped.invoke(Item.OpenInFenix)
},
BrowserMenuImageText(
context.getString(R.string.browser_menu_find_in_page),
R.drawable.mozac_ic_search,
DefaultThemeManager.resolveAttribute(R.attr.browserToolbarMenuIcons, context)
) {
onItemTapped.invoke(Item.FindInPage)
},
BrowserMenuSwitch(context.getString(R.string.browser_menu_desktop_site),
requestDesktopStateProvider, { checked ->
onItemTapped.invoke(Item.RequestDesktop(checked))
}),
BrowserMenuImageText(
context.getString(R.string.browser_menu_share),
R.drawable.mozac_ic_share,
DefaultThemeManager.resolveAttribute(R.attr.browserToolbarMenuIcons, context)
) {
onItemTapped.invoke(Item.Share)
},
menuToolbar
)
} else {
listOf(
BrowserMenuImageText(
context.getString(R.string.browser_menu_help),
R.drawable.ic_help,
DefaultThemeManager.resolveAttribute(R.attr.browserToolbarMenuIcons, context)
) {
onItemTapped.invoke(Item.Help)
},

BrowserMenuImageText(
context.getString(R.string.browser_menu_settings),
R.drawable.ic_settings,
DefaultThemeManager.resolveAttribute(R.attr.browserToolbarMenuIcons, context)
) {
onItemTapped.invoke(Item.Settings)
},

BrowserMenuImageText(
context.getString(R.string.browser_menu_library),
R.drawable.ic_library,
DefaultThemeManager.resolveAttribute(R.attr.browserToolbarMenuIcons, context)
) {
onItemTapped.invoke(Item.Library)
},

BrowserMenuDivider(),

BrowserMenuSwitch(context.getString(R.string.browser_menu_desktop_site),
requestDesktopStateProvider, { checked ->
onItemTapped.invoke(Item.RequestDesktop(checked))
}),

BrowserMenuImageText(
context.getString(R.string.browser_menu_find_in_page),
R.drawable.mozac_ic_search,
DefaultThemeManager.resolveAttribute(R.attr.browserToolbarMenuIcons, context)
) {
onItemTapped.invoke(Item.FindInPage)
},

BrowserMenuImageText(
context.getString(R.string.browser_menu_private_tab),
R.drawable.ic_private_browsing,
DefaultThemeManager.resolveAttribute(R.attr.browserToolbarMenuIcons, context)
) {
onItemTapped.invoke(Item.NewPrivateTab)
},

BrowserMenuImageText(
context.getString(R.string.browser_menu_new_tab),
R.drawable.ic_new,
DefaultThemeManager.resolveAttribute(R.attr.browserToolbarMenuIcons, context)
) {
onItemTapped.invoke(Item.NewTab)
},

BrowserMenuImageText(
context.getString(R.string.browser_menu_share),
R.drawable.mozac_ic_share,
DefaultThemeManager.resolveAttribute(R.attr.browserToolbarMenuIcons, context)
) {
onItemTapped.invoke(Item.Share)
},

BrowserMenuImageText(
context.getString(R.string.browser_menu_report_issue),
R.drawable.ic_report_issues,
DefaultThemeManager.resolveAttribute(R.attr.browserToolbarMenuIcons, context)
) {
onItemTapped.invoke(Item.ReportIssue)
},

BrowserMenuDivider(),

menuToolbar
)
}
listOf(
BrowserMenuImageText(
context.getString(R.string.browser_menu_help),
R.drawable.ic_help,
DefaultThemeManager.resolveAttribute(R.attr.browserToolbarMenuIcons, context)
) {
onItemTapped.invoke(Item.Help)
},

BrowserMenuImageText(
context.getString(R.string.browser_menu_settings),
R.drawable.ic_settings,
DefaultThemeManager.resolveAttribute(R.attr.browserToolbarMenuIcons, context)
) {
onItemTapped.invoke(Item.Settings)
},

BrowserMenuImageText(
context.getString(R.string.browser_menu_library),
R.drawable.ic_library,
DefaultThemeManager.resolveAttribute(R.attr.browserToolbarMenuIcons, context)
) {
onItemTapped.invoke(Item.Library)
},

BrowserMenuDivider(),

BrowserMenuSwitch(context.getString(R.string.browser_menu_desktop_site),
requestDesktopStateProvider, { checked ->
onItemTapped.invoke(Item.RequestDesktop(checked))
}),

BrowserMenuImageText(
context.getString(R.string.browser_menu_find_in_page),
R.drawable.mozac_ic_search,
DefaultThemeManager.resolveAttribute(R.attr.browserToolbarMenuIcons, context)
) {
onItemTapped.invoke(Item.FindInPage)
},

BrowserMenuImageText(
context.getString(R.string.browser_menu_private_tab),
R.drawable.ic_private_browsing,
DefaultThemeManager.resolveAttribute(R.attr.browserToolbarMenuIcons, context)
) {
onItemTapped.invoke(Item.NewPrivateTab)
},

BrowserMenuImageText(
context.getString(R.string.browser_menu_new_tab),
R.drawable.ic_new,
DefaultThemeManager.resolveAttribute(R.attr.browserToolbarMenuIcons, context)
) {
onItemTapped.invoke(Item.NewTab)
},

BrowserMenuImageText(
context.getString(R.string.browser_menu_share),
R.drawable.mozac_ic_share,
DefaultThemeManager.resolveAttribute(R.attr.browserToolbarMenuIcons, context)
) {
onItemTapped.invoke(Item.Share)
},

BrowserMenuImageText(
context.getString(R.string.browser_menu_report_issue),
R.drawable.ic_report_issues,
DefaultThemeManager.resolveAttribute(R.attr.browserToolbarMenuIcons, context)
) {
onItemTapped.invoke(Item.ReportIssue)
},

BrowserMenuDivider(),

menuToolbar
)
}

companion object {
Expand Down
Loading

0 comments on commit e6b9e69

Please sign in to comment.