For #8800 - dismiss all highlights when menu is closed

fennec/beta
Mihai Branescu 4 years ago
parent 1381444a52
commit 485efacd33

@ -27,4 +27,8 @@ open class BrowserInteractor(
override fun onBrowserToolbarMenuItemTapped(item: ToolbarMenu.Item) { override fun onBrowserToolbarMenuItemTapped(item: ToolbarMenu.Item) {
browserToolbarController.handleToolbarItemInteraction(item) browserToolbarController.handleToolbarItemInteraction(item)
} }
override fun onBrowserMenuDismissed(lowPrioHighlightItems: List<ToolbarMenu.Item>) {
browserToolbarController.handleBrowserMenuDismissed(lowPrioHighlightItems)
}
} }

@ -49,6 +49,7 @@ interface BrowserToolbarController {
fun handleToolbarItemInteraction(item: ToolbarMenu.Item) fun handleToolbarItemInteraction(item: ToolbarMenu.Item)
fun handleToolbarClick() fun handleToolbarClick()
fun handleTabCounterClick() fun handleTabCounterClick()
fun handleBrowserMenuDismissed(lowPrioHighlightItems: List<ToolbarMenu.Item>)
} }
@Suppress("LargeClass") @Suppress("LargeClass")
@ -121,6 +122,17 @@ class DefaultBrowserToolbarController(
animateTabAndNavigateHome() animateTabAndNavigateHome()
} }
override fun handleBrowserMenuDismissed(lowPrioHighlightItems: List<ToolbarMenu.Item>) {
lowPrioHighlightItems.forEach {
when (it) {
ToolbarMenu.Item.AddToHomeScreen -> activity.settings().installPwaOpened = true
is ToolbarMenu.Item.ReaderMode -> activity.settings().readerModeOpened = true
ToolbarMenu.Item.OpenInApp -> activity.settings().openInAppOpened = true
else -> {}
}
}
}
@ExperimentalCoroutinesApi @ExperimentalCoroutinesApi
@SuppressWarnings("ComplexMethod", "LongMethod") @SuppressWarnings("ComplexMethod", "LongMethod")
override fun handleToolbarItemInteraction(item: ToolbarMenu.Item) { override fun handleToolbarItemInteraction(item: ToolbarMenu.Item) {

@ -16,8 +16,10 @@ import androidx.core.view.isVisible
import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.LifecycleOwner
import com.google.android.material.snackbar.Snackbar import com.google.android.material.snackbar.Snackbar
import kotlinx.android.extensions.LayoutContainer import kotlinx.android.extensions.LayoutContainer
import kotlinx.android.synthetic.main.browser_toolbar_popup_window.view.* import kotlinx.android.synthetic.main.browser_toolbar_popup_window.view.copy
import kotlinx.android.synthetic.main.component_browser_top_toolbar.view.* import kotlinx.android.synthetic.main.browser_toolbar_popup_window.view.paste
import kotlinx.android.synthetic.main.browser_toolbar_popup_window.view.paste_and_go
import kotlinx.android.synthetic.main.component_browser_top_toolbar.view.app_bar
import mozilla.components.browser.domains.autocomplete.ShippedDomainsProvider import mozilla.components.browser.domains.autocomplete.ShippedDomainsProvider
import mozilla.components.browser.session.Session import mozilla.components.browser.session.Session
import mozilla.components.browser.toolbar.BrowserToolbar import mozilla.components.browser.toolbar.BrowserToolbar
@ -39,6 +41,7 @@ interface BrowserToolbarViewInteractor {
fun onBrowserToolbarClicked() fun onBrowserToolbarClicked()
fun onBrowserToolbarMenuItemTapped(item: ToolbarMenu.Item) fun onBrowserToolbarMenuItemTapped(item: ToolbarMenu.Item)
fun onTabCounterClicked() fun onTabCounterClicked()
fun onBrowserMenuDismissed(lowPrioHighlightItems: List<ToolbarMenu.Item>)
} }
class BrowserToolbarView( class BrowserToolbarView(
@ -173,8 +176,9 @@ class BrowserToolbarView(
display.hint = context.getString(R.string.search_hint) display.hint = context.getString(R.string.search_hint)
} }
val menuToolbar = if (isCustomTabSession) { val menuToolbar: ToolbarMenu
CustomTabToolbarMenu( if (isCustomTabSession) {
menuToolbar = CustomTabToolbarMenu(
this, this,
sessionManager, sessionManager,
customTabSession?.id, customTabSession?.id,
@ -184,7 +188,7 @@ class BrowserToolbarView(
} }
) )
} else { } else {
DefaultToolbarMenu( menuToolbar = DefaultToolbarMenu(
context = this, context = this,
hasAccountProblem = components.backgroundServices.accountManager.accountNeedsReauth(), hasAccountProblem = components.backgroundServices.accountManager.accountNeedsReauth(),
shouldReverseItems = !shouldUseBottomToolbar, shouldReverseItems = !shouldUseBottomToolbar,
@ -193,6 +197,10 @@ class BrowserToolbarView(
sessionManager = sessionManager, sessionManager = sessionManager,
bookmarksStorage = bookmarkStorage bookmarksStorage = bookmarkStorage
) )
view.display.setMenuDismissAction {
interactor.onBrowserMenuDismissed(menuToolbar.getLowPrioHighlightItems())
view.invalidateActions()
}
} }
toolbarIntegration = if (customTabSession != null) { toolbarIntegration = if (customTabSession != null) {

@ -132,6 +132,34 @@ class DefaultToolbarMenu(
BrowserMenuItemToolbar(listOf(bookmark, share, forward, refresh)) BrowserMenuItemToolbar(listOf(bookmark, share, forward, refresh))
} }
internal fun getLowPrioHighlightItems(): List<ToolbarMenu.Item> {
val lowPrioHighlightItems: MutableList<ToolbarMenu.Item> = mutableListOf()
if (shouldShowAddToHomescreen() && addToHomescreen.isHighlighted()) {
lowPrioHighlightItems.add(ToolbarMenu.Item.AddToHomeScreen)
}
if (shouldShowReaderMode() && readerMode.isHighlighted()) {
lowPrioHighlightItems.add(ToolbarMenu.Item.ReaderMode(false))
}
if (shouldShowOpenInApp() && openInApp.isHighlighted()) {
lowPrioHighlightItems.add(ToolbarMenu.Item.OpenInApp)
}
return lowPrioHighlightItems
}
// Predicates that need to be repeatedly called as the session changes
private fun shouldShowAddToHomescreen(): Boolean =
session != null && context.components.useCases.webAppUseCases.isPinningSupported()
private fun shouldShowReaderMode(): Boolean = session?.readerable ?: false
private fun shouldShowOpenInApp(): Boolean = session?.let { session ->
val appLink = context.components.useCases.appLinksUseCases.appLinkRedirect
appLink(session.url).hasExternalApp()
} ?: false
private fun shouldShowReaderAppearance(): Boolean = session?.readerMode ?: false
// End of predicates //
private val menuItems by lazy { private val menuItems by lazy {
// Predicates that are called once, during screen init // Predicates that are called once, during screen init
val shouldShowSaveToCollection = (context.asActivity() as? HomeActivity) val shouldShowSaveToCollection = (context.asActivity() as? HomeActivity)
@ -143,16 +171,6 @@ class DefaultToolbarMenu(
ReleaseChannel.FennecProduction ReleaseChannel.FennecProduction
) )
// Predicates that need to be repeatedly called as the session changes
fun shouldShowAddToHomescreen(): Boolean =
session != null && context.components.useCases.webAppUseCases.isPinningSupported()
fun shouldShowReaderMode(): Boolean = session?.readerable ?: false
fun shouldShowOpenInApp(): Boolean = session?.let { session ->
val appLink = context.components.useCases.appLinksUseCases.appLinkRedirect
appLink(session.url).hasExternalApp()
} ?: false
fun shouldShowReaderAppearance(): Boolean = session?.readerMode ?: false
val menuItems = listOfNotNull( val menuItems = listOfNotNull(
library, library,
addons, addons,

Loading…
Cancel
Save