1
0
Fork 0

Closes #832: Adds custom tabs menu (#944)

master
Sawyer Blatz 2019-03-13 09:47:23 -07:00 committed by GitHub
parent 78c3db1fc8
commit 33b83fb0e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 137 additions and 72 deletions

View File

@ -6,6 +6,7 @@ package org.mozilla.fenix.browser
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.view.Gravity
import android.view.LayoutInflater
@ -37,6 +38,7 @@ import mozilla.components.support.ktx.android.view.exitImmersiveModeIfNeeded
import org.mozilla.fenix.BrowsingModeManager
import org.mozilla.fenix.DefaultThemeManager
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.IntentReceiverActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.components.FindInPageIntegration
import org.mozilla.fenix.components.toolbar.SearchAction
@ -45,6 +47,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.ext.components
import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.ext.share
import org.mozilla.fenix.mvi.ActionBusFactory
@ -289,6 +292,13 @@ class BrowserFragment : Fragment(), BackHandler {
Navigation.findNavController(view!!).navigate(directions)
(activity as HomeActivity).browsingModeManager.mode = BrowsingModeManager.Mode.Normal
}
ToolbarMenu.Item.OpenInFenix -> {
val intent = Intent(context, IntentReceiverActivity::class.java)
val session = context!!.components.core.sessionManager.findSessionById(sessionId!!)
intent.action = Intent.ACTION_VIEW
intent.data = Uri.parse(session?.url)
startActivity(intent)
}
}
}

View File

@ -10,11 +10,15 @@ 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
class ToolbarMenu(
private val context: Context,
private val sessionId: String?,
private val requestDesktopStateProvider: () -> Boolean = { false },
private val onItemTapped: (Item) -> Unit = {}
) {
@ -31,6 +35,7 @@ class ToolbarMenu(
object Forward : Item()
object Reload : Item()
object ReportIssue : Item()
object OpenInFenix : Item()
}
val menuBuilder by lazy { BrowserMenuBuilder(menuItems) }
@ -63,82 +68,124 @@ 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 {
listOf(
BrowserMenuImageText(
context.getString(R.string.browser_menu_help),
R.drawable.ic_help,
DefaultThemeManager.resolveAttribute(R.attr.browserToolbarMenuIcons, context)
) {
onItemTapped.invoke(Item.Help)
},
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_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)
},
BrowserMenuImageText(
context.getString(R.string.browser_menu_library),
R.drawable.ic_library,
DefaultThemeManager.resolveAttribute(R.attr.browserToolbarMenuIcons, context)
) {
onItemTapped.invoke(Item.Library)
},
BrowserMenuDivider(),
BrowserMenuDivider(),
BrowserMenuSwitch(context.getString(R.string.browser_menu_desktop_site),
requestDesktopStateProvider, { checked ->
onItemTapped.invoke(Item.RequestDesktop(checked))
}),
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_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_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_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_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)
},
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(),
BrowserMenuDivider(),
menuToolbar
)
menuToolbar
)
}
}
companion object {
const val CAPTION_TEXT_SIZE = 12f
}
}

View File

@ -72,6 +72,7 @@ class ToolbarUIView(
this,
view,
ToolbarMenu(this,
sessionId = sessionId,
requestDesktopStateProvider = { session?.desktopMode ?: false },
onItemTapped = { actionEmitter.onNext(SearchAction.ToolbarMenuItemTapped(it)) }
),

View File

@ -5,6 +5,7 @@
<resources>
<!-- Name of the application -->
<string name="app_name">Fenix</string>
<!-- Home Fragment -->
<!-- Content description (not visible, for screen readers etc.): "Three dot" menu button. -->
<string name="content_description_menu">More options</string>
@ -16,6 +17,7 @@
<string name="sessions_intro_description">Sessions help you return to the sites you visit often and those you\'ve just discovered. Start browsing and they\'ll begin to appear here. </string>
<!-- Placeholder text shown in the search bar before a user enters text -->
<string name="search_hint">Search or enter address</string>
<!-- Private Browsing -->
<!-- Title for private session option -->
<string name="private_browsing_title">You\'re in a private session</string>
@ -23,6 +25,7 @@
<string name="private_browsing_explanation">Fenix clears your search and browsing history when you close your private session. While this doesn\'t make you anonymous to websites or your internet service provider, it makes it easier to keep what you do online private from anyone else who uses this device.\n\nCommon myths about private browsing</string>
<!-- Delete session button to erase your history in a private session -->
<string name="private_browsing_delete_session">Delete session</string>
<!-- Browser Fragment -->
<!-- Content description (not visible, for screen readers etc.): Navigate home -->
<string name="browser_home_button">Home</string>
@ -52,6 +55,11 @@
<string name="browser_menu_share">Share</string>
<!-- Share menu title, displayed when a user is sharing their current site -->
<string name="menu_share_with">Share with…</string>
<!-- Browser menu button shown in custom tabs that opens the current tab in Fenix -->
<string name="browser_menu_open_in_fenix">Open in Fenix"</string>
<!-- Browser menu text shown in custom tabs to indicate this is a Fenix tab -->
<string name="browser_menu_powered_by">POWERED BY FENIX"</string>
<!-- Search Fragment -->
<!-- Button in the search view that lets a user search by scanning a QR code -->
<string name="search_scan_button">Scan</string>
@ -59,9 +67,11 @@
<string name="search_shortcuts_button">Shortcuts</string>
<!-- Button in the search view that lets a user navigate to the site in their clipboard -->
<string name="awesomebar_clipboard_title">Fill link from clipboard</string>
<!-- Settings Fragment -->
<!-- Title for the settings page-->
<string name="settings">Settings</string>
<!-- Preferences -->
<!-- Preference category for basic settings -->
<string name="preferences_category_basics">Basics</string>
@ -103,10 +113,8 @@
<string name="preferences_data_choices">Data choices</string>
<!-- Preference for developers -->
<string name="preference_leakcanary">Leak Canary</string>
<!-- Preference title for switch preference to show search suggestions -->
<string name="preferences_show_search_suggestions">Show search suggestions</string>
<!-- Preference for account settings -->
<string name="preferences_account_settings">Account Settings</string>
@ -156,6 +164,7 @@
<p>%1$s puts you in control.</p>
<p>%1$s is produced by Mozilla. Our mission is to foster a healthy, open Internet.<br/>
]]></string>
<!-- Sessions -->
<!-- Title for the list of tabs in the current session -->
<string name="tabs_header_title">Current Session</string>
@ -177,20 +186,17 @@
<string name="current_session_send_and_share">Send and Share</string>
<!-- Content description (not visible, for screen readers etc.): Title icon for current session menu -->
<string name="current_session_image">Current session image</string>
<!-- Text for the button to save a session -->
<string name="session_save">Save Session</string>
<!-- Text for the button to delete a session -->
<string name="session_delete">Delete Session</string>
<!-- Text for the button to delete a single session -->
<string name="session_item_delete">Delete</string>
<!-- Text to tell the user how many more tabs this session has.
The first parameter is how many extra tabs the session has. -->
<string name="session_items_more">%1$d sites…</string>
<!-- History -->
<!-- Text for the button to clear all history -->
<string name="history_delete_all">Delete history</string>
<!-- Text for the button to delete a single history item -->
@ -199,5 +205,6 @@
is the number of items you have selected -->
<string name="history_delete_some">Delete %1$d items</string>
<string name="full_screen_notification">Entering full screen mode</string>q
<!-- Text displayed in a notification when the user enters full screen mode -->
<string name="full_screen_notification">Entering full screen mode</string>
</resources>