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/customtabs/CustomTabToolbarMenu.kt

192 lines
8.2 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.customtabs
import android.content.Context
import android.graphics.Typeface
import androidx.annotation.ColorRes
import androidx.annotation.VisibleForTesting
import androidx.core.content.ContextCompat.getColor
import mozilla.components.browser.menu.BrowserMenuBuilder
import mozilla.components.browser.menu.BrowserMenuHighlight
import mozilla.components.browser.menu.item.BrowserMenuCategory
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.BrowserMenuItemToolbar
import mozilla.components.browser.menu.item.SimpleBrowserMenuItem
import mozilla.components.browser.state.selector.findCustomTab
import mozilla.components.browser.state.state.CustomTabSessionState
import mozilla.components.browser.state.store.BrowserStore
import org.mozilla.fenix.R
import org.mozilla.fenix.components.toolbar.IncompleteRedesignToolbarFeature
import org.mozilla.fenix.components.toolbar.ToolbarMenu
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.getStringWithArgSafe
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.theme.ThemeManager
import java.util.Locale
/**
* Builds the toolbar object used with the 3-dot menu in the custom tab browser fragment.
*
* @param context An Android [Context].
* @param store reference to the application's [BrowserStore].
* @param sessionId ID of the open custom tab session.
* @param shouldReverseItems If true, reverse the menu items.
* @param isSandboxCustomTab If true, menu should not show the "Open in Firefox" and "POWERED BY FIREFOX" items.
* @param onItemTapped Called when a menu item is tapped.
*/
class CustomTabToolbarMenu(
private val context: Context,
private val store: BrowserStore,
private val sessionId: String?,
private val shouldReverseItems: Boolean,
private val isSandboxCustomTab: Boolean,
private val onItemTapped: (ToolbarMenu.Item) -> Unit = {},
) : ToolbarMenu {
override val menuBuilder by lazy { BrowserMenuBuilder(menuItems) }
/** Gets the current custom tab session */
@VisibleForTesting
internal val session: CustomTabSessionState? get() = sessionId?.let { store.state.findCustomTab(it) }
private val appName = context.getString(R.string.app_name)
private val shouldShowMenuToolbar = !IncompleteRedesignToolbarFeature(context.settings()).isEnabled
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 = {
session?.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 = {
session?.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 = {
session?.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 (session?.content?.loading == true) {
onItemTapped.invoke(ToolbarMenu.Item.Stop)
} else {
onItemTapped.invoke(ToolbarMenu.Item.Reload(bypassCache = false))
}
}
BrowserMenuItemToolbar(listOf(back, forward, refresh))
}
private fun shouldShowOpenInApp(): Boolean = session?.let { session ->
val appLink = context.components.useCases.appLinksUseCases.appLinkRedirect
appLink(session.content.url).hasExternalApp()
} ?: false
private val menuItems by lazy {
val menuItems = listOfNotNull(
poweredBy.apply { visible = { !isSandboxCustomTab } },
BrowserMenuDivider().apply { visible = { !isSandboxCustomTab } },
[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
desktopMode,
findInPage,
openInApp.apply { visible = ::shouldShowOpenInApp },
openInFenix.apply { visible = { !isSandboxCustomTab } },
[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
BrowserMenuDivider(),
if (shouldShowMenuToolbar) menuToolbar else null,
[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
)
if (shouldReverseItems) {
menuItems.reversed()
} else {
menuItems
}
[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 desktopMode = 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,
[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
label = context.getString(R.string.browser_menu_desktop_site),
initialState = { session?.content?.desktopMode ?: false },
) { checked ->
onItemTapped.invoke(ToolbarMenu.Item.RequestDesktop(checked))
}
[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 findInPage = BrowserMenuImageText(
label = context.getString(R.string.browser_menu_find_in_page),
imageResource = R.drawable.mozac_ic_search_24,
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
) {
onItemTapped.invoke(ToolbarMenu.Item.FindInPage)
}
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)
}
[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 openInFenix = SimpleBrowserMenuItem(
label = context.getString(R.string.browser_menu_open_in_fenix, appName),
textColorResource = 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
) {
onItemTapped.invoke(ToolbarMenu.Item.OpenInFenix)
}
private val poweredBy = BrowserMenuCategory(
label = context.getStringWithArgSafe(R.string.browser_menu_powered_by, appName)
.uppercase(Locale.getDefault()),
textSize = CAPTION_TEXT_SIZE,
textColorResource = primaryTextColor(),
textStyle = Typeface.NORMAL,
[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
)
@ColorRes
private fun primaryTextColor() = ThemeManager.resolveAttribute(R.attr.textPrimary, context)
companion object {
private const val CAPTION_TEXT_SIZE = 12f
}
}