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

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

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

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

@ -197,6 +197,12 @@ class SessionControlInteractorTest {
verify { recentBookmarksController.handleBookmarkClicked(bookmark) } 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 @Test
fun `WHEN tapping on the customize home button THEN openCustomizeHomePage`() { fun `WHEN tapping on the customize home button THEN openCustomizeHomePage`() {
interactor.openCustomizeHomePage() interactor.openCustomizeHomePage()

@ -132,4 +132,18 @@ class DefaultRecentBookmarksControllerTest {
} }
assertNotNull(RecentBookmarks.showAllBookmarks.testGetValue()) 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