2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-17 15:26:23 +00:00

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

This commit is contained in:
Alexandru2909 2022-09-06 10:34:51 +03:00 committed by mergify[bot]
parent 3d949c808f
commit 49d9032df2
7 changed files with 61 additions and 2 deletions

View File

@ -60,6 +60,11 @@ interface RecentVisitsController {
* @param highlightUrl Url of the [RecentHistoryHighlight] to remove.
*/
fun handleRemoveRecentHistoryHighlight(highlightUrl: String)
/**
* Callback for when the user long clicks on a recent visit.
*/
fun handleRecentVisitLongClicked()
}
/**
@ -140,6 +145,13 @@ class DefaultRecentVisitsController(
}
}
/**
* Dismiss the search dialog if displayed.
*/
override fun handleRecentVisitLongClicked() {
dismissSearchDialogIfDisplayed()
}
@VisibleForTesting(otherwise = PRIVATE)
fun dismissSearchDialogIfDisplayed() {
if (navController.currentDestination?.id == R.id.searchDialogFragment) {

View File

@ -44,4 +44,9 @@ interface RecentVisitsInteractor {
* @param highlightUrl [RecentHistoryHighlight.url] of the item to remove.
*/
fun onRemoveRecentHistoryHighlight(highlightUrl: String)
/**
* Called when opening the dropdown menu on a recent visit by long press.
*/
fun onRecentVisitLongClicked()
}

View File

@ -64,12 +64,14 @@ private const val VISITS_PER_COLUMN = 3
* @param recentVisits List of [RecentlyVisitedItem] to display.
* @param menuItems List of [RecentVisitMenuItem] shown long clicking a [RecentlyVisitedItem].
* @param onRecentVisitClick Invoked when the user clicks on a recent visit.
* @param onRecentVisitLongClick Invoked when the user long clicks on a recent visit.
*/
@Composable
fun RecentlyVisited(
recentVisits: List<RecentlyVisitedItem>,
menuItems: List<RecentVisitMenuItem>,
onRecentVisitClick: (RecentlyVisitedItem, Int) -> Unit = { _, _ -> },
onRecentVisitLongClick: () -> Unit = {},
) {
Card(
modifier = Modifier.fillMaxWidth(),
@ -102,6 +104,7 @@ fun RecentlyVisited(
onRecentVisitClick = {
onRecentVisitClick(it, pageIndex + 1)
},
onRecentVisitLongClick = { onRecentVisitLongClick() },
)
is RecentHistoryGroup -> RecentlyVisitedHistoryGroup(
recentVisit = recentVisit,
@ -111,6 +114,7 @@ fun RecentlyVisited(
onRecentVisitClick = {
onRecentVisitClick(it, pageIndex + 1)
},
onRecentVisitLongClick = { onRecentVisitLongClick() },
)
}
}
@ -128,8 +132,10 @@ fun RecentlyVisited(
* @param clickableEnabled Whether click actions should be invoked or not.
* @param showDividerLine Whether to show a divider line at the bottom.
* @param onRecentVisitClick Invoked when the user clicks on a recent visit.
* @param onRecentVisitClick Invoked when the user long clicks on a recently visited group.
*/
@OptIn(ExperimentalFoundationApi::class)
@Suppress("LongParameterList")
@Composable
private fun RecentlyVisitedHistoryGroup(
recentVisit: RecentHistoryGroup,
@ -137,6 +143,7 @@ private fun RecentlyVisitedHistoryGroup(
clickableEnabled: Boolean,
showDividerLine: Boolean,
onRecentVisitClick: (RecentHistoryGroup) -> Unit = { _ -> },
onRecentVisitLongClick: () -> Unit = {},
) {
var isMenuExpanded by remember { mutableStateOf(false) }
@ -145,7 +152,10 @@ private fun RecentlyVisitedHistoryGroup(
.combinedClickable(
enabled = clickableEnabled,
onClick = { onRecentVisitClick(recentVisit) },
onLongClick = { isMenuExpanded = true },
onLongClick = {
onRecentVisitLongClick()
isMenuExpanded = true
},
)
.size(268.dp, 56.dp),
verticalAlignment = Alignment.CenterVertically,
@ -195,8 +205,10 @@ private fun RecentlyVisitedHistoryGroup(
* @param clickableEnabled Whether click actions should be invoked or not.
* @param showDividerLine Whether to show a divider line at the bottom.
* @param onRecentVisitClick Invoked when the user clicks on a recent visit.
* @param onRecentVisitLongClick Invoked when the user long clicks on a recent visit highlight.
*/
@OptIn(ExperimentalFoundationApi::class)
@Suppress("LongParameterList")
@Composable
private fun RecentlyVisitedHistoryHighlight(
recentVisit: RecentHistoryHighlight,
@ -204,6 +216,7 @@ private fun RecentlyVisitedHistoryHighlight(
clickableEnabled: Boolean,
showDividerLine: Boolean,
onRecentVisitClick: (RecentHistoryHighlight) -> Unit = { _ -> },
onRecentVisitLongClick: () -> Unit = {},
) {
var isMenuExpanded by remember { mutableStateOf(false) }
@ -212,7 +225,10 @@ private fun RecentlyVisitedHistoryHighlight(
.combinedClickable(
enabled = clickableEnabled,
onClick = { onRecentVisitClick(recentVisit) },
onLongClick = { isMenuExpanded = true },
onLongClick = {
onRecentVisitLongClick()
isMenuExpanded = true
},
)
.size(268.dp, 56.dp),
verticalAlignment = Alignment.CenterVertically,

View File

@ -76,6 +76,7 @@ class RecentlyVisitedViewHolder(
}
}
},
onRecentVisitLongClick = { interactor.onRecentVisitLongClicked() },
)
}

View File

@ -434,6 +434,10 @@ class SessionControlInteractor(
recentVisitsController.handleRemoveRecentHistoryHighlight(highlightUrl)
}
override fun onRecentVisitLongClicked() {
recentVisitsController.handleRecentVisitLongClicked()
}
override fun openCustomizeHomePage() {
controller.handleCustomizeHomeTapped()
}

View File

@ -181,4 +181,18 @@ class RecentVisitsControllerTest {
}
}
}
@Test
fun `WHEN long clicking a recent visit THEN search dialog should be dismissed `() = runTestOnMain {
every { navController.currentDestination } returns mockk {
every { id } returns R.id.searchDialogFragment
}
controller.handleRecentVisitLongClicked()
verify {
controller.dismissSearchDialogIfDisplayed()
navController.navigateUp()
}
}
}

View File

@ -120,4 +120,11 @@ class RecentVisitsInteractorTest {
verify { recentVisitsController.handleRemoveRecentHistoryHighlight("url") }
}
@Test
fun onRecentVisitLongClicked() {
interactor.onRecentVisitLongClicked()
verify { recentVisitsController.handleRecentVisitLongClicked() }
}
}