Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Merge #7679
Browse files Browse the repository at this point in the history
7679: Closes #7644: Add long click listener to BrowserMenuItemToolbar items. r=psymoon a=person808




Co-authored-by: Kainalu Hagiwara <[email protected]>
  • Loading branch information
MozLando and person808 committed Jul 13, 2020
2 parents f074469 + c376696 commit cdef87e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ class BrowserMenuItemToolbar(
item.listener()
menu.dismiss()
}
button.setOnLongClickListener {
item.longClickListener()
menu.dismiss()
true
}

layout.addView(button, LinearLayout.LayoutParams(0, MATCH_PARENT, 1f))
}
Expand All @@ -77,13 +82,16 @@ class BrowserMenuItemToolbar(
* @param contentDescription The button's content description, used for accessibility support.
* @param iconTintColorResource Optional ID of color resource to tint the icon.
* @param isEnabled Lambda to return true/false to indicate if this button should be enabled or disabled.
* @param longClickListener Callback to be invoked when the button is long clicked.
* @param listener Callback to be invoked when the button is pressed.
*/
@Suppress("LongParameterList")
open class Button(
@DrawableRes val imageResource: Int,
val contentDescription: String,
@ColorRes val iconTintColorResource: Int = NO_ID,
val isEnabled: () -> Boolean = { true },
val longClickListener: () -> Unit = {},
val listener: () -> Unit
) {

Expand Down Expand Up @@ -131,8 +139,10 @@ class BrowserMenuItemToolbar(
* @param secondaryImageTintResource Optional ID of secondary color resource to tint the icon.
* @param isInPrimaryState Lambda to return true/false to indicate if this button should be primary or secondary.
* @param disableInSecondaryState Optional boolean to disable the button when in secondary state.
* @param longClickListener Callback to be invoked when the button is long clicked.
* @param listener Callback to be invoked when the button is pressed.
*/
@Suppress("LongParameterList")
open class TwoStateButton(
@DrawableRes val primaryImageResource: Int,
val primaryContentDescription: String,
Expand All @@ -142,12 +152,14 @@ class BrowserMenuItemToolbar(
@ColorRes val secondaryImageTintResource: Int = primaryImageTintResource,
val isInPrimaryState: () -> Boolean = { true },
val disableInSecondaryState: Boolean = false,
longClickListener: () -> Unit = {},
listener: () -> Unit
) : Button(
primaryImageResource,
primaryContentDescription,
primaryImageTintResource,
isInPrimaryState,
longClickListener = longClickListener,
listener = listener
) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,39 @@ class BrowserMenuItemToolbarTest {
verify(menu).dismiss()
}

@Test
fun `long clicking item view invokes callback and dismisses menu`() {
var callbackInvoked = false

val button = BrowserMenuItemToolbar.Button(
R.drawable.abc_ic_ab_back_material,
"Test",
longClickListener = {
callbackInvoked = true
}
) {}

assertFalse(callbackInvoked)

val menu = mock(BrowserMenu::class.java)
val layout = LinearLayout(testContext)

val toolbar = BrowserMenuItemToolbar(listOf(button))
toolbar.bind(menu, layout)

assertEquals(1, layout.childCount)

val view = layout.getChildAt(0)

assertFalse(callbackInvoked)
verify(menu, never()).dismiss()

view.performLongClick()

assertTrue(callbackInvoked)
verify(menu).dismiss()
}

@Test
fun `toolbar can be converted to candidate`() {
val listener = {}
Expand Down
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ permalink: /changelog/

* **browser-state**
* Added map of `SessionState.contextId` and their respective `ContainerState` in `BrowserState` to track the state of a container.

* **browser-menu**
* Added an optional `longClickListener` parameter to `BrowserMenuItemToolbar.Button` and `BrowserMenuItemToolbar.TwoStateButton` to handle long click events.

# 49.0.0

Expand Down

0 comments on commit cdef87e

Please sign in to comment.