@ -63,10 +63,11 @@ class DefaultToolbarMenu(
val isPinningSupported : Boolean
val isPinningSupported : Boolean
) : ToolbarMenu {
) : ToolbarMenu {
private var currentUrlIs Bookmarked = false
private var isCurrentUrl Bookmarked = false
private var isBookmarkedJob : Job ? = null
private var isBookmarkedJob : Job ? = null
private val isTopToolbarSelected = shouldReverseItems
private val selectedSession : TabSessionState ? get ( ) = store . state . selectedTab
private val selectedSession : TabSessionState ?
get ( ) = store . state . selectedTab
override val menuBuilder by lazy {
override val menuBuilder by lazy {
WebExtensionBrowserMenuBuilder (
WebExtensionBrowserMenuBuilder (
@ -146,24 +147,28 @@ class DefaultToolbarMenu(
registerForIsBookmarkedUpdates ( )
registerForIsBookmarkedUpdates ( )
val bookmark = BrowserMenuItemToolbar . TwoStateButton (
if ( FeatureFlags . toolbarMenuFeature ) {
primaryImageResource = R . drawable . ic _bookmark _filled ,
BrowserMenuItemToolbar ( listOf ( back , forward , share , refresh ) )
primaryContentDescription = context . getString ( R . string . browser _menu _edit _bookmark ) ,
} else {
primaryImageTintResource = primaryTextColor ( ) ,
val bookmark = BrowserMenuItemToolbar . TwoStateButton (
// TwoStateButton.isInPrimaryState must be synchronous, and checking bookmark state is
primaryImageResource = R . drawable . ic _bookmark _filled ,
// relatively slow. The best we can do here is periodically compute and cache a new "is
primaryContentDescription = context . getString ( R . string . browser _menu _edit _bookmark ) ,
// bookmarked" state, and use that whenever the menu has been opened.
primaryImageTintResource = primaryTextColor ( ) ,
isInPrimaryState = { currentUrlIsBookmarked } ,
// TwoStateButton.isInPrimaryState must be synchronous, and checking bookmark state is
secondaryImageResource = R . drawable . ic _bookmark _outline ,
// relatively slow. The best we can do here is periodically compute and cache a new "is
secondaryContentDescription = context . getString ( R . string . browser _menu _bookmark ) ,
// bookmarked" state, and use that whenever the menu has been opened.
secondaryImageTintResource = primaryTextColor ( ) ,
isInPrimaryState = { isCurrentUrlBookmarked } ,
disableInSecondaryState = false
secondaryImageResource = R . drawable . ic _bookmark _outline ,
) {
secondaryContentDescription = context . getString ( R . string . browser _menu _bookmark ) ,
if ( ! currentUrlIsBookmarked ) currentUrlIsBookmarked = true
secondaryImageTintResource = primaryTextColor ( ) ,
onItemTapped . invoke ( ToolbarMenu . Item . Bookmark )
disableInSecondaryState = false
}
) {
if ( !is CurrentUrlBookmarked ) isCurrentUrlBookmarked = true
onItemTapped . invoke ( ToolbarMenu . Item . Bookmark )
}
BrowserMenuItemToolbar ( listOf ( back , forward , bookmark , share , refresh ) )
BrowserMenuItemToolbar ( listOf ( back , forward , bookmark , share , refresh ) )
}
}
}
// Predicates that need to be repeatedly called as the session changes
// Predicates that need to be repeatedly called as the session changes
@ -469,26 +474,28 @@ class DefaultToolbarMenu(
onItemTapped . invoke ( ToolbarMenu . Item . Settings )
onItemTapped . invoke ( ToolbarMenu . Item . Settings )
}
}
val menuItems = listOfNotNull (
val menuItems =
newTabItem ,
listOfNotNull (
BrowserMenuDivider ( ) ,
if ( isTopToolbarSelected ) menuToolbar else null ,
bookmarksItem ,
newTabItem ,
historyItem ,
BrowserMenuDivider ( ) ,
downloadsItem ,
bookmarksItem ,
extensionsItem ,
historyItem ,
syncedTabsItem ,
downloadsItem ,
BrowserMenuDivider ( ) ,
extensionsItem ,
findInPageItem ,
syncedTabsItem ,
desktopSiteItem ,
BrowserMenuDivider ( ) ,
BrowserMenuDivider ( ) ,
findInPageItem ,
addToHomeScreenItem . apply { visible = :: canAddToHomescreen } ,
desktopSiteItem ,
addToTopSitesItem ,
BrowserMenuDivider ( ) ,
saveToCollectionItem ,
addToHomeScreenItem . apply { visible = :: canAddToHomescreen } ,
BrowserMenuDivider ( ) ,
addToTopSitesItem ,
settingsItem ,
saveToCollectionItem ,
BrowserMenuDivider ( ) ,
BrowserMenuDivider ( ) ,
menuToolbar
settingsItem ,
)
if ( isTopToolbarSelected ) null else BrowserMenuDivider ( ) ,
if ( isTopToolbarSelected ) null else menuToolbar
)
menuItems
menuItems
}
}
@ -512,7 +519,7 @@ class DefaultToolbarMenu(
)
)
}
}
. collect {
. collect {
currentUrlIs Bookmarked = false
isCurrentUrl Bookmarked = false
updateCurrentUrlIsBookmarked ( it . content . url )
updateCurrentUrlIsBookmarked ( it . content . url )
}
}
}
}
@ -522,7 +529,7 @@ class DefaultToolbarMenu(
internal fun updateCurrentUrlIsBookmarked ( newUrl : String ) {
internal fun updateCurrentUrlIsBookmarked ( newUrl : String ) {
isBookmarkedJob ?. cancel ( )
isBookmarkedJob ?. cancel ( )
isBookmarkedJob = lifecycleOwner . lifecycleScope . launch {
isBookmarkedJob = lifecycleOwner . lifecycleScope . launch {
currentUrlIs Bookmarked = bookmarksStorage
isCurrentUrl Bookmarked = bookmarksStorage
. getBookmarksWithUrl ( newUrl )
. getBookmarksWithUrl ( newUrl )
. any { it . url == newUrl }
. any { it . url == newUrl }
}
}