You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
iceraven-browser/app/src/main/java/org/mozilla/fenix/components/toolbar/DefaultToolbarMenu.kt

499 lines
21 KiB
Kotlin

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.components.toolbar
import android.content.Context
import androidx.annotation.ColorRes
import androidx.annotation.VisibleForTesting
import androidx.annotation.VisibleForTesting.Companion.PRIVATE
import androidx.core.content.ContextCompat.getColor
[fenix] 4281 remove qab (https://github.com/mozilla-mobile/fenix/pull/6310) * For https://github.com/mozilla-mobile/fenix/issues/4281: small ToolbarMenu refactor This makes it easier to see how items are ordered in the menuItems list * For 4281: add QAB buttons to menu * For 4281: removed menu back button per mocks I double checked with UX, and we'll be relying on the hardware back button for its functionality * For 4281: add content descriptions for bookmarking * For 4281: updated BrowserToolbarController for new functionality * For 4281: provided simple dependencies to browser controller More complex changes will be in a following commit, for review readability * For 4281: move toolbar controller dependencies up to BaseBrowserFragment The functionality they control is being moved into the toolbar menu, which is shared by both normal tabs and custom ones * For 4281: removed (now unused) code related to QAB * For 4281: fix test compilation after QAB removal Tests still need to be expanded to include added functionality * For 4281: updated menu to show if url is bookmarked This sloppy workaround is required because TwoStateButton requires that `isInPrimaryState` be a synchronous call, and checking whether or not the current site is bookmarked is quite slow (10-50 MS, in my tests). After days of work and many attempted solutions, this was the least abhorrent among them. https://github.com/mozilla-mobile/android-components/issues/4915 was opened against AC to evaluate potentially supporting async `isInPrimaryState` functions. https://github.com/mozilla-mobile/fenix/issues/6370 was opened against Fenix to investigate the unexpectedly slow call to `BookmarkStorage`. * For 4281: update reader mode switch * For 4281: selectively show/hide menu items * For 4281: add reader mode appearance * For 4281: update bookmark button when it is clicked * For 4281: removed unused QAB code * For 4281: removed QAB robot, updated UI tests * For 4281: removed QuickActionSheet metrics Since this behavior now lives in the toolbar, it is tracked via Event.BrowserMenuItemTapped * For 4281: fixed lint errors * For 4281: add new strings for buttons added to menu This is necessary because the location change (from QAB to toolbar menu) could affect the grammar in some languages * For 4281: remove outdated TODOs * For 4281: removed QAB container * For 4281: removed back button reference from UI test This button no longer exists * For 4821: Fixes a visual defect (extra padding on top of toolbar) * For 4281: update copy on reader mode * For 4281: fixed review nits
5 years ago
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.lifecycleScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.mapNotNull
[fenix] 4281 remove qab (https://github.com/mozilla-mobile/fenix/pull/6310) * For https://github.com/mozilla-mobile/fenix/issues/4281: small ToolbarMenu refactor This makes it easier to see how items are ordered in the menuItems list * For 4281: add QAB buttons to menu * For 4281: removed menu back button per mocks I double checked with UX, and we'll be relying on the hardware back button for its functionality * For 4281: add content descriptions for bookmarking * For 4281: updated BrowserToolbarController for new functionality * For 4281: provided simple dependencies to browser controller More complex changes will be in a following commit, for review readability * For 4281: move toolbar controller dependencies up to BaseBrowserFragment The functionality they control is being moved into the toolbar menu, which is shared by both normal tabs and custom ones * For 4281: removed (now unused) code related to QAB * For 4281: fix test compilation after QAB removal Tests still need to be expanded to include added functionality * For 4281: updated menu to show if url is bookmarked This sloppy workaround is required because TwoStateButton requires that `isInPrimaryState` be a synchronous call, and checking whether or not the current site is bookmarked is quite slow (10-50 MS, in my tests). After days of work and many attempted solutions, this was the least abhorrent among them. https://github.com/mozilla-mobile/android-components/issues/4915 was opened against AC to evaluate potentially supporting async `isInPrimaryState` functions. https://github.com/mozilla-mobile/fenix/issues/6370 was opened against Fenix to investigate the unexpectedly slow call to `BookmarkStorage`. * For 4281: update reader mode switch * For 4281: selectively show/hide menu items * For 4281: add reader mode appearance * For 4281: update bookmark button when it is clicked * For 4281: removed unused QAB code * For 4281: removed QAB robot, updated UI tests * For 4281: removed QuickActionSheet metrics Since this behavior now lives in the toolbar, it is tracked via Event.BrowserMenuItemTapped * For 4281: fixed lint errors * For 4281: add new strings for buttons added to menu This is necessary because the location change (from QAB to toolbar menu) could affect the grammar in some languages * For 4281: remove outdated TODOs * For 4281: removed QAB container * For 4281: removed back button reference from UI test This button no longer exists * For 4821: Fixes a visual defect (extra padding on top of toolbar) * For 4281: update copy on reader mode * For 4281: fixed review nits
5 years ago
import kotlinx.coroutines.launch
import mozilla.components.browser.menu.BrowserMenuHighlight
import mozilla.components.browser.menu.BrowserMenuItem
import mozilla.components.browser.menu.WebExtensionBrowserMenuBuilder
import mozilla.components.browser.menu.item.BrowserMenuDivider
import mozilla.components.browser.menu.item.BrowserMenuHighlightableItem
import mozilla.components.browser.menu.item.BrowserMenuImageSwitch
import mozilla.components.browser.menu.item.BrowserMenuImageText
import mozilla.components.browser.menu.item.BrowserMenuImageTextCheckboxButton
import mozilla.components.browser.menu.item.BrowserMenuItemToolbar
import mozilla.components.browser.menu.item.TwoStateBrowserMenuImageText
import mozilla.components.browser.menu.item.WebExtensionPlaceholderMenuItem
import mozilla.components.browser.state.selector.findTab
import mozilla.components.browser.state.selector.selectedTab
import mozilla.components.browser.state.state.TabSessionState
import mozilla.components.browser.state.store.BrowserStore
[fenix] 4281 remove qab (https://github.com/mozilla-mobile/fenix/pull/6310) * For https://github.com/mozilla-mobile/fenix/issues/4281: small ToolbarMenu refactor This makes it easier to see how items are ordered in the menuItems list * For 4281: add QAB buttons to menu * For 4281: removed menu back button per mocks I double checked with UX, and we'll be relying on the hardware back button for its functionality * For 4281: add content descriptions for bookmarking * For 4281: updated BrowserToolbarController for new functionality * For 4281: provided simple dependencies to browser controller More complex changes will be in a following commit, for review readability * For 4281: move toolbar controller dependencies up to BaseBrowserFragment The functionality they control is being moved into the toolbar menu, which is shared by both normal tabs and custom ones * For 4281: removed (now unused) code related to QAB * For 4281: fix test compilation after QAB removal Tests still need to be expanded to include added functionality * For 4281: updated menu to show if url is bookmarked This sloppy workaround is required because TwoStateButton requires that `isInPrimaryState` be a synchronous call, and checking whether or not the current site is bookmarked is quite slow (10-50 MS, in my tests). After days of work and many attempted solutions, this was the least abhorrent among them. https://github.com/mozilla-mobile/android-components/issues/4915 was opened against AC to evaluate potentially supporting async `isInPrimaryState` functions. https://github.com/mozilla-mobile/fenix/issues/6370 was opened against Fenix to investigate the unexpectedly slow call to `BookmarkStorage`. * For 4281: update reader mode switch * For 4281: selectively show/hide menu items * For 4281: add reader mode appearance * For 4281: update bookmark button when it is clicked * For 4281: removed unused QAB code * For 4281: removed QAB robot, updated UI tests * For 4281: removed QuickActionSheet metrics Since this behavior now lives in the toolbar, it is tracked via Event.BrowserMenuItemTapped * For 4281: fixed lint errors * For 4281: add new strings for buttons added to menu This is necessary because the location change (from QAB to toolbar menu) could affect the grammar in some languages * For 4281: remove outdated TODOs * For 4281: removed QAB container * For 4281: removed back button reference from UI test This button no longer exists * For 4821: Fixes a visual defect (extra padding on top of toolbar) * For 4281: update copy on reader mode * For 4281: fixed review nits
5 years ago
import mozilla.components.concept.storage.BookmarksStorage
import mozilla.components.feature.top.sites.PinnedSiteStorage
import mozilla.components.feature.webcompat.reporter.WebCompatReporterFeature
import mozilla.components.lib.state.ext.flowScoped
import mozilla.components.support.ktx.android.content.getColorFromAttr
import mozilla.components.support.ktx.kotlinx.coroutines.flow.ifAnyChanged
import org.mozilla.fenix.Config
import org.mozilla.fenix.R
import org.mozilla.fenix.components.accounts.FenixAccountManager
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.nimbus.FxNimbus
import org.mozilla.fenix.theme.ThemeManager
/**
* Builds the toolbar object used with the 3-dot menu in the browser fragment.
* @param context a [Context] for accessing system resources.
* @param store reference to the application's [BrowserStore].
* @param hasAccountProblem If true, there was a problem signing into the Firefox account.
* @param onItemTapped Called when a menu item is tapped.
* @param lifecycleOwner View lifecycle owner used to determine when to cancel UI jobs.
* @param bookmarksStorage Used to check if a page is bookmarked.
* @param pinnedSiteStorage Used to check if the current url is a pinned site.
* @property isPinningSupported true if the launcher supports adding shortcuts.
*/
@Suppress("LargeClass", "TooManyFunctions")
open class DefaultToolbarMenu(
private val context: Context,
private val store: BrowserStore,
hasAccountProblem: Boolean = false,
[fenix] 4281 remove qab (https://github.com/mozilla-mobile/fenix/pull/6310) * For https://github.com/mozilla-mobile/fenix/issues/4281: small ToolbarMenu refactor This makes it easier to see how items are ordered in the menuItems list * For 4281: add QAB buttons to menu * For 4281: removed menu back button per mocks I double checked with UX, and we'll be relying on the hardware back button for its functionality * For 4281: add content descriptions for bookmarking * For 4281: updated BrowserToolbarController for new functionality * For 4281: provided simple dependencies to browser controller More complex changes will be in a following commit, for review readability * For 4281: move toolbar controller dependencies up to BaseBrowserFragment The functionality they control is being moved into the toolbar menu, which is shared by both normal tabs and custom ones * For 4281: removed (now unused) code related to QAB * For 4281: fix test compilation after QAB removal Tests still need to be expanded to include added functionality * For 4281: updated menu to show if url is bookmarked This sloppy workaround is required because TwoStateButton requires that `isInPrimaryState` be a synchronous call, and checking whether or not the current site is bookmarked is quite slow (10-50 MS, in my tests). After days of work and many attempted solutions, this was the least abhorrent among them. https://github.com/mozilla-mobile/android-components/issues/4915 was opened against AC to evaluate potentially supporting async `isInPrimaryState` functions. https://github.com/mozilla-mobile/fenix/issues/6370 was opened against Fenix to investigate the unexpectedly slow call to `BookmarkStorage`. * For 4281: update reader mode switch * For 4281: selectively show/hide menu items * For 4281: add reader mode appearance * For 4281: update bookmark button when it is clicked * For 4281: removed unused QAB code * For 4281: removed QAB robot, updated UI tests * For 4281: removed QuickActionSheet metrics Since this behavior now lives in the toolbar, it is tracked via Event.BrowserMenuItemTapped * For 4281: fixed lint errors * For 4281: add new strings for buttons added to menu This is necessary because the location change (from QAB to toolbar menu) could affect the grammar in some languages * For 4281: remove outdated TODOs * For 4281: removed QAB container * For 4281: removed back button reference from UI test This button no longer exists * For 4821: Fixes a visual defect (extra padding on top of toolbar) * For 4281: update copy on reader mode * For 4281: fixed review nits
5 years ago
private val onItemTapped: (ToolbarMenu.Item) -> Unit = {},
private val lifecycleOwner: LifecycleOwner,
private val bookmarksStorage: BookmarksStorage,
private val pinnedSiteStorage: PinnedSiteStorage,
@get:VisibleForTesting internal val isPinningSupported: Boolean,
) : ToolbarMenu {
private var isCurrentUrlPinned = false
private var isCurrentUrlBookmarked = false
[fenix] 4281 remove qab (https://github.com/mozilla-mobile/fenix/pull/6310) * For https://github.com/mozilla-mobile/fenix/issues/4281: small ToolbarMenu refactor This makes it easier to see how items are ordered in the menuItems list * For 4281: add QAB buttons to menu * For 4281: removed menu back button per mocks I double checked with UX, and we'll be relying on the hardware back button for its functionality * For 4281: add content descriptions for bookmarking * For 4281: updated BrowserToolbarController for new functionality * For 4281: provided simple dependencies to browser controller More complex changes will be in a following commit, for review readability * For 4281: move toolbar controller dependencies up to BaseBrowserFragment The functionality they control is being moved into the toolbar menu, which is shared by both normal tabs and custom ones * For 4281: removed (now unused) code related to QAB * For 4281: fix test compilation after QAB removal Tests still need to be expanded to include added functionality * For 4281: updated menu to show if url is bookmarked This sloppy workaround is required because TwoStateButton requires that `isInPrimaryState` be a synchronous call, and checking whether or not the current site is bookmarked is quite slow (10-50 MS, in my tests). After days of work and many attempted solutions, this was the least abhorrent among them. https://github.com/mozilla-mobile/android-components/issues/4915 was opened against AC to evaluate potentially supporting async `isInPrimaryState` functions. https://github.com/mozilla-mobile/fenix/issues/6370 was opened against Fenix to investigate the unexpectedly slow call to `BookmarkStorage`. * For 4281: update reader mode switch * For 4281: selectively show/hide menu items * For 4281: add reader mode appearance * For 4281: update bookmark button when it is clicked * For 4281: removed unused QAB code * For 4281: removed QAB robot, updated UI tests * For 4281: removed QuickActionSheet metrics Since this behavior now lives in the toolbar, it is tracked via Event.BrowserMenuItemTapped * For 4281: fixed lint errors * For 4281: add new strings for buttons added to menu This is necessary because the location change (from QAB to toolbar menu) could affect the grammar in some languages * For 4281: remove outdated TODOs * For 4281: removed QAB container * For 4281: removed back button reference from UI test This button no longer exists * For 4821: Fixes a visual defect (extra padding on top of toolbar) * For 4281: update copy on reader mode * For 4281: fixed review nits
5 years ago
private var isBookmarkedJob: Job? = null
private val shouldDeleteDataOnQuit = context.settings().shouldDeleteBrowsingDataOnQuit
private val shouldUseBottomToolbar = context.settings().shouldUseBottomToolbar
private val shouldShowMenuToolbar = !IncompleteRedesignToolbarFeature(context.settings()).isEnabled
private val shouldShowTopSites = context.settings().showTopSitesFeature
private val accountManager = FenixAccountManager(context)
private val selectedSession: TabSessionState?
get() = store.state.selectedTab
override val menuBuilder by lazy {
FxNimbus.features.print.recordExposure()
WebExtensionBrowserMenuBuilder(
items = coreMenuItems,
endOfMenuAlwaysVisible = shouldUseBottomToolbar,
store = store,
style = WebExtensionBrowserMenuBuilder.Style(
webExtIconTintColorResource = primaryTextColor(),
addonsManagerMenuItemDrawableRes = R.drawable.ic_addons_extensions,
),
onAddonsManagerTapped = {
onItemTapped.invoke(ToolbarMenu.Item.AddonsManager)
},
appendExtensionSubMenuAtStart = shouldUseBottomToolbar,
)
}
override val menuToolbar by lazy {
val back = BrowserMenuItemToolbar.TwoStateButton(
primaryImageResource = mozilla.components.ui.icons.R.drawable.mozac_ic_back_24,
primaryContentDescription = context.getString(R.string.browser_menu_back),
primaryImageTintResource = primaryTextColor(),
isInPrimaryState = {
selectedSession?.content?.canGoBack ?: true
},
secondaryImageTintResource = ThemeManager.resolveAttribute(R.attr.textDisabled, context),
disableInSecondaryState = true,
longClickListener = { onItemTapped.invoke(ToolbarMenu.Item.Back(viewHistory = true)) },
) {
onItemTapped.invoke(ToolbarMenu.Item.Back(viewHistory = false))
}
val forward = BrowserMenuItemToolbar.TwoStateButton(
primaryImageResource = mozilla.components.ui.icons.R.drawable.mozac_ic_forward_24,
primaryContentDescription = context.getString(R.string.browser_menu_forward),
primaryImageTintResource = primaryTextColor(),
isInPrimaryState = {
selectedSession?.content?.canGoForward ?: true
},
secondaryImageTintResource = ThemeManager.resolveAttribute(R.attr.textDisabled, context),
disableInSecondaryState = true,
longClickListener = { onItemTapped.invoke(ToolbarMenu.Item.Forward(viewHistory = true)) },
) {
onItemTapped.invoke(ToolbarMenu.Item.Forward(viewHistory = false))
}
val refresh = BrowserMenuItemToolbar.TwoStateButton(
primaryImageResource = mozilla.components.ui.icons.R.drawable.mozac_ic_arrow_clockwise_24,
primaryContentDescription = context.getString(R.string.browser_menu_refresh),
primaryImageTintResource = primaryTextColor(),
isInPrimaryState = {
selectedSession?.content?.loading == false
},
secondaryImageResource = mozilla.components.ui.icons.R.drawable.mozac_ic_stop,
secondaryContentDescription = context.getString(R.string.browser_menu_stop),
secondaryImageTintResource = primaryTextColor(),
disableInSecondaryState = false,
longClickListener = { onItemTapped.invoke(ToolbarMenu.Item.Reload(bypassCache = true)) },
) {
if (selectedSession?.content?.loading == true) {
onItemTapped.invoke(ToolbarMenu.Item.Stop)
} else {
onItemTapped.invoke(ToolbarMenu.Item.Reload(bypassCache = false))
}
}
[fenix] 4281 remove qab (https://github.com/mozilla-mobile/fenix/pull/6310) * For https://github.com/mozilla-mobile/fenix/issues/4281: small ToolbarMenu refactor This makes it easier to see how items are ordered in the menuItems list * For 4281: add QAB buttons to menu * For 4281: removed menu back button per mocks I double checked with UX, and we'll be relying on the hardware back button for its functionality * For 4281: add content descriptions for bookmarking * For 4281: updated BrowserToolbarController for new functionality * For 4281: provided simple dependencies to browser controller More complex changes will be in a following commit, for review readability * For 4281: move toolbar controller dependencies up to BaseBrowserFragment The functionality they control is being moved into the toolbar menu, which is shared by both normal tabs and custom ones * For 4281: removed (now unused) code related to QAB * For 4281: fix test compilation after QAB removal Tests still need to be expanded to include added functionality * For 4281: updated menu to show if url is bookmarked This sloppy workaround is required because TwoStateButton requires that `isInPrimaryState` be a synchronous call, and checking whether or not the current site is bookmarked is quite slow (10-50 MS, in my tests). After days of work and many attempted solutions, this was the least abhorrent among them. https://github.com/mozilla-mobile/android-components/issues/4915 was opened against AC to evaluate potentially supporting async `isInPrimaryState` functions. https://github.com/mozilla-mobile/fenix/issues/6370 was opened against Fenix to investigate the unexpectedly slow call to `BookmarkStorage`. * For 4281: update reader mode switch * For 4281: selectively show/hide menu items * For 4281: add reader mode appearance * For 4281: update bookmark button when it is clicked * For 4281: removed unused QAB code * For 4281: removed QAB robot, updated UI tests * For 4281: removed QuickActionSheet metrics Since this behavior now lives in the toolbar, it is tracked via Event.BrowserMenuItemTapped * For 4281: fixed lint errors * For 4281: add new strings for buttons added to menu This is necessary because the location change (from QAB to toolbar menu) could affect the grammar in some languages * For 4281: remove outdated TODOs * For 4281: removed QAB container * For 4281: removed back button reference from UI test This button no longer exists * For 4821: Fixes a visual defect (extra padding on top of toolbar) * For 4281: update copy on reader mode * For 4281: fixed review nits
5 years ago
val share = BrowserMenuItemToolbar.Button(
[fenix] For https://github.com/mozilla-mobile/fenix/issues/23350 - Revert changes from removing duplicate icons that already exists in ui-icons (https://github.com/mozilla-mobile/fenix/pull/23527) * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Override @color/mozac_ui_icons_fill with ?primaryText attribute" This reverts commit 4c630eba96182254daa4cdd2bbfeac23ab04690d. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_share with @drawable/mozac_ic_share" This reverts commit 072d3a3c9f87b77ed6381c36af7d9c812b8b371d. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_storage_enabled with @drawable/mozac_ic_storage" This reverts commit 10dde2baa6fd320443690a49dd6551938a2d83db. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_notifications_enabled with @drawable/mozac_ic_notification" This reverts commit 90943cfda427fd06d5e77b1e4fd0463bbe21e449. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_microphone_enabled with @drawable/mozac_ic_microphone" This reverts commit 200fd14d288b4b21c1711995f63d548f58fb1dc8. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_location_enabled with @drawable/mozac_ic_location" This reverts commit e85998bdc24dcdd17585581bd99aab35d5147f93. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_autoplay_disabled with @drawable/mozac_ic_autoplay_blocked" This reverts commit 0e408dc26e069719c895ae5279d3c11df6677699. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_camera_enabled with @drawable/mozac_ic_video" This reverts commit ceab2d77490b9b9b545ebbc14ee2a7b3811d3064. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/mozac_ic_extensions_black with @drawable/mozac_ic_extensions" This reverts commit 7bc005927acee0481c8936d000737ba7f738e2ba. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_top_sites with @drawable/mozac_ic_pin" This reverts commit f4d58ff722baa5dc9f7f811a758de75699bb8ccb. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_search with @drawable/mozac_ic_search" This reverts commit ac8f8632557ac07c32d040fbb0ddfa3cf1a0e5f6. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_readermode with @drawable/mozac_ic_reader_mode" This reverts commit d1953045b062a5b6fbedd990252834e9e1a6ca4f. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_menu with @drawable/mozac_ic_menu" This reverts commit 682b02101aa7e5ce82868de81d9b034701629976. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_login with @drawable/mozac_ic_login" This reverts commit 982c695260aaa10fc1f0ee7e6d2e271e9a214ce3. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_internet with @drawable/mozac_ic_globe" This reverts commit d248bfc21fff644bdc2141c4e24ae5bc125a41d2. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_download with @drawable/mozac_ic_download" This reverts commit 4cdceb393ac411a7b59d9c0e1164fddfb62bc494. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_lock with @drawable/mozac_ic_lock" This reverts commit 3878a83e30f318293b099bc49c690f953c2f3def. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_desktop with @drawable/mozac_ic_device_desktop" This reverts commit 8c4e6e23e0bf1ed762d9c3ab8566aff4df0a8eb1. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_close with @drawable/mozac_ic_close" This reverts commit 7f61c95923600eeabb8046380a31c1eaa4968525. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_delete with @drawable/mozac_ic_delete" This reverts commit b8814f62bffde0c192f078f8cd5e808d0f07af9d. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_chevron_up with @drawable/mozac_ic_arrowhead_up" This reverts commit 265b0a47cae6bed39ce9e8cc9af465705d1a2363. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_chevron_down with @drawable/mozac_ic_arrowhead_down" This reverts commit fe8a0b604941bbbb9dacff176cd17ce0485431ed. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_back_button with @drawable/mozac_ic_back" This reverts commit fb236b1c6175c1f8b5e6b1bf6d9f02c6a7fff9b9. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawable/ic_arrowhead_right with @drawable/mozac_ic_arrowhead_right" This reverts commit ae2f768ac02aa6b161b0bcbba7922f5f12e31e80. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawable/ic_new with @drawable/mozac_ic_new" This reverts commit ce5bb35a7cdbd189bb177900ec19bc6cb5a9bfa7. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawable/ic_addons_extensions with @drawable/mozac_ic_extensions" This reverts commit 1006637673965ebf70ad5e18e9a3598cf736347b.
2 years ago
imageResource = R.drawable.ic_share,
[fenix] 4281 remove qab (https://github.com/mozilla-mobile/fenix/pull/6310) * For https://github.com/mozilla-mobile/fenix/issues/4281: small ToolbarMenu refactor This makes it easier to see how items are ordered in the menuItems list * For 4281: add QAB buttons to menu * For 4281: removed menu back button per mocks I double checked with UX, and we'll be relying on the hardware back button for its functionality * For 4281: add content descriptions for bookmarking * For 4281: updated BrowserToolbarController for new functionality * For 4281: provided simple dependencies to browser controller More complex changes will be in a following commit, for review readability * For 4281: move toolbar controller dependencies up to BaseBrowserFragment The functionality they control is being moved into the toolbar menu, which is shared by both normal tabs and custom ones * For 4281: removed (now unused) code related to QAB * For 4281: fix test compilation after QAB removal Tests still need to be expanded to include added functionality * For 4281: updated menu to show if url is bookmarked This sloppy workaround is required because TwoStateButton requires that `isInPrimaryState` be a synchronous call, and checking whether or not the current site is bookmarked is quite slow (10-50 MS, in my tests). After days of work and many attempted solutions, this was the least abhorrent among them. https://github.com/mozilla-mobile/android-components/issues/4915 was opened against AC to evaluate potentially supporting async `isInPrimaryState` functions. https://github.com/mozilla-mobile/fenix/issues/6370 was opened against Fenix to investigate the unexpectedly slow call to `BookmarkStorage`. * For 4281: update reader mode switch * For 4281: selectively show/hide menu items * For 4281: add reader mode appearance * For 4281: update bookmark button when it is clicked * For 4281: removed unused QAB code * For 4281: removed QAB robot, updated UI tests * For 4281: removed QuickActionSheet metrics Since this behavior now lives in the toolbar, it is tracked via Event.BrowserMenuItemTapped * For 4281: fixed lint errors * For 4281: add new strings for buttons added to menu This is necessary because the location change (from QAB to toolbar menu) could affect the grammar in some languages * For 4281: remove outdated TODOs * For 4281: removed QAB container * For 4281: removed back button reference from UI test This button no longer exists * For 4821: Fixes a visual defect (extra padding on top of toolbar) * For 4281: update copy on reader mode * For 4281: fixed review nits
5 years ago
contentDescription = context.getString(R.string.browser_menu_share),
iconTintColorResource = primaryTextColor(),
[fenix] 4281 remove qab (https://github.com/mozilla-mobile/fenix/pull/6310) * For https://github.com/mozilla-mobile/fenix/issues/4281: small ToolbarMenu refactor This makes it easier to see how items are ordered in the menuItems list * For 4281: add QAB buttons to menu * For 4281: removed menu back button per mocks I double checked with UX, and we'll be relying on the hardware back button for its functionality * For 4281: add content descriptions for bookmarking * For 4281: updated BrowserToolbarController for new functionality * For 4281: provided simple dependencies to browser controller More complex changes will be in a following commit, for review readability * For 4281: move toolbar controller dependencies up to BaseBrowserFragment The functionality they control is being moved into the toolbar menu, which is shared by both normal tabs and custom ones * For 4281: removed (now unused) code related to QAB * For 4281: fix test compilation after QAB removal Tests still need to be expanded to include added functionality * For 4281: updated menu to show if url is bookmarked This sloppy workaround is required because TwoStateButton requires that `isInPrimaryState` be a synchronous call, and checking whether or not the current site is bookmarked is quite slow (10-50 MS, in my tests). After days of work and many attempted solutions, this was the least abhorrent among them. https://github.com/mozilla-mobile/android-components/issues/4915 was opened against AC to evaluate potentially supporting async `isInPrimaryState` functions. https://github.com/mozilla-mobile/fenix/issues/6370 was opened against Fenix to investigate the unexpectedly slow call to `BookmarkStorage`. * For 4281: update reader mode switch * For 4281: selectively show/hide menu items * For 4281: add reader mode appearance * For 4281: update bookmark button when it is clicked * For 4281: removed unused QAB code * For 4281: removed QAB robot, updated UI tests * For 4281: removed QuickActionSheet metrics Since this behavior now lives in the toolbar, it is tracked via Event.BrowserMenuItemTapped * For 4281: fixed lint errors * For 4281: add new strings for buttons added to menu This is necessary because the location change (from QAB to toolbar menu) could affect the grammar in some languages * For 4281: remove outdated TODOs * For 4281: removed QAB container * For 4281: removed back button reference from UI test This button no longer exists * For 4821: Fixes a visual defect (extra padding on top of toolbar) * For 4281: update copy on reader mode * For 4281: fixed review nits
5 years ago
listener = {
onItemTapped.invoke(ToolbarMenu.Item.Share)
},
[fenix] 4281 remove qab (https://github.com/mozilla-mobile/fenix/pull/6310) * For https://github.com/mozilla-mobile/fenix/issues/4281: small ToolbarMenu refactor This makes it easier to see how items are ordered in the menuItems list * For 4281: add QAB buttons to menu * For 4281: removed menu back button per mocks I double checked with UX, and we'll be relying on the hardware back button for its functionality * For 4281: add content descriptions for bookmarking * For 4281: updated BrowserToolbarController for new functionality * For 4281: provided simple dependencies to browser controller More complex changes will be in a following commit, for review readability * For 4281: move toolbar controller dependencies up to BaseBrowserFragment The functionality they control is being moved into the toolbar menu, which is shared by both normal tabs and custom ones * For 4281: removed (now unused) code related to QAB * For 4281: fix test compilation after QAB removal Tests still need to be expanded to include added functionality * For 4281: updated menu to show if url is bookmarked This sloppy workaround is required because TwoStateButton requires that `isInPrimaryState` be a synchronous call, and checking whether or not the current site is bookmarked is quite slow (10-50 MS, in my tests). After days of work and many attempted solutions, this was the least abhorrent among them. https://github.com/mozilla-mobile/android-components/issues/4915 was opened against AC to evaluate potentially supporting async `isInPrimaryState` functions. https://github.com/mozilla-mobile/fenix/issues/6370 was opened against Fenix to investigate the unexpectedly slow call to `BookmarkStorage`. * For 4281: update reader mode switch * For 4281: selectively show/hide menu items * For 4281: add reader mode appearance * For 4281: update bookmark button when it is clicked * For 4281: removed unused QAB code * For 4281: removed QAB robot, updated UI tests * For 4281: removed QuickActionSheet metrics Since this behavior now lives in the toolbar, it is tracked via Event.BrowserMenuItemTapped * For 4281: fixed lint errors * For 4281: add new strings for buttons added to menu This is necessary because the location change (from QAB to toolbar menu) could affect the grammar in some languages * For 4281: remove outdated TODOs * For 4281: removed QAB container * For 4281: removed back button reference from UI test This button no longer exists * For 4821: Fixes a visual defect (extra padding on top of toolbar) * For 4281: update copy on reader mode * For 4281: fixed review nits
5 years ago
)
registerForIsBookmarkedUpdates()
BrowserMenuItemToolbar(listOf(back, forward, share, refresh), isSticky = true)
}
// Predicates that need to be repeatedly called as the session changes
@VisibleForTesting(otherwise = PRIVATE)
fun canAddToHomescreen(): Boolean =
selectedSession != null && isPinningSupported &&
!context.components.useCases.webAppUseCases.isInstallable()
@VisibleForTesting(otherwise = PRIVATE)
fun canInstall(): Boolean =
selectedSession != null && isPinningSupported &&
context.components.useCases.webAppUseCases.isInstallable()
/**
* Should the "Open in regular tab" menu item be visible?
*/
@VisibleForTesting(otherwise = PRIVATE)
fun shouldShowOpenInRegularTab(): Boolean = selectedSession?.let { session ->
// This feature is gated behind Nightly for the time being.
Config.channel.isNightlyOrDebug &&
// This feature is explicitly for users opening links in private tabs.
context.settings().openLinksInAPrivateTab &&
// and is only visible in private tabs.
session.content.private
} ?: false
@VisibleForTesting(otherwise = PRIVATE)
fun shouldShowOpenInApp(): Boolean = selectedSession?.let { session ->
val appLink = context.components.useCases.appLinksUseCases.appLinkRedirect
appLink(session.content.url).hasExternalApp()
} ?: false
@VisibleForTesting(otherwise = PRIVATE)
fun shouldShowReaderViewCustomization(): Boolean = selectedSession?.let {
store.state.findTab(it.id)?.readerState?.active
} ?: false
/**
* Should Translations menu item be visible?
*/
@VisibleForTesting(otherwise = PRIVATE)
fun shouldShowTranslations(): Boolean = selectedSession?.let {
store.state.translationEngine.isEngineSupported == true &&
FxNimbus.features.translations.value().mainFlowBrowserMenuEnabled
} ?: false
// End of predicates //
private val installToHomescreen = BrowserMenuHighlightableItem(
label = context.getString(R.string.browser_menu_install_on_homescreen),
startImageResource = R.drawable.mozac_ic_add_to_homescreen_24,
iconTintColorResource = primaryTextColor(),
highlight = BrowserMenuHighlight.LowPriority(
label = context.getString(R.string.browser_menu_install_on_homescreen),
notificationTint = getColor(context, R.color.fx_mobile_icon_color_information),
),
isCollapsingMenuLimit = true,
isHighlighted = {
!context.settings().installPwaOpened
},
) {
onItemTapped.invoke(ToolbarMenu.Item.InstallPwaToHomeScreen)
}
@VisibleForTesting
internal val newTabItem = BrowserMenuImageText(
context.getString(R.string.library_new_tab),
[fenix] For https://github.com/mozilla-mobile/fenix/issues/23350 - Revert changes from removing duplicate icons that already exists in ui-icons (https://github.com/mozilla-mobile/fenix/pull/23527) * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Override @color/mozac_ui_icons_fill with ?primaryText attribute" This reverts commit 4c630eba96182254daa4cdd2bbfeac23ab04690d. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_share with @drawable/mozac_ic_share" This reverts commit 072d3a3c9f87b77ed6381c36af7d9c812b8b371d. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_storage_enabled with @drawable/mozac_ic_storage" This reverts commit 10dde2baa6fd320443690a49dd6551938a2d83db. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_notifications_enabled with @drawable/mozac_ic_notification" This reverts commit 90943cfda427fd06d5e77b1e4fd0463bbe21e449. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_microphone_enabled with @drawable/mozac_ic_microphone" This reverts commit 200fd14d288b4b21c1711995f63d548f58fb1dc8. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_location_enabled with @drawable/mozac_ic_location" This reverts commit e85998bdc24dcdd17585581bd99aab35d5147f93. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_autoplay_disabled with @drawable/mozac_ic_autoplay_blocked" This reverts commit 0e408dc26e069719c895ae5279d3c11df6677699. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_camera_enabled with @drawable/mozac_ic_video" This reverts commit ceab2d77490b9b9b545ebbc14ee2a7b3811d3064. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/mozac_ic_extensions_black with @drawable/mozac_ic_extensions" This reverts commit 7bc005927acee0481c8936d000737ba7f738e2ba. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_top_sites with @drawable/mozac_ic_pin" This reverts commit f4d58ff722baa5dc9f7f811a758de75699bb8ccb. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_search with @drawable/mozac_ic_search" This reverts commit ac8f8632557ac07c32d040fbb0ddfa3cf1a0e5f6. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_readermode with @drawable/mozac_ic_reader_mode" This reverts commit d1953045b062a5b6fbedd990252834e9e1a6ca4f. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_menu with @drawable/mozac_ic_menu" This reverts commit 682b02101aa7e5ce82868de81d9b034701629976. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_login with @drawable/mozac_ic_login" This reverts commit 982c695260aaa10fc1f0ee7e6d2e271e9a214ce3. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_internet with @drawable/mozac_ic_globe" This reverts commit d248bfc21fff644bdc2141c4e24ae5bc125a41d2. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_download with @drawable/mozac_ic_download" This reverts commit 4cdceb393ac411a7b59d9c0e1164fddfb62bc494. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_lock with @drawable/mozac_ic_lock" This reverts commit 3878a83e30f318293b099bc49c690f953c2f3def. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_desktop with @drawable/mozac_ic_device_desktop" This reverts commit 8c4e6e23e0bf1ed762d9c3ab8566aff4df0a8eb1. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_close with @drawable/mozac_ic_close" This reverts commit 7f61c95923600eeabb8046380a31c1eaa4968525. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_delete with @drawable/mozac_ic_delete" This reverts commit b8814f62bffde0c192f078f8cd5e808d0f07af9d. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_chevron_up with @drawable/mozac_ic_arrowhead_up" This reverts commit 265b0a47cae6bed39ce9e8cc9af465705d1a2363. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_chevron_down with @drawable/mozac_ic_arrowhead_down" This reverts commit fe8a0b604941bbbb9dacff176cd17ce0485431ed. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_back_button with @drawable/mozac_ic_back" This reverts commit fb236b1c6175c1f8b5e6b1bf6d9f02c6a7fff9b9. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawable/ic_arrowhead_right with @drawable/mozac_ic_arrowhead_right" This reverts commit ae2f768ac02aa6b161b0bcbba7922f5f12e31e80. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawable/ic_new with @drawable/mozac_ic_new" This reverts commit ce5bb35a7cdbd189bb177900ec19bc6cb5a9bfa7. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawable/ic_addons_extensions with @drawable/mozac_ic_extensions" This reverts commit 1006637673965ebf70ad5e18e9a3598cf736347b.
2 years ago
R.drawable.ic_new,
primaryTextColor(),
) {
onItemTapped.invoke(ToolbarMenu.Item.NewTab)
}
private val historyItem = BrowserMenuImageText(
context.getString(R.string.library_history),
R.drawable.ic_history,
primaryTextColor(),
) {
onItemTapped.invoke(ToolbarMenu.Item.History)
}
private val downloadsItem = BrowserMenuImageText(
context.getString(R.string.library_downloads),
[fenix] For https://github.com/mozilla-mobile/fenix/issues/23350 - Revert changes from removing duplicate icons that already exists in ui-icons (https://github.com/mozilla-mobile/fenix/pull/23527) * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Override @color/mozac_ui_icons_fill with ?primaryText attribute" This reverts commit 4c630eba96182254daa4cdd2bbfeac23ab04690d. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_share with @drawable/mozac_ic_share" This reverts commit 072d3a3c9f87b77ed6381c36af7d9c812b8b371d. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_storage_enabled with @drawable/mozac_ic_storage" This reverts commit 10dde2baa6fd320443690a49dd6551938a2d83db. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_notifications_enabled with @drawable/mozac_ic_notification" This reverts commit 90943cfda427fd06d5e77b1e4fd0463bbe21e449. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_microphone_enabled with @drawable/mozac_ic_microphone" This reverts commit 200fd14d288b4b21c1711995f63d548f58fb1dc8. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_location_enabled with @drawable/mozac_ic_location" This reverts commit e85998bdc24dcdd17585581bd99aab35d5147f93. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_autoplay_disabled with @drawable/mozac_ic_autoplay_blocked" This reverts commit 0e408dc26e069719c895ae5279d3c11df6677699. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_camera_enabled with @drawable/mozac_ic_video" This reverts commit ceab2d77490b9b9b545ebbc14ee2a7b3811d3064. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/mozac_ic_extensions_black with @drawable/mozac_ic_extensions" This reverts commit 7bc005927acee0481c8936d000737ba7f738e2ba. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_top_sites with @drawable/mozac_ic_pin" This reverts commit f4d58ff722baa5dc9f7f811a758de75699bb8ccb. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_search with @drawable/mozac_ic_search" This reverts commit ac8f8632557ac07c32d040fbb0ddfa3cf1a0e5f6. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_readermode with @drawable/mozac_ic_reader_mode" This reverts commit d1953045b062a5b6fbedd990252834e9e1a6ca4f. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_menu with @drawable/mozac_ic_menu" This reverts commit 682b02101aa7e5ce82868de81d9b034701629976. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_login with @drawable/mozac_ic_login" This reverts commit 982c695260aaa10fc1f0ee7e6d2e271e9a214ce3. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_internet with @drawable/mozac_ic_globe" This reverts commit d248bfc21fff644bdc2141c4e24ae5bc125a41d2. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_download with @drawable/mozac_ic_download" This reverts commit 4cdceb393ac411a7b59d9c0e1164fddfb62bc494. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_lock with @drawable/mozac_ic_lock" This reverts commit 3878a83e30f318293b099bc49c690f953c2f3def. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_desktop with @drawable/mozac_ic_device_desktop" This reverts commit 8c4e6e23e0bf1ed762d9c3ab8566aff4df0a8eb1. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_close with @drawable/mozac_ic_close" This reverts commit 7f61c95923600eeabb8046380a31c1eaa4968525. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_delete with @drawable/mozac_ic_delete" This reverts commit b8814f62bffde0c192f078f8cd5e808d0f07af9d. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_chevron_up with @drawable/mozac_ic_arrowhead_up" This reverts commit 265b0a47cae6bed39ce9e8cc9af465705d1a2363. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_chevron_down with @drawable/mozac_ic_arrowhead_down" This reverts commit fe8a0b604941bbbb9dacff176cd17ce0485431ed. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_back_button with @drawable/mozac_ic_back" This reverts commit fb236b1c6175c1f8b5e6b1bf6d9f02c6a7fff9b9. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawable/ic_arrowhead_right with @drawable/mozac_ic_arrowhead_right" This reverts commit ae2f768ac02aa6b161b0bcbba7922f5f12e31e80. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawable/ic_new with @drawable/mozac_ic_new" This reverts commit ce5bb35a7cdbd189bb177900ec19bc6cb5a9bfa7. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawable/ic_addons_extensions with @drawable/mozac_ic_extensions" This reverts commit 1006637673965ebf70ad5e18e9a3598cf736347b.
2 years ago
R.drawable.ic_download,
primaryTextColor(),
) {
onItemTapped.invoke(ToolbarMenu.Item.Downloads)
}
private val extensionsItem = WebExtensionPlaceholderMenuItem(
id = WebExtensionPlaceholderMenuItem.MAIN_EXTENSIONS_MENU_ID,
)
private val findInPageItem = BrowserMenuImageText(
label = context.getString(R.string.browser_menu_find_in_page),
imageResource = R.drawable.mozac_ic_search_24,
iconTintColorResource = primaryTextColor(),
) {
onItemTapped.invoke(ToolbarMenu.Item.FindInPage)
}
private val translationsItem = BrowserMenuImageText(
label = context.getString(R.string.browser_menu_translations),
imageResource = R.drawable.mozac_ic_translate_24,
iconTintColorResource = primaryTextColor(),
) {
onItemTapped.invoke(ToolbarMenu.Item.Translate)
}
private val desktopSiteItem = BrowserMenuImageSwitch(
[fenix] For https://github.com/mozilla-mobile/fenix/issues/23350 - Revert changes from removing duplicate icons that already exists in ui-icons (https://github.com/mozilla-mobile/fenix/pull/23527) * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Override @color/mozac_ui_icons_fill with ?primaryText attribute" This reverts commit 4c630eba96182254daa4cdd2bbfeac23ab04690d. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_share with @drawable/mozac_ic_share" This reverts commit 072d3a3c9f87b77ed6381c36af7d9c812b8b371d. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_storage_enabled with @drawable/mozac_ic_storage" This reverts commit 10dde2baa6fd320443690a49dd6551938a2d83db. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_notifications_enabled with @drawable/mozac_ic_notification" This reverts commit 90943cfda427fd06d5e77b1e4fd0463bbe21e449. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_microphone_enabled with @drawable/mozac_ic_microphone" This reverts commit 200fd14d288b4b21c1711995f63d548f58fb1dc8. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_location_enabled with @drawable/mozac_ic_location" This reverts commit e85998bdc24dcdd17585581bd99aab35d5147f93. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_autoplay_disabled with @drawable/mozac_ic_autoplay_blocked" This reverts commit 0e408dc26e069719c895ae5279d3c11df6677699. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_camera_enabled with @drawable/mozac_ic_video" This reverts commit ceab2d77490b9b9b545ebbc14ee2a7b3811d3064. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/mozac_ic_extensions_black with @drawable/mozac_ic_extensions" This reverts commit 7bc005927acee0481c8936d000737ba7f738e2ba. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_top_sites with @drawable/mozac_ic_pin" This reverts commit f4d58ff722baa5dc9f7f811a758de75699bb8ccb. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_search with @drawable/mozac_ic_search" This reverts commit ac8f8632557ac07c32d040fbb0ddfa3cf1a0e5f6. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_readermode with @drawable/mozac_ic_reader_mode" This reverts commit d1953045b062a5b6fbedd990252834e9e1a6ca4f. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_menu with @drawable/mozac_ic_menu" This reverts commit 682b02101aa7e5ce82868de81d9b034701629976. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_login with @drawable/mozac_ic_login" This reverts commit 982c695260aaa10fc1f0ee7e6d2e271e9a214ce3. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_internet with @drawable/mozac_ic_globe" This reverts commit d248bfc21fff644bdc2141c4e24ae5bc125a41d2. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_download with @drawable/mozac_ic_download" This reverts commit 4cdceb393ac411a7b59d9c0e1164fddfb62bc494. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_lock with @drawable/mozac_ic_lock" This reverts commit 3878a83e30f318293b099bc49c690f953c2f3def. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_desktop with @drawable/mozac_ic_device_desktop" This reverts commit 8c4e6e23e0bf1ed762d9c3ab8566aff4df0a8eb1. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_close with @drawable/mozac_ic_close" This reverts commit 7f61c95923600eeabb8046380a31c1eaa4968525. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_delete with @drawable/mozac_ic_delete" This reverts commit b8814f62bffde0c192f078f8cd5e808d0f07af9d. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_chevron_up with @drawable/mozac_ic_arrowhead_up" This reverts commit 265b0a47cae6bed39ce9e8cc9af465705d1a2363. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_chevron_down with @drawable/mozac_ic_arrowhead_down" This reverts commit fe8a0b604941bbbb9dacff176cd17ce0485431ed. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_back_button with @drawable/mozac_ic_back" This reverts commit fb236b1c6175c1f8b5e6b1bf6d9f02c6a7fff9b9. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawable/ic_arrowhead_right with @drawable/mozac_ic_arrowhead_right" This reverts commit ae2f768ac02aa6b161b0bcbba7922f5f12e31e80. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawable/ic_new with @drawable/mozac_ic_new" This reverts commit ce5bb35a7cdbd189bb177900ec19bc6cb5a9bfa7. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawable/ic_addons_extensions with @drawable/mozac_ic_extensions" This reverts commit 1006637673965ebf70ad5e18e9a3598cf736347b.
2 years ago
imageResource = R.drawable.ic_desktop,
label = context.getString(R.string.browser_menu_desktop_site),
initialState = {
selectedSession?.content?.desktopMode ?: false
},
) { checked ->
onItemTapped.invoke(ToolbarMenu.Item.RequestDesktop(checked))
}
private val openInRegularTabItem = BrowserMenuImageText(
label = context.getString(R.string.browser_menu_open_in_regular_tab),
imageResource = R.drawable.ic_open_in_regular_tab,
) {
onItemTapped.invoke(ToolbarMenu.Item.OpenInRegularTab)
}
private val customizeReaderView = BrowserMenuImageText(
label = context.getString(R.string.browser_menu_customize_reader_view),
imageResource = R.drawable.ic_readermode_appearance,
iconTintColorResource = primaryTextColor(),
) {
onItemTapped.invoke(ToolbarMenu.Item.CustomizeReaderView)
}
private val openInApp = BrowserMenuHighlightableItem(
label = context.getString(R.string.browser_menu_open_app_link),
startImageResource = R.drawable.ic_open_in_app,
iconTintColorResource = primaryTextColor(),
highlight = BrowserMenuHighlight.LowPriority(
label = context.getString(R.string.browser_menu_open_app_link),
notificationTint = getColor(context, R.color.fx_mobile_icon_color_information),
),
isHighlighted = { !context.settings().openInAppOpened },
) {
onItemTapped.invoke(ToolbarMenu.Item.OpenInApp)
}
private val reportSiteIssuePlaceholder = WebExtensionPlaceholderMenuItem(
id = WebCompatReporterFeature.WEBCOMPAT_REPORTER_EXTENSION_ID,
iconTintColorResource = primaryTextColor(),
)
private val addToHomeScreenItem = BrowserMenuImageText(
label = context.getString(R.string.browser_menu_add_to_homescreen),
imageResource = R.drawable.mozac_ic_add_to_homescreen_24,
iconTintColorResource = primaryTextColor(),
isCollapsingMenuLimit = true,
) {
onItemTapped.invoke(ToolbarMenu.Item.AddToHomeScreen)
}
private val addRemoveTopSitesItem = TwoStateBrowserMenuImageText(
primaryLabel = context.getString(R.string.browser_menu_add_to_shortcuts),
secondaryLabel = context.getString(R.string.browser_menu_remove_from_shortcuts),
[fenix] For https://github.com/mozilla-mobile/fenix/issues/23350 - Revert changes from removing duplicate icons that already exists in ui-icons (https://github.com/mozilla-mobile/fenix/pull/23527) * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Override @color/mozac_ui_icons_fill with ?primaryText attribute" This reverts commit 4c630eba96182254daa4cdd2bbfeac23ab04690d. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_share with @drawable/mozac_ic_share" This reverts commit 072d3a3c9f87b77ed6381c36af7d9c812b8b371d. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_storage_enabled with @drawable/mozac_ic_storage" This reverts commit 10dde2baa6fd320443690a49dd6551938a2d83db. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_notifications_enabled with @drawable/mozac_ic_notification" This reverts commit 90943cfda427fd06d5e77b1e4fd0463bbe21e449. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_microphone_enabled with @drawable/mozac_ic_microphone" This reverts commit 200fd14d288b4b21c1711995f63d548f58fb1dc8. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_location_enabled with @drawable/mozac_ic_location" This reverts commit e85998bdc24dcdd17585581bd99aab35d5147f93. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_autoplay_disabled with @drawable/mozac_ic_autoplay_blocked" This reverts commit 0e408dc26e069719c895ae5279d3c11df6677699. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_camera_enabled with @drawable/mozac_ic_video" This reverts commit ceab2d77490b9b9b545ebbc14ee2a7b3811d3064. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/mozac_ic_extensions_black with @drawable/mozac_ic_extensions" This reverts commit 7bc005927acee0481c8936d000737ba7f738e2ba. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_top_sites with @drawable/mozac_ic_pin" This reverts commit f4d58ff722baa5dc9f7f811a758de75699bb8ccb. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_search with @drawable/mozac_ic_search" This reverts commit ac8f8632557ac07c32d040fbb0ddfa3cf1a0e5f6. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_readermode with @drawable/mozac_ic_reader_mode" This reverts commit d1953045b062a5b6fbedd990252834e9e1a6ca4f. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_menu with @drawable/mozac_ic_menu" This reverts commit 682b02101aa7e5ce82868de81d9b034701629976. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_login with @drawable/mozac_ic_login" This reverts commit 982c695260aaa10fc1f0ee7e6d2e271e9a214ce3. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_internet with @drawable/mozac_ic_globe" This reverts commit d248bfc21fff644bdc2141c4e24ae5bc125a41d2. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_download with @drawable/mozac_ic_download" This reverts commit 4cdceb393ac411a7b59d9c0e1164fddfb62bc494. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_lock with @drawable/mozac_ic_lock" This reverts commit 3878a83e30f318293b099bc49c690f953c2f3def. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_desktop with @drawable/mozac_ic_device_desktop" This reverts commit 8c4e6e23e0bf1ed762d9c3ab8566aff4df0a8eb1. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_close with @drawable/mozac_ic_close" This reverts commit 7f61c95923600eeabb8046380a31c1eaa4968525. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_delete with @drawable/mozac_ic_delete" This reverts commit b8814f62bffde0c192f078f8cd5e808d0f07af9d. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_chevron_up with @drawable/mozac_ic_arrowhead_up" This reverts commit 265b0a47cae6bed39ce9e8cc9af465705d1a2363. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_chevron_down with @drawable/mozac_ic_arrowhead_down" This reverts commit fe8a0b604941bbbb9dacff176cd17ce0485431ed. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawble/ic_back_button with @drawable/mozac_ic_back" This reverts commit fb236b1c6175c1f8b5e6b1bf6d9f02c6a7fff9b9. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawable/ic_arrowhead_right with @drawable/mozac_ic_arrowhead_right" This reverts commit ae2f768ac02aa6b161b0bcbba7922f5f12e31e80. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawable/ic_new with @drawable/mozac_ic_new" This reverts commit ce5bb35a7cdbd189bb177900ec19bc6cb5a9bfa7. * Revert "For https://github.com/mozilla-mobile/fenix/issues/23121 - Replace @drawable/ic_addons_extensions with @drawable/mozac_ic_extensions" This reverts commit 1006637673965ebf70ad5e18e9a3598cf736347b.
2 years ago
primaryStateIconResource = R.drawable.ic_top_sites,
secondaryStateIconResource = R.drawable.ic_top_sites,
iconTintColorResource = primaryTextColor(),
isInPrimaryState = { !isCurrentUrlPinned },
isInSecondaryState = { isCurrentUrlPinned },
primaryStateAction = {
isCurrentUrlPinned = true
onItemTapped.invoke(ToolbarMenu.Item.AddToTopSites)
},
secondaryStateAction = {
isCurrentUrlPinned = false
onItemTapped.invoke(ToolbarMenu.Item.RemoveFromTopSites)
},
)
private val saveToCollectionItem = BrowserMenuImageText(
label = context.getString(R.string.browser_menu_save_to_collection_2),
imageResource = R.drawable.ic_tab_collection,
iconTintColorResource = primaryTextColor(),
) {
onItemTapped.invoke(ToolbarMenu.Item.SaveToCollection)
}
[fenix] 4281 remove qab (https://github.com/mozilla-mobile/fenix/pull/6310) * For https://github.com/mozilla-mobile/fenix/issues/4281: small ToolbarMenu refactor This makes it easier to see how items are ordered in the menuItems list * For 4281: add QAB buttons to menu * For 4281: removed menu back button per mocks I double checked with UX, and we'll be relying on the hardware back button for its functionality * For 4281: add content descriptions for bookmarking * For 4281: updated BrowserToolbarController for new functionality * For 4281: provided simple dependencies to browser controller More complex changes will be in a following commit, for review readability * For 4281: move toolbar controller dependencies up to BaseBrowserFragment The functionality they control is being moved into the toolbar menu, which is shared by both normal tabs and custom ones * For 4281: removed (now unused) code related to QAB * For 4281: fix test compilation after QAB removal Tests still need to be expanded to include added functionality * For 4281: updated menu to show if url is bookmarked This sloppy workaround is required because TwoStateButton requires that `isInPrimaryState` be a synchronous call, and checking whether or not the current site is bookmarked is quite slow (10-50 MS, in my tests). After days of work and many attempted solutions, this was the least abhorrent among them. https://github.com/mozilla-mobile/android-components/issues/4915 was opened against AC to evaluate potentially supporting async `isInPrimaryState` functions. https://github.com/mozilla-mobile/fenix/issues/6370 was opened against Fenix to investigate the unexpectedly slow call to `BookmarkStorage`. * For 4281: update reader mode switch * For 4281: selectively show/hide menu items * For 4281: add reader mode appearance * For 4281: update bookmark button when it is clicked * For 4281: removed unused QAB code * For 4281: removed QAB robot, updated UI tests * For 4281: removed QuickActionSheet metrics Since this behavior now lives in the toolbar, it is tracked via Event.BrowserMenuItemTapped * For 4281: fixed lint errors * For 4281: add new strings for buttons added to menu This is necessary because the location change (from QAB to toolbar menu) could affect the grammar in some languages * For 4281: remove outdated TODOs * For 4281: removed QAB container * For 4281: removed back button reference from UI test This button no longer exists * For 4821: Fixes a visual defect (extra padding on top of toolbar) * For 4281: update copy on reader mode * For 4281: fixed review nits
5 years ago
private val printPageItem = BrowserMenuImageText(
label = context.getString(R.string.menu_print),
imageResource = R.drawable.ic_print,
iconTintColorResource = primaryTextColor(),
) {
onItemTapped.invoke(ToolbarMenu.Item.PrintContent)
}
@VisibleForTesting
internal val settingsItem = BrowserMenuHighlightableItem(
label = context.getString(R.string.browser_menu_settings),
startImageResource = R.drawable.mozac_ic_settings_24,
iconTintColorResource = if (hasAccountProblem) {
ThemeManager.resolveAttribute(R.attr.syncDisconnected, context)
} else {
primaryTextColor()
},
textColorResource = if (hasAccountProblem) {
ThemeManager.resolveAttribute(R.attr.textPrimary, context)
} else {
primaryTextColor()
},
highlight = BrowserMenuHighlight.HighPriority(
endImageResource = R.drawable.ic_sync_disconnected,
backgroundTint = context.getColorFromAttr(R.attr.syncDisconnectedBackground),
canPropagate = false,
),
isHighlighted = { hasAccountProblem },
) {
onItemTapped.invoke(ToolbarMenu.Item.Settings)
}
[fenix] 4281 remove qab (https://github.com/mozilla-mobile/fenix/pull/6310) * For https://github.com/mozilla-mobile/fenix/issues/4281: small ToolbarMenu refactor This makes it easier to see how items are ordered in the menuItems list * For 4281: add QAB buttons to menu * For 4281: removed menu back button per mocks I double checked with UX, and we'll be relying on the hardware back button for its functionality * For 4281: add content descriptions for bookmarking * For 4281: updated BrowserToolbarController for new functionality * For 4281: provided simple dependencies to browser controller More complex changes will be in a following commit, for review readability * For 4281: move toolbar controller dependencies up to BaseBrowserFragment The functionality they control is being moved into the toolbar menu, which is shared by both normal tabs and custom ones * For 4281: removed (now unused) code related to QAB * For 4281: fix test compilation after QAB removal Tests still need to be expanded to include added functionality * For 4281: updated menu to show if url is bookmarked This sloppy workaround is required because TwoStateButton requires that `isInPrimaryState` be a synchronous call, and checking whether or not the current site is bookmarked is quite slow (10-50 MS, in my tests). After days of work and many attempted solutions, this was the least abhorrent among them. https://github.com/mozilla-mobile/android-components/issues/4915 was opened against AC to evaluate potentially supporting async `isInPrimaryState` functions. https://github.com/mozilla-mobile/fenix/issues/6370 was opened against Fenix to investigate the unexpectedly slow call to `BookmarkStorage`. * For 4281: update reader mode switch * For 4281: selectively show/hide menu items * For 4281: add reader mode appearance * For 4281: update bookmark button when it is clicked * For 4281: removed unused QAB code * For 4281: removed QAB robot, updated UI tests * For 4281: removed QuickActionSheet metrics Since this behavior now lives in the toolbar, it is tracked via Event.BrowserMenuItemTapped * For 4281: fixed lint errors * For 4281: add new strings for buttons added to menu This is necessary because the location change (from QAB to toolbar menu) could affect the grammar in some languages * For 4281: remove outdated TODOs * For 4281: removed QAB container * For 4281: removed back button reference from UI test This button no longer exists * For 4821: Fixes a visual defect (extra padding on top of toolbar) * For 4281: update copy on reader mode * For 4281: fixed review nits
5 years ago
private val bookmarksItem = BrowserMenuImageTextCheckboxButton(
imageResource = R.drawable.ic_bookmarks_menu,
iconTintColorResource = primaryTextColor(),
label = context.getString(R.string.library_bookmarks),
labelListener = {
onItemTapped.invoke(ToolbarMenu.Item.Bookmarks)
},
primaryStateIconResource = R.drawable.ic_bookmark_outline,
secondaryStateIconResource = R.drawable.ic_bookmark_filled,
tintColorResource = menuItemButtonTintColor(),
primaryLabel = context.getString(R.string.browser_menu_add),
secondaryLabel = context.getString(R.string.browser_menu_edit),
isInPrimaryState = { !isCurrentUrlBookmarked },
) {
handleBookmarkItemTapped()
}
private val deleteDataOnQuit = BrowserMenuImageText(
label = context.getString(R.string.delete_browsing_data_on_quit_action),
imageResource = R.drawable.mozac_ic_cross_circle_24,
iconTintColorResource = primaryTextColor(),
) {
onItemTapped.invoke(ToolbarMenu.Item.Quit)
}
private fun syncMenuItem(): BrowserMenuItem {
return BrowserMenuSignIn(primaryTextColor()) {
onItemTapped.invoke(
ToolbarMenu.Item.SyncAccount(accountManager.accountState),
)
}
}
@VisibleForTesting(otherwise = PRIVATE)
val coreMenuItems by lazy {
val menuItems =
listOfNotNull(
if (shouldUseBottomToolbar || !shouldShowMenuToolbar) null else menuToolbar,
newTabItem,
BrowserMenuDivider(),
bookmarksItem,
historyItem,
downloadsItem,
extensionsItem,
syncMenuItem(),
BrowserMenuDivider(),
findInPageItem,
translationsItem.apply { visible = ::shouldShowTranslations },
desktopSiteItem,
openInRegularTabItem.apply { visible = ::shouldShowOpenInRegularTab },
customizeReaderView.apply { visible = ::shouldShowReaderViewCustomization },
openInApp.apply { visible = ::shouldShowOpenInApp },
reportSiteIssuePlaceholder,
BrowserMenuDivider(),
addToHomeScreenItem.apply { visible = ::canAddToHomescreen },
installToHomescreen.apply { visible = ::canInstall },
if (shouldShowTopSites) addRemoveTopSitesItem else null,
saveToCollectionItem,
if (FxNimbus.features.print.value().browserPrintEnabled) printPageItem else null,
BrowserMenuDivider(),
settingsItem,
if (shouldDeleteDataOnQuit) deleteDataOnQuit else null,
if (shouldUseBottomToolbar) BrowserMenuDivider() else null,
if (shouldUseBottomToolbar && shouldShowMenuToolbar) menuToolbar else null,
)
menuItems
}
private fun handleBookmarkItemTapped() {
if (!isCurrentUrlBookmarked) isCurrentUrlBookmarked = true
onItemTapped.invoke(ToolbarMenu.Item.Bookmark)
}
@ColorRes
@VisibleForTesting
internal fun primaryTextColor() = ThemeManager.resolveAttribute(R.attr.textPrimary, context)
@ColorRes
@VisibleForTesting
internal fun menuItemButtonTintColor() = ThemeManager.resolveAttribute(R.attr.menuItemButtonTintColor, context)
@VisibleForTesting
internal fun updateIsCurrentUrlPinned(currentUrl: String) {
lifecycleOwner.lifecycleScope.launch {
isCurrentUrlPinned = pinnedSiteStorage
.getPinnedSites()
.find { it.url == currentUrl } != null
}
}
@VisibleForTesting
internal fun registerForIsBookmarkedUpdates() {
store.flowScoped(lifecycleOwner) { flow ->
flow.mapNotNull { state -> state.selectedTab }
.ifAnyChanged { tab ->
arrayOf(
tab.id,
tab.content.url,
)
}
.collect {
isCurrentUrlPinned = false
updateIsCurrentUrlPinned(it.content.url)
isCurrentUrlBookmarked = false
updateCurrentUrlIsBookmarked(it.content.url)
}
[fenix] 4281 remove qab (https://github.com/mozilla-mobile/fenix/pull/6310) * For https://github.com/mozilla-mobile/fenix/issues/4281: small ToolbarMenu refactor This makes it easier to see how items are ordered in the menuItems list * For 4281: add QAB buttons to menu * For 4281: removed menu back button per mocks I double checked with UX, and we'll be relying on the hardware back button for its functionality * For 4281: add content descriptions for bookmarking * For 4281: updated BrowserToolbarController for new functionality * For 4281: provided simple dependencies to browser controller More complex changes will be in a following commit, for review readability * For 4281: move toolbar controller dependencies up to BaseBrowserFragment The functionality they control is being moved into the toolbar menu, which is shared by both normal tabs and custom ones * For 4281: removed (now unused) code related to QAB * For 4281: fix test compilation after QAB removal Tests still need to be expanded to include added functionality * For 4281: updated menu to show if url is bookmarked This sloppy workaround is required because TwoStateButton requires that `isInPrimaryState` be a synchronous call, and checking whether or not the current site is bookmarked is quite slow (10-50 MS, in my tests). After days of work and many attempted solutions, this was the least abhorrent among them. https://github.com/mozilla-mobile/android-components/issues/4915 was opened against AC to evaluate potentially supporting async `isInPrimaryState` functions. https://github.com/mozilla-mobile/fenix/issues/6370 was opened against Fenix to investigate the unexpectedly slow call to `BookmarkStorage`. * For 4281: update reader mode switch * For 4281: selectively show/hide menu items * For 4281: add reader mode appearance * For 4281: update bookmark button when it is clicked * For 4281: removed unused QAB code * For 4281: removed QAB robot, updated UI tests * For 4281: removed QuickActionSheet metrics Since this behavior now lives in the toolbar, it is tracked via Event.BrowserMenuItemTapped * For 4281: fixed lint errors * For 4281: add new strings for buttons added to menu This is necessary because the location change (from QAB to toolbar menu) could affect the grammar in some languages * For 4281: remove outdated TODOs * For 4281: removed QAB container * For 4281: removed back button reference from UI test This button no longer exists * For 4821: Fixes a visual defect (extra padding on top of toolbar) * For 4281: update copy on reader mode * For 4281: fixed review nits
5 years ago
}
}
@VisibleForTesting
internal fun updateCurrentUrlIsBookmarked(newUrl: String) {
[fenix] 4281 remove qab (https://github.com/mozilla-mobile/fenix/pull/6310) * For https://github.com/mozilla-mobile/fenix/issues/4281: small ToolbarMenu refactor This makes it easier to see how items are ordered in the menuItems list * For 4281: add QAB buttons to menu * For 4281: removed menu back button per mocks I double checked with UX, and we'll be relying on the hardware back button for its functionality * For 4281: add content descriptions for bookmarking * For 4281: updated BrowserToolbarController for new functionality * For 4281: provided simple dependencies to browser controller More complex changes will be in a following commit, for review readability * For 4281: move toolbar controller dependencies up to BaseBrowserFragment The functionality they control is being moved into the toolbar menu, which is shared by both normal tabs and custom ones * For 4281: removed (now unused) code related to QAB * For 4281: fix test compilation after QAB removal Tests still need to be expanded to include added functionality * For 4281: updated menu to show if url is bookmarked This sloppy workaround is required because TwoStateButton requires that `isInPrimaryState` be a synchronous call, and checking whether or not the current site is bookmarked is quite slow (10-50 MS, in my tests). After days of work and many attempted solutions, this was the least abhorrent among them. https://github.com/mozilla-mobile/android-components/issues/4915 was opened against AC to evaluate potentially supporting async `isInPrimaryState` functions. https://github.com/mozilla-mobile/fenix/issues/6370 was opened against Fenix to investigate the unexpectedly slow call to `BookmarkStorage`. * For 4281: update reader mode switch * For 4281: selectively show/hide menu items * For 4281: add reader mode appearance * For 4281: update bookmark button when it is clicked * For 4281: removed unused QAB code * For 4281: removed QAB robot, updated UI tests * For 4281: removed QuickActionSheet metrics Since this behavior now lives in the toolbar, it is tracked via Event.BrowserMenuItemTapped * For 4281: fixed lint errors * For 4281: add new strings for buttons added to menu This is necessary because the location change (from QAB to toolbar menu) could affect the grammar in some languages * For 4281: remove outdated TODOs * For 4281: removed QAB container * For 4281: removed back button reference from UI test This button no longer exists * For 4821: Fixes a visual defect (extra padding on top of toolbar) * For 4281: update copy on reader mode * For 4281: fixed review nits
5 years ago
isBookmarkedJob?.cancel()
isBookmarkedJob = lifecycleOwner.lifecycleScope.launch {
isCurrentUrlBookmarked = bookmarksStorage
[fenix] 4281 remove qab (https://github.com/mozilla-mobile/fenix/pull/6310) * For https://github.com/mozilla-mobile/fenix/issues/4281: small ToolbarMenu refactor This makes it easier to see how items are ordered in the menuItems list * For 4281: add QAB buttons to menu * For 4281: removed menu back button per mocks I double checked with UX, and we'll be relying on the hardware back button for its functionality * For 4281: add content descriptions for bookmarking * For 4281: updated BrowserToolbarController for new functionality * For 4281: provided simple dependencies to browser controller More complex changes will be in a following commit, for review readability * For 4281: move toolbar controller dependencies up to BaseBrowserFragment The functionality they control is being moved into the toolbar menu, which is shared by both normal tabs and custom ones * For 4281: removed (now unused) code related to QAB * For 4281: fix test compilation after QAB removal Tests still need to be expanded to include added functionality * For 4281: updated menu to show if url is bookmarked This sloppy workaround is required because TwoStateButton requires that `isInPrimaryState` be a synchronous call, and checking whether or not the current site is bookmarked is quite slow (10-50 MS, in my tests). After days of work and many attempted solutions, this was the least abhorrent among them. https://github.com/mozilla-mobile/android-components/issues/4915 was opened against AC to evaluate potentially supporting async `isInPrimaryState` functions. https://github.com/mozilla-mobile/fenix/issues/6370 was opened against Fenix to investigate the unexpectedly slow call to `BookmarkStorage`. * For 4281: update reader mode switch * For 4281: selectively show/hide menu items * For 4281: add reader mode appearance * For 4281: update bookmark button when it is clicked * For 4281: removed unused QAB code * For 4281: removed QAB robot, updated UI tests * For 4281: removed QuickActionSheet metrics Since this behavior now lives in the toolbar, it is tracked via Event.BrowserMenuItemTapped * For 4281: fixed lint errors * For 4281: add new strings for buttons added to menu This is necessary because the location change (from QAB to toolbar menu) could affect the grammar in some languages * For 4281: remove outdated TODOs * For 4281: removed QAB container * For 4281: removed back button reference from UI test This button no longer exists * For 4821: Fixes a visual defect (extra padding on top of toolbar) * For 4281: update copy on reader mode * For 4281: fixed review nits
5 years ago
.getBookmarksWithUrl(newUrl)
.any { it.url == newUrl }
}
}
}