Commit 485efacd authored by Mihai Branescu's avatar Mihai Branescu
Browse files

For #8800 - dismiss all highlights when menu is closed

parent 1381444a
......@@ -27,4 +27,8 @@ open class BrowserInteractor(
override fun onBrowserToolbarMenuItemTapped(item: ToolbarMenu.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 handleToolbarClick()
fun handleTabCounterClick()
fun handleBrowserMenuDismissed(lowPrioHighlightItems: List<ToolbarMenu.Item>)
}
@Suppress("LargeClass")
......@@ -121,6 +122,17 @@ class DefaultBrowserToolbarController(
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
@SuppressWarnings("ComplexMethod", "LongMethod")
override fun handleToolbarItemInteraction(item: ToolbarMenu.Item) {
......
......@@ -16,8 +16,10 @@ import androidx.core.view.isVisible
import androidx.lifecycle.LifecycleOwner
import com.google.android.material.snackbar.Snackbar
import kotlinx.android.extensions.LayoutContainer
import kotlinx.android.synthetic.main.browser_toolbar_popup_window.view.*
import kotlinx.android.synthetic.main.component_browser_top_toolbar.view.*
import kotlinx.android.synthetic.main.browser_toolbar_popup_window.view.copy
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.session.Session
import mozilla.components.browser.toolbar.BrowserToolbar
......@@ -39,6 +41,7 @@ interface BrowserToolbarViewInteractor {
fun onBrowserToolbarClicked()
fun onBrowserToolbarMenuItemTapped(item: ToolbarMenu.Item)
fun onTabCounterClicked()
fun onBrowserMenuDismissed(lowPrioHighlightItems: List<ToolbarMenu.Item>)
}
class BrowserToolbarView(
......@@ -173,8 +176,9 @@ class BrowserToolbarView(
display.hint = context.getString(R.string.search_hint)
}
val menuToolbar = if (isCustomTabSession) {
CustomTabToolbarMenu(
val menuToolbar: ToolbarMenu
if (isCustomTabSession) {
menuToolbar = CustomTabToolbarMenu(
this,
sessionManager,
customTabSession?.id,
......@@ -184,7 +188,7 @@ class BrowserToolbarView(
}
)
} else {
DefaultToolbarMenu(
menuToolbar = DefaultToolbarMenu(
context = this,
hasAccountProblem = components.backgroundServices.accountManager.accountNeedsReauth(),
shouldReverseItems = !shouldUseBottomToolbar,
......@@ -193,6 +197,10 @@ class BrowserToolbarView(
sessionManager = sessionManager,
bookmarksStorage = bookmarkStorage
)
view.display.setMenuDismissAction {
interactor.onBrowserMenuDismissed(menuToolbar.getLowPrioHighlightItems())
view.invalidateActions()
}
}
toolbarIntegration = if (customTabSession != null) {
......
......@@ -132,6 +132,34 @@ class DefaultToolbarMenu(
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 {
// Predicates that are called once, during screen init
val shouldShowSaveToCollection = (context.asActivity() as? HomeActivity)
......@@ -143,16 +171,6 @@ class DefaultToolbarMenu(
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(
library,
addons,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment