Bug 1816555 - Add functionality for collections button in composed multi selection banner

fenix/115.2.0
Alexandru2909 1 year ago committed by mergify[bot]
parent 7aa627bbcc
commit a9ee5277f2

@ -72,6 +72,8 @@ import mozilla.components.browser.storage.sync.Tab as SyncTab
* @param onInactiveTabClick Invoked when the user clicks on an inactive tab.
* @param onInactiveTabClose Invoked when the user clicks on an inactive tab's close button.
* @param onSyncedTabClick Invoked when the user clicks on a synced tab.
* @param onSaveToCollectionClick Invoked when the user clicks on the save to collection button from
* the multi select banner.
*/
@OptIn(ExperimentalPagerApi::class, ExperimentalComposeUiApi::class)
@Suppress("LongMethod", "LongParameterList", "ComplexMethod")
@ -97,6 +99,7 @@ fun TabsTray(
onInactiveTabClick: (TabSessionState) -> Unit,
onInactiveTabClose: (TabSessionState) -> Unit,
onSyncedTabClick: (SyncTab) -> Unit,
onSaveToCollectionClick: () -> Unit,
) {
val normalTabCount = browserStore
.observeAsComposableState { state -> state.normalTabs.size }.value ?: 0
@ -139,6 +142,7 @@ fun TabsTray(
isInDebugMode = isInDebugMode,
onTabPageIndicatorClicked = onTabPageClick,
onExitSelectModeClick = { tabsTrayStore.dispatch(TabsTrayAction.ExitSelectMode) },
onSaveToCollectionClick = onSaveToCollectionClick,
)
}
@ -491,6 +495,7 @@ private fun TabsTrayPreviewRoot(
onInactiveTabClick = {},
onInactiveTabClose = inactiveTabsState::remove,
onSyncedTabClick = {},
onSaveToCollectionClick = {},
)
}
}

@ -63,6 +63,8 @@ private val ICON_SIZE = 24.dp
* @param onTabPageIndicatorClicked Invoked when the user clicks on a tab page indicator.
* @param onExitSelectModeClick Invoked when the user clicks on exit select mode button from the
* multi select banner.
* @param onSaveToCollectionClick Invoked when the user clicks on the save to collection button from
* the multi select banner.
*/
@Suppress("LongParameterList")
@Composable
@ -73,12 +75,14 @@ fun TabsTrayBanner(
isInDebugMode: Boolean,
onTabPageIndicatorClicked: (Page) -> Unit,
onExitSelectModeClick: () -> Unit,
onSaveToCollectionClick: () -> Unit,
) {
if (selectMode is TabsTrayState.Mode.Select) {
MultiSelectBanner(
selectedTabCount = selectMode.selectedTabs.size,
shouldShowInactiveButton = isInDebugMode,
onExitSelectModeClick = onExitSelectModeClick,
onSaveToCollectionsClick = onSaveToCollectionClick,
)
} else {
SingleSelectBanner(
@ -222,6 +226,7 @@ private fun NormalTabsTabIcon(normalTabCount: Int) {
* @param selectedTabCount Number of selected tabs.
* @param shouldShowInactiveButton Whether or not to show the inactive tabs menu item.
* @param onExitSelectModeClick Invoked when the user clicks on exit select mode button.
* @param onSaveToCollectionsClick Invoked when the user clicks on the save to collection button.
*/
@Suppress("LongMethod")
@Composable
@ -229,6 +234,7 @@ private fun MultiSelectBanner(
selectedTabCount: Int,
shouldShowInactiveButton: Boolean,
onExitSelectModeClick: () -> Unit,
onSaveToCollectionsClick: () -> Unit,
) {
var showMenu by remember { mutableStateOf(false) }
val menuItems = mutableListOf(
@ -272,7 +278,7 @@ private fun MultiSelectBanner(
Spacer(modifier = Modifier.weight(1.0f))
IconButton(onClick = {}) {
IconButton(onClick = onSaveToCollectionsClick) {
Icon(
painter = painterResource(id = R.drawable.ic_tab_collection),
contentDescription = stringResource(
@ -369,6 +375,7 @@ private fun TabsTrayBannerPreviewRoot(
selectedPageState = page
},
onExitSelectModeClick = { selectModeState = TabsTrayState.Mode.Normal },
onSaveToCollectionClick = {},
)
}
}

@ -258,6 +258,7 @@ class TabsTrayFragment : AppCompatDialogFragment() {
onInactiveTabClick = tabsTrayInteractor::onInactiveTabClicked,
onInactiveTabClose = tabsTrayInteractor::onInactiveTabClosed,
onSyncedTabClick = tabsTrayInteractor::onSyncedTabClicked,
onSaveToCollectionClick = tabsTrayInteractor::onAddSelectedTabsToCollectionClicked,
)
}
}
@ -580,11 +581,7 @@ class TabsTrayFragment : AppCompatDialogFragment() {
},
operation = { },
elevation = ELEVATION,
anchorView = when {
requireContext().settings().enableTabsTrayToCompose -> fabButtonComposeBinding.root
fabButtonBinding.newTabButton.isVisible -> fabButtonBinding.newTabButton
else -> null
},
anchorView = getSnackbarAnchor(),
)
}
@ -716,12 +713,10 @@ class TabsTrayFragment : AppCompatDialogFragment() {
return parentFragmentManager.findFragmentByTag(DOWNLOAD_CANCEL_DIALOG_FRAGMENT_TAG) as? DownloadCancelDialogFragment
}
private fun getSnackbarAnchor(): View? {
return if (requireComponents.settings.accessibilityServicesEnabled) {
null
} else {
fabButtonBinding.newTabButton
}
private fun getSnackbarAnchor(): View? = when {
requireContext().settings().enableTabsTrayToCompose -> fabButtonComposeBinding.root
fabButtonBinding.newTabButton.isVisible -> fabButtonBinding.newTabButton
else -> null
}
private fun showInactiveTabsAutoCloseConfirmationSnackbar() {

Loading…
Cancel
Save