Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
Closes #832: Adds custom tabs menu (#944)
Browse files Browse the repository at this point in the history
  • Loading branch information
sblatz authored Mar 13, 2019
1 parent 78c3db1 commit 33b83fb
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 83 deletions.
10 changes: 10 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 @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
}
}

Expand Down
199 changes: 123 additions & 76 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,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 = {}
) {
Expand All @@ -31,6 +35,7 @@ class ToolbarMenu(
object Forward : Item()
object Reload : Item()
object ReportIssue : Item()
object OpenInFenix : Item()
}

val menuBuilder by lazy { BrowserMenuBuilder(menuItems) }
Expand Down Expand Up @@ -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)
},

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
)
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
)
}
}

companion object {
const val CAPTION_TEXT_SIZE = 12f
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class ToolbarUIView(
this,
view,
ToolbarMenu(this,
sessionId = sessionId,
requestDesktopStateProvider = { session?.desktopMode ?: false },
onItemTapped = { actionEmitter.onNext(SearchAction.ToolbarMenuItemTapped(it)) }
),
Expand Down
21 changes: 14 additions & 7 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -16,13 +17,15 @@
<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>
<!-- Explanation for private browsing displayed to users on home view when they first enable private mode -->
<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>
Expand Down Expand Up @@ -52,16 +55,23 @@
<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>
<!-- Button in the search view that lets a user search by using a shortcut -->
<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>
Expand Down Expand Up @@ -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>

Expand Down Expand Up @@ -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>
Expand All @@ -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 -->
Expand All @@ -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>

0 comments on commit 33b83fb

Please sign in to comment.