1
0
Fork 0

For #3584 - Check if menu is open before showing a new one (#5674)

Could have implemented this check (if menu is showing) inside the show() method
of BrowserMenu but this would mean the client (us) would go to the process of
building a new menu and then trying to have it displayed only for this to be
ignored by BrowserMenu in a somewhat opaque way.
Having this check done as soon as possible offers us full control and avoids
the unnecessary steps for building an already shown menu.
master
Mugurell 2019-10-10 16:37:47 +03:00 committed by Sawyer Blatz
parent 17d183ea0b
commit 8f0325c05b
2 changed files with 26 additions and 8 deletions

View File

@ -245,11 +245,19 @@ class HomeFragment : Fragment() {
}
}
view.menuButton.setOnClickListener {
homeMenu?.menuBuilder?.build(requireContext())?.show(
anchor = it,
orientation = BrowserMenu.Orientation.DOWN
)
with(view.menuButton) {
var menu: PopupWindow? = null
setOnClickListener {
if (menu == null) {
menu = homeMenu?.menuBuilder?.build(requireContext())?.show(
anchor = it,
orientation = BrowserMenu.Orientation.DOWN,
onDismiss = { menu = null }
)
} else {
menu?.dismiss()
}
}
}
view.toolbar.compoundDrawablePadding =
view.resources.getDimensionPixelSize(R.dimen.search_bar_search_engine_icon_padding)

View File

@ -6,6 +6,7 @@ package org.mozilla.fenix.home.sessioncontrol.viewholders
import android.content.Context
import android.view.View
import android.widget.PopupWindow
import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView
import io.reactivex.Observer
@ -55,10 +56,19 @@ class TabHeaderViewHolder(
}
tabs_overflow_button.run {
var menu: PopupWindow? = null
setOnClickListener {
tabsMenu.menuBuilder
.build(view.context)
.show(anchor = it, orientation = BrowserMenu.Orientation.DOWN)
if (menu == null) {
menu = tabsMenu.menuBuilder
.build(view.context)
.show(
anchor = it,
orientation = BrowserMenu.Orientation.DOWN,
onDismiss = { menu = null }
)
} else {
menu?.dismiss()
}
}
}
}