Skip to content

Commit

Permalink
For mozilla-mobile#8474 Reorganize browser menu items
Browse files Browse the repository at this point in the history
  • Loading branch information
mcarare committed Mar 11, 2020
1 parent 709bf6f commit b0e41f5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import org.mozilla.fenix.R
import org.mozilla.fenix.browser.BrowserAnimator
import org.mozilla.fenix.browser.BrowserFragment
import org.mozilla.fenix.browser.BrowserFragmentDirections
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
import org.mozilla.fenix.browser.browsingmode.BrowsingModeManager
import org.mozilla.fenix.browser.readermode.ReaderModeController
import org.mozilla.fenix.collections.SaveCollectionStep
Expand Down Expand Up @@ -183,24 +182,7 @@ class DefaultBrowserToolbarController(
)
navController.navigate(directions)
}
ToolbarMenu.Item.NewTab -> {
val directions = BrowserFragmentDirections.actionBrowserFragmentToSearchFragment(
sessionId = null
)

// Do not adjustBackground here or an exception gets thrown as we switch themes
navController.nav(R.id.browserFragment, directions)
browsingModeManager.mode = BrowsingMode.Normal
}
ToolbarMenu.Item.NewPrivateTab -> {
val directions = BrowserFragmentDirections.actionBrowserFragmentToSearchFragment(
sessionId = null
)

// Do not adjustBackground here or an exception gets thrown as we switch themes
navController.nav(R.id.browserFragment, directions)
browsingModeManager.mode = BrowsingMode.Private
}
ToolbarMenu.Item.FindInPage -> {
findInPageLauncher()
activity.components.analytics.metrics.track(Event.FindInPageOpened)
Expand All @@ -212,9 +194,7 @@ class DefaultBrowserToolbarController(
activity.components.useCases.tabsUseCases.addTab.invoke(reportUrl)
}
}
ToolbarMenu.Item.Help -> {
activity.components.useCases.tabsUseCases.addTab.invoke(getSupportUrl())
}

ToolbarMenu.Item.AddonsManager -> {
navController.nav(
R.id.browserFragment,
Expand Down Expand Up @@ -331,11 +311,8 @@ class DefaultBrowserToolbarController(
Event.BrowserMenuItemTapped.Item.DESKTOP_VIEW_OFF
}

ToolbarMenu.Item.NewPrivateTab -> Event.BrowserMenuItemTapped.Item.NEW_PRIVATE_TAB
ToolbarMenu.Item.FindInPage -> Event.BrowserMenuItemTapped.Item.FIND_IN_PAGE
ToolbarMenu.Item.ReportIssue -> Event.BrowserMenuItemTapped.Item.REPORT_SITE_ISSUE
ToolbarMenu.Item.Help -> Event.BrowserMenuItemTapped.Item.HELP
ToolbarMenu.Item.NewTab -> Event.BrowserMenuItemTapped.Item.NEW_TAB
ToolbarMenu.Item.OpenInFenix -> Event.BrowserMenuItemTapped.Item.OPEN_IN_FENIX
ToolbarMenu.Item.Share -> Event.BrowserMenuItemTapped.Item.SHARE
ToolbarMenu.Item.SaveToCollection -> Event.BrowserMenuItemTapped.Item.SAVE_TO_COLLECTION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class DefaultToolbarMenu(
onItemTapped.invoke(ToolbarMenu.Item.Bookmark)
}

BrowserMenuItemToolbar(listOf(forward, bookmark, share, refresh))
BrowserMenuItemToolbar(listOf(bookmark, share, forward, refresh))
}

private val menuItems by lazy {
Expand All @@ -153,22 +153,20 @@ class DefaultToolbarMenu(
fun shouldShowReaderAppearance(): Boolean = session?.readerMode ?: false

val menuItems = listOfNotNull(
help,
settings,
library,
desktopMode,
addToTopSites,
addToHomescreen.apply { visible = ::shouldShowAddToHomescreen },
addons,
findInPage,
privateTab,
newTab,
settings,
if (shouldDeleteDataOnQuit) deleteDataOnQuit else null,
BrowserMenuDivider(),
if (shouldShowWebcompatReporter) reportIssue else null,
findInPage,
addToTopSites,
addToHomescreen.apply { visible = ::shouldShowAddToHomescreen },
if (shouldShowSaveToCollection) saveToCollection else null,
if (shouldDeleteDataOnQuit) deleteDataOnQuit else null,
desktopMode,
openInApp.apply { visible = ::shouldShowOpenInApp },
readerMode.apply { visible = ::shouldShowReaderMode },
readerAppearance.apply { visible = ::shouldShowReaderAppearance },
openInApp.apply { visible = ::shouldShowOpenInApp },
BrowserMenuDivider(),
menuToolbar
)
Expand All @@ -184,14 +182,6 @@ class DefaultToolbarMenu(
onItemTapped.invoke(ToolbarMenu.Item.AddonsManager)
}

private val help = BrowserMenuImageText(
label = context.getString(R.string.browser_menu_help),
imageResource = R.drawable.ic_help,
iconTintColorResource = primaryTextColor()
) {
onItemTapped.invoke(ToolbarMenu.Item.Help)
}

private val settings = BrowserMenuHighlightableItem(
label = context.getString(R.string.browser_menu_settings),
startImageResource = R.drawable.ic_settings,
Expand Down Expand Up @@ -260,22 +250,6 @@ class DefaultToolbarMenu(
onItemTapped.invoke(ToolbarMenu.Item.FindInPage)
}

private val privateTab = BrowserMenuImageText(
label = context.getString(R.string.browser_menu_private_tab),
imageResource = R.drawable.ic_private_browsing,
iconTintColorResource = primaryTextColor()
) {
onItemTapped.invoke(ToolbarMenu.Item.NewPrivateTab)
}

private val newTab = BrowserMenuImageText(
label = context.getString(R.string.browser_menu_new_tab),
imageResource = R.drawable.ic_new,
iconTintColorResource = primaryTextColor()
) {
onItemTapped.invoke(ToolbarMenu.Item.NewTab)
}

private val reportIssue = BrowserMenuImageText(
label = context.getString(R.string.browser_menu_report_issue),
imageResource = R.drawable.ic_report_issues,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@ import mozilla.components.browser.menu.item.BrowserMenuItemToolbar

interface ToolbarMenu {
sealed class Item {
object Help : Item()
object Settings : Item()
object Library : Item()
data class RequestDesktop(val isChecked: Boolean) : Item()
object FindInPage : Item()
object NewPrivateTab : Item()
object NewTab : Item()
object Share : Item()
object Back : Item()
object Forward : Item()
Expand Down

0 comments on commit b0e41f5

Please sign in to comment.