mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-03 23:15:31 +00:00
Bug 1833757 - Merge onTabMultiSelectClick
and onTabClick
lambdas
This commit is contained in:
parent
7b6650a151
commit
99bd7f92b1
@ -60,7 +60,6 @@ import mozilla.components.browser.storage.sync.Tab as SyncTab
|
||||
* @param onTabClose Invoked when the user clicks to close a tab.
|
||||
* @param onTabMediaClick Invoked when the user interacts with a tab's media controls.
|
||||
* @param onTabClick Invoked when the user clicks on a tab.
|
||||
* @param onTabMultiSelectClick Invoked when the user clicks on a tab while in multi-select mode.
|
||||
* @param onTabLongClick Invoked when the user long clicks a tab.
|
||||
* @param onInactiveTabsHeaderClick Invoked when the user clicks on the inactive tabs section header.
|
||||
* @param onDeleteAllInactiveTabsClick Invoked when the user clicks on the delete all inactive tabs button.
|
||||
@ -99,7 +98,6 @@ fun TabsTray(
|
||||
onTabClose: (TabSessionState) -> Unit,
|
||||
onTabMediaClick: (TabSessionState) -> Unit,
|
||||
onTabClick: (TabSessionState) -> Unit,
|
||||
onTabMultiSelectClick: (TabSessionState) -> Unit,
|
||||
onTabLongClick: (TabSessionState) -> Unit,
|
||||
onInactiveTabsHeaderClick: (Boolean) -> Unit,
|
||||
onDeleteAllInactiveTabsClick: () -> Unit,
|
||||
@ -127,14 +125,6 @@ fun TabsTray(
|
||||
val pagerState = rememberPagerState(initialPage = selectedPage.ordinal)
|
||||
val isInMultiSelectMode = multiselectMode is TabsTrayState.Mode.Select
|
||||
|
||||
val handleTabClick: ((TabSessionState) -> Unit) = { tab ->
|
||||
if (isInMultiSelectMode) {
|
||||
onTabMultiSelectClick(tab)
|
||||
} else {
|
||||
onTabClick(tab)
|
||||
}
|
||||
}
|
||||
|
||||
val shapeModifier = if (isInMultiSelectMode) {
|
||||
Modifier
|
||||
} else {
|
||||
@ -188,7 +178,7 @@ fun TabsTray(
|
||||
displayTabsInGrid = displayTabsInGrid,
|
||||
onTabClose = onTabClose,
|
||||
onTabMediaClick = onTabMediaClick,
|
||||
onTabClick = handleTabClick,
|
||||
onTabClick = onTabClick,
|
||||
onTabLongClick = onTabLongClick,
|
||||
shouldShowInactiveTabsAutoCloseDialog = shouldShowInactiveTabsAutoCloseDialog,
|
||||
onInactiveTabsHeaderClick = onInactiveTabsHeaderClick,
|
||||
@ -208,7 +198,7 @@ fun TabsTray(
|
||||
displayTabsInGrid = displayTabsInGrid,
|
||||
onTabClose = onTabClose,
|
||||
onTabMediaClick = onTabMediaClick,
|
||||
onTabClick = handleTabClick,
|
||||
onTabClick = onTabClick,
|
||||
onTabLongClick = onTabLongClick,
|
||||
)
|
||||
}
|
||||
@ -504,12 +494,16 @@ private fun TabsTrayPreviewRoot(
|
||||
}
|
||||
},
|
||||
onTabMediaClick = {},
|
||||
onTabClick = {},
|
||||
onTabMultiSelectClick = { tab ->
|
||||
if (tabsTrayStore.state.mode.selectedTabs.contains(tab)) {
|
||||
tabsTrayStore.dispatch(TabsTrayAction.RemoveSelectTab(tab))
|
||||
} else {
|
||||
tabsTrayStore.dispatch(TabsTrayAction.AddSelectTab(tab))
|
||||
onTabClick = { tab ->
|
||||
when (tabsTrayStore.state.mode) {
|
||||
TabsTrayState.Mode.Normal -> {}
|
||||
is TabsTrayState.Mode.Select -> {
|
||||
if (tabsTrayStore.state.mode.selectedTabs.contains(tab)) {
|
||||
tabsTrayStore.dispatch(TabsTrayAction.RemoveSelectTab(tab))
|
||||
} else {
|
||||
tabsTrayStore.dispatch(TabsTrayAction.AddSelectTab(tab))
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
onTabLongClick = { tab ->
|
||||
|
@ -137,17 +137,6 @@ interface TabsTrayController : SyncedTabsController, InactiveTabsController, Tab
|
||||
*/
|
||||
fun handleMediaClicked(tab: SessionState)
|
||||
|
||||
/**
|
||||
* Handles a user's tab click while in multi select mode.
|
||||
*
|
||||
* @param tab [TabSessionState] that was clicked.
|
||||
* @param source App feature from which the tab was clicked.
|
||||
*/
|
||||
fun handleMultiSelectClicked(
|
||||
tab: TabSessionState,
|
||||
source: String?,
|
||||
)
|
||||
|
||||
/**
|
||||
* Adds the provided tab to the current selection of tabs.
|
||||
*
|
||||
@ -527,17 +516,6 @@ class DefaultTabsTrayController(
|
||||
)
|
||||
}
|
||||
|
||||
override fun handleMultiSelectClicked(tab: TabSessionState, source: String?) {
|
||||
val selected = tabsTrayStore.state.mode.selectedTabs
|
||||
when {
|
||||
selected.isEmpty() && tabsTrayStore.state.mode.isSelect().not() -> {
|
||||
handleTabSelected(tab, source)
|
||||
}
|
||||
tab.id in selected.map { it.id } -> handleTabUnselected(tab)
|
||||
else -> tabsTrayStore.dispatch(TabsTrayAction.AddSelectTab(tab))
|
||||
}
|
||||
}
|
||||
|
||||
override fun handleTabLongClick(tab: TabSessionState): Boolean {
|
||||
return if (tab.isNormalTab() && tabsTrayStore.state.mode.selectedTabs.isEmpty()) {
|
||||
Collections.longPress.record(NoExtras())
|
||||
@ -549,10 +527,17 @@ class DefaultTabsTrayController(
|
||||
}
|
||||
|
||||
override fun handleTabSelected(tab: TabSessionState, source: String?) {
|
||||
TabsTray.openedExistingTab.record(TabsTray.OpenedExistingTabExtra(source ?: "unknown"))
|
||||
tabsUseCases.selectTab(tab.id)
|
||||
browsingModeManager.mode = BrowsingMode.fromBoolean(tab.content.private)
|
||||
handleNavigateToBrowser()
|
||||
val selected = tabsTrayStore.state.mode.selectedTabs
|
||||
when {
|
||||
selected.isEmpty() && tabsTrayStore.state.mode.isSelect().not() -> {
|
||||
TabsTray.openedExistingTab.record(TabsTray.OpenedExistingTabExtra(source ?: "unknown"))
|
||||
tabsUseCases.selectTab(tab.id)
|
||||
browsingModeManager.mode = BrowsingMode.fromBoolean(tab.content.private)
|
||||
handleNavigateToBrowser()
|
||||
}
|
||||
tab.id in selected.map { it.id } -> handleTabUnselected(tab)
|
||||
else -> tabsTrayStore.dispatch(TabsTrayAction.AddSelectTab(tab))
|
||||
}
|
||||
}
|
||||
|
||||
override fun handleTabUnselected(tab: TabSessionState) {
|
||||
|
@ -246,9 +246,6 @@ class TabsTrayFragment : AppCompatDialogFragment() {
|
||||
onTabClick = { tab ->
|
||||
tabsTrayInteractor.onTabSelected(tab, TABS_TRAY_FEATURE_NAME)
|
||||
},
|
||||
onTabMultiSelectClick = { tab ->
|
||||
tabsTrayInteractor.onMultiSelectClicked(tab, TABS_TRAY_FEATURE_NAME)
|
||||
},
|
||||
onTabLongClick = tabsTrayInteractor::onTabLongClicked,
|
||||
onInactiveTabsHeaderClick = tabsTrayInteractor::onInactiveTabsHeaderClicked,
|
||||
onDeleteAllInactiveTabsClick = tabsTrayInteractor::onDeleteAllInactiveTabsClicked,
|
||||
|
@ -84,17 +84,6 @@ interface TabsTrayInteractor :
|
||||
*/
|
||||
fun onMediaClicked(tab: TabSessionState)
|
||||
|
||||
/**
|
||||
* Invoked when tabs are clicked when multi-selection is enabled.
|
||||
*
|
||||
* @param tab [TabSessionState] that was clicked.
|
||||
* @param source App feature from which the tab was clicked.
|
||||
*/
|
||||
fun onMultiSelectClicked(
|
||||
tab: TabSessionState,
|
||||
source: String?,
|
||||
)
|
||||
|
||||
/**
|
||||
* Invoked when a tab is long clicked.
|
||||
*
|
||||
@ -197,10 +186,6 @@ class DefaultTabsTrayInteractor(
|
||||
controller.handleMediaClicked(tab)
|
||||
}
|
||||
|
||||
override fun onMultiSelectClicked(tab: TabSessionState, source: String?) {
|
||||
controller.handleMultiSelectClicked(tab, source)
|
||||
}
|
||||
|
||||
override fun onTabLongClicked(tab: TabSessionState): Boolean {
|
||||
return controller.handleTabLongClick(tab)
|
||||
}
|
||||
|
@ -211,7 +211,7 @@ abstract class AbstractBrowserTabViewHolder(
|
||||
interactor: TabsTrayInteractor,
|
||||
) {
|
||||
itemView.setOnClickListener {
|
||||
interactor.onMultiSelectClicked(item, featureName)
|
||||
interactor.onTabSelected(item, featureName)
|
||||
}
|
||||
|
||||
itemView.setOnLongClickListener {
|
||||
|
@ -65,11 +65,7 @@ class ComposeGridViewHolder(
|
||||
}
|
||||
|
||||
private fun onClick(tab: TabSessionState) {
|
||||
if (store.state.mode is TabsTrayState.Mode.Select) {
|
||||
interactor.onMultiSelectClicked(tab, featureName)
|
||||
} else {
|
||||
interactor.onTabSelected(tab, featureName)
|
||||
}
|
||||
interactor.onTabSelected(tab, featureName)
|
||||
}
|
||||
|
||||
private fun onLongClick(tab: TabSessionState) {
|
||||
|
@ -68,11 +68,7 @@ class ComposeListViewHolder(
|
||||
}
|
||||
|
||||
private fun onClick(tab: TabSessionState) {
|
||||
if (tabsTrayStore.state.mode is TabsTrayState.Mode.Select) {
|
||||
interactor.onMultiSelectClicked(tab, featureName)
|
||||
} else {
|
||||
interactor.onTabSelected(tab, featureName)
|
||||
}
|
||||
interactor.onTabSelected(tab, featureName)
|
||||
}
|
||||
|
||||
private fun onLongClick(tab: TabSessionState) {
|
||||
|
@ -585,10 +585,10 @@ class DefaultTabsTrayControllerTest {
|
||||
trayStore.dispatch(TabsTrayAction.ExitSelectMode)
|
||||
trayStore.waitUntilIdle()
|
||||
|
||||
controller.handleMultiSelectClicked(tab1, "Tabs tray")
|
||||
controller.handleTabSelected(tab1, "Tabs tray")
|
||||
verify(exactly = 1) { controller.handleTabSelected(tab1, "Tabs tray") }
|
||||
|
||||
controller.handleMultiSelectClicked(tab2, "Tabs tray")
|
||||
controller.handleTabSelected(tab2, "Tabs tray")
|
||||
verify(exactly = 1) { controller.handleTabSelected(tab2, "Tabs tray") }
|
||||
}
|
||||
|
||||
@ -613,10 +613,10 @@ class DefaultTabsTrayControllerTest {
|
||||
trayStore.dispatch(TabsTrayAction.AddSelectTab(tab2))
|
||||
trayStore.waitUntilIdle()
|
||||
|
||||
controller.handleMultiSelectClicked(tab1, "Tabs tray")
|
||||
controller.handleTabSelected(tab1, "Tabs tray")
|
||||
verify(exactly = 1) { controller.handleTabUnselected(tab1) }
|
||||
|
||||
controller.handleMultiSelectClicked(tab2, "Tabs tray")
|
||||
controller.handleTabSelected(tab2, "Tabs tray")
|
||||
verify(exactly = 1) { controller.handleTabUnselected(tab2) }
|
||||
}
|
||||
|
||||
@ -644,7 +644,7 @@ class DefaultTabsTrayControllerTest {
|
||||
trayStore.dispatch(TabsTrayAction.AddSelectTab(tab1))
|
||||
trayStore.waitUntilIdle()
|
||||
|
||||
controller.handleMultiSelectClicked(tab2, "Tabs tray")
|
||||
controller.handleTabSelected(tab2, "Tabs tray")
|
||||
|
||||
middleware.assertLastAction(TabsTrayAction.AddSelectTab::class) {
|
||||
assertEquals(tab2, it.tab)
|
||||
@ -903,6 +903,7 @@ class DefaultTabsTrayControllerTest {
|
||||
content = ContentState(url = "https://mozilla.com", private = true),
|
||||
id = "privateTab",
|
||||
)
|
||||
trayStore = TabsTrayStore()
|
||||
browserStore = BrowserStore(
|
||||
initialState = BrowserState(
|
||||
tabs = listOf(normalTab, privateTab),
|
||||
@ -942,6 +943,7 @@ class DefaultTabsTrayControllerTest {
|
||||
val privateTab = TabSessionState(content = ContentState(url = "https://mozilla.com", private = true), id = "privateTab")
|
||||
var showUndoSnackbarForTabInvoked = false
|
||||
var navigateToHomeAndDeleteSessionInvoked = false
|
||||
trayStore = TabsTrayStore()
|
||||
browserStore = BrowserStore(
|
||||
initialState = BrowserState(
|
||||
tabs = listOf(currentTab, privateTab),
|
||||
|
@ -82,7 +82,7 @@ class AbstractBrowserTabViewHolderTest {
|
||||
|
||||
holder.itemView.performClick()
|
||||
|
||||
verify { interactor.onMultiSelectClicked(tab, holder.featureName) }
|
||||
verify { interactor.onTabSelected(tab, holder.featureName) }
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user