[fenix] For https://github.com/mozilla-mobile/fenix/issues/26790 - Dismiss search dialog when opening recent bookmark dropdown menu

pull/600/head
Alexandru2909 2 years ago committed by mergify[bot]
parent 49d9032df2
commit 632a03ff12

@ -40,6 +40,11 @@ interface RecentBookmarksController {
* @see [RecentBookmarksInteractor.onRecentBookmarkRemoved]
*/
fun handleBookmarkRemoved(bookmark: RecentBookmark)
/**
* @see [RecentBookmarksInteractor.onRecentBookmarkLongClicked]
*/
fun handleBookmarkLongClicked()
}
/**
@ -74,6 +79,10 @@ class DefaultRecentBookmarksController(
appStore.dispatch(AppAction.RemoveRecentBookmark(bookmark))
}
override fun handleBookmarkLongClicked() {
dismissSearchDialogIfDisplayed()
}
@VisibleForTesting(otherwise = PRIVATE)
fun dismissSearchDialogIfDisplayed() {
if (navController.currentDestination?.id == R.id.searchDialogFragment) {

@ -33,4 +33,9 @@ interface RecentBookmarksInteractor {
* @param bookmark The bookmark that has been removed.
*/
fun onRecentBookmarkRemoved(bookmark: RecentBookmark)
/**
* Called when the user long clicks a recent bookmark.
*/
fun onRecentBookmarkLongClicked()
}

@ -65,12 +65,14 @@ private val imageModifier = Modifier
* @param bookmarks List of [RecentBookmark]s to display.
* @param menuItems List of [RecentBookmarksMenuItem] shown when long clicking a [RecentBookmarkItem]
* @param onRecentBookmarkClick Invoked when the user clicks on a recent bookmark.
* @param onRecentBookmarkLongClick Invoked when the user long clicks on a recent bookmark.
*/
@Composable
fun RecentBookmarks(
bookmarks: List<RecentBookmark>,
menuItems: List<RecentBookmarksMenuItem>,
onRecentBookmarkClick: (RecentBookmark) -> Unit = {},
onRecentBookmarkLongClick: () -> Unit = {},
) {
LazyRow(
contentPadding = PaddingValues(horizontal = 16.dp),
@ -81,6 +83,7 @@ fun RecentBookmarks(
bookmark = bookmark,
menuItems = menuItems,
onRecentBookmarkClick = onRecentBookmarkClick,
onRecentBookmarkLongClick = onRecentBookmarkLongClick,
)
}
}
@ -91,6 +94,7 @@ fun RecentBookmarks(
*
* @param bookmark The [RecentBookmark] to display.
* @param onRecentBookmarkClick Invoked when the user clicks on the recent bookmark item.
* @param onRecentBookmarkLongClick Invoked when the user long clicks on the recent bookmark item.
*/
@OptIn(ExperimentalFoundationApi::class)
@Composable
@ -98,6 +102,7 @@ private fun RecentBookmarkItem(
bookmark: RecentBookmark,
menuItems: List<RecentBookmarksMenuItem>,
onRecentBookmarkClick: (RecentBookmark) -> Unit = {},
onRecentBookmarkLongClick: () -> Unit = {},
) {
var isMenuExpanded by remember { mutableStateOf(false) }
@ -107,7 +112,10 @@ private fun RecentBookmarkItem(
.combinedClickable(
enabled = true,
onClick = { onRecentBookmarkClick(bookmark) },
onLongClick = { isMenuExpanded = true },
onLongClick = {
onRecentBookmarkLongClick()
isMenuExpanded = true
},
),
shape = cardShape,
backgroundColor = FirefoxTheme.colors.layer2,

@ -45,6 +45,7 @@ class RecentBookmarksViewHolder(
onClick = { bookmark -> interactor.onRecentBookmarkRemoved(bookmark) },
),
),
onRecentBookmarkLongClick = interactor::onRecentBookmarkLongClicked,
)
}
}

@ -412,6 +412,10 @@ class SessionControlInteractor(
recentBookmarksController.handleBookmarkRemoved(bookmark)
}
override fun onRecentBookmarkLongClicked() {
recentBookmarksController.handleBookmarkLongClicked()
}
override fun onHistoryShowAllClicked() {
recentVisitsController.handleHistoryShowAllClicked()
}

@ -197,6 +197,12 @@ class SessionControlInteractorTest {
verify { recentBookmarksController.handleBookmarkClicked(bookmark) }
}
@Test
fun `WHEN a recent bookmark is long clicked THEN the long click is handled`() {
interactor.onRecentBookmarkLongClicked()
verify { recentBookmarksController.handleBookmarkLongClicked() }
}
@Test
fun `WHEN tapping on the customize home button THEN openCustomizeHomePage`() {
interactor.openCustomizeHomePage()

@ -132,4 +132,18 @@ class DefaultRecentBookmarksControllerTest {
}
assertNotNull(RecentBookmarks.showAllBookmarks.testGetValue())
}
@Test
fun `GIVEN search dialog is displayed WHEN recent bookmark is long clicked THEN dismiss search dialog`() {
every { navController.currentDestination } returns mockk {
every { id } returns R.id.searchDialogFragment
}
controller.handleBookmarkLongClicked()
verify {
controller.dismissSearchDialogIfDisplayed()
navController.navigateUp()
}
}
}

Loading…
Cancel
Save