Skip to content

Commit

Permalink
For mozilla-mobile#26690 - Dismiss search dialog when opening recent …
Browse files Browse the repository at this point in the history
…synced tab dropdown menu
  • Loading branch information
Alexandru2909 committed Sep 2, 2022
1 parent df9c60b commit 58b1094
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ interface RecentSyncedTabController {
*/
fun handleRecentSyncedTabClick(tab: RecentSyncedTab)

/**
* @see [RecentSyncedTabInteractor.onRecentSyncedTabLongClick]
*/
fun handleRecentSyncedTabLongClick()

/**
* @see [RecentSyncedTabInteractor.onRecentSyncedTabClicked]
*/
Expand Down Expand Up @@ -66,6 +71,12 @@ class DefaultRecentSyncedTabController(
)
}

override fun handleRecentSyncedTabLongClick() {
if (navController.currentDestination?.id == R.id.searchDialogFragment) {
navController.navigateUp()
}
}

override fun handleRecentSyncedTabRemoved(tab: RecentSyncedTab) {
appStore.dispatch(AppAction.RemoveRecentSyncedTab(tab))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ interface RecentSyncedTabInteractor {
*/
fun onRecentSyncedTabClicked(tab: RecentSyncedTab)

/**
* Called when opening the dropdown menu on a recent tab by long press.
*/
fun onRecentSyncedTabLongClick()

/**
* Opens the tabs tray to the synced tab page. Called when a user clicks on the "See all synced
* tabs" button.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import org.mozilla.fenix.theme.Theme
* @param onRecentSyncedTabClick Invoked when the user clicks on the recent synced tab.
* @param onSeeAllSyncedTabsButtonClick Invoked when user clicks on the "See all" button in the synced tab card.
* @param onRemoveSyncedTab Invoked when user clicks on the "Remove" dropdown menu option.
* @param onRecentSyncedTabLongClick Invoked when user long presses the recent synced tab.
*/
@OptIn(ExperimentalFoundationApi::class)
@Suppress("LongMethod")
Expand All @@ -68,6 +69,7 @@ fun RecentSyncedTab(
onRecentSyncedTabClick: (RecentSyncedTab) -> Unit,
onSeeAllSyncedTabsButtonClick: () -> Unit,
onRemoveSyncedTab: (RecentSyncedTab) -> Unit,
onRecentSyncedTabLongClick: () -> Unit,
) {
var isDropdownExpanded by remember { mutableStateOf(false) }

Expand All @@ -82,7 +84,10 @@ fun RecentSyncedTab(
.height(180.dp)
.combinedClickable(
onClick = { tab?.let { onRecentSyncedTabClick(tab) } },
onLongClick = { isDropdownExpanded = true }
onLongClick = {
onRecentSyncedTabLongClick()
isDropdownExpanded = true
}
),
shape = RoundedCornerShape(8.dp),
backgroundColor = FirefoxTheme.colors.layer2,
Expand Down Expand Up @@ -285,6 +290,7 @@ private fun LoadedRecentSyncedTab() {
onRecentSyncedTabClick = {},
onSeeAllSyncedTabsButtonClick = {},
onRemoveSyncedTab = {},
onRecentSyncedTabLongClick = {},
)
}
}
Expand All @@ -298,6 +304,7 @@ private fun LoadingRecentSyncedTab() {
onRecentSyncedTabClick = {},
onSeeAllSyncedTabsButtonClick = {},
onRemoveSyncedTab = {},
onRecentSyncedTabLongClick = {},
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ class RecentSyncedTabViewHolder(
tab = syncedTab,
onRecentSyncedTabClick = recentSyncedTabInteractor::onRecentSyncedTabClicked,
onSeeAllSyncedTabsButtonClick = recentSyncedTabInteractor::onSyncedTabShowAllClicked,
onRemoveSyncedTab = recentSyncedTabInteractor::onRemovedRecentSyncedTab
onRemoveSyncedTab = recentSyncedTabInteractor::onRemovedRecentSyncedTab,
onRecentSyncedTabLongClick = recentSyncedTabInteractor::onRecentSyncedTabLongClick
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,10 @@ class SessionControlInteractor(
recentSyncedTabController.handleRecentSyncedTabClick(tab)
}

override fun onRecentSyncedTabLongClick() {
recentSyncedTabController.handleRecentSyncedTabLongClick()
}

override fun onSyncedTabShowAllClicked() {
recentSyncedTabController.handleSyncedTabShowAllClicked()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,20 @@ class DefaultRecentSyncedTabControllerTest {
}
}

@Test
fun `GIVEN search dialog is displayed WHEN recent synced tab is long clicked THEN dismiss search dialog`() {
every { navController.navigateUp() } returns true
every { navController.currentDestination } returns mockk {
every { id } returns R.id.searchDialogFragment
}

controller.handleRecentSyncedTabLongClick()

verify {
navController.navigateUp()
}
}

@Test
fun `WHEN synced tab clicked THEN metric counter labeled by device type is incremented`() {
val url = "https://mozilla.org"
Expand Down

0 comments on commit 58b1094

Please sign in to comment.