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 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 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 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) @OptIn(ExperimentalPagerApi::class, ExperimentalComposeUiApi::class)
@Suppress("LongMethod", "LongParameterList", "ComplexMethod") @Suppress("LongMethod", "LongParameterList", "ComplexMethod")
@ -97,6 +99,7 @@ fun TabsTray(
onInactiveTabClick: (TabSessionState) -> Unit, onInactiveTabClick: (TabSessionState) -> Unit,
onInactiveTabClose: (TabSessionState) -> Unit, onInactiveTabClose: (TabSessionState) -> Unit,
onSyncedTabClick: (SyncTab) -> Unit, onSyncedTabClick: (SyncTab) -> Unit,
onSaveToCollectionClick: () -> Unit,
) { ) {
val normalTabCount = browserStore val normalTabCount = browserStore
.observeAsComposableState { state -> state.normalTabs.size }.value ?: 0 .observeAsComposableState { state -> state.normalTabs.size }.value ?: 0
@ -139,6 +142,7 @@ fun TabsTray(
isInDebugMode = isInDebugMode, isInDebugMode = isInDebugMode,
onTabPageIndicatorClicked = onTabPageClick, onTabPageIndicatorClicked = onTabPageClick,
onExitSelectModeClick = { tabsTrayStore.dispatch(TabsTrayAction.ExitSelectMode) }, onExitSelectModeClick = { tabsTrayStore.dispatch(TabsTrayAction.ExitSelectMode) },
onSaveToCollectionClick = onSaveToCollectionClick,
) )
} }
@ -491,6 +495,7 @@ private fun TabsTrayPreviewRoot(
onInactiveTabClick = {}, onInactiveTabClick = {},
onInactiveTabClose = inactiveTabsState::remove, onInactiveTabClose = inactiveTabsState::remove,
onSyncedTabClick = {}, 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 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 * @param onExitSelectModeClick Invoked when the user clicks on exit select mode button from the
* multi select banner. * multi select banner.
* @param onSaveToCollectionClick Invoked when the user clicks on the save to collection button from
* the multi select banner.
*/ */
@Suppress("LongParameterList") @Suppress("LongParameterList")
@Composable @Composable
@ -73,12 +75,14 @@ fun TabsTrayBanner(
isInDebugMode: Boolean, isInDebugMode: Boolean,
onTabPageIndicatorClicked: (Page) -> Unit, onTabPageIndicatorClicked: (Page) -> Unit,
onExitSelectModeClick: () -> Unit, onExitSelectModeClick: () -> Unit,
onSaveToCollectionClick: () -> Unit,
) { ) {
if (selectMode is TabsTrayState.Mode.Select) { if (selectMode is TabsTrayState.Mode.Select) {
MultiSelectBanner( MultiSelectBanner(
selectedTabCount = selectMode.selectedTabs.size, selectedTabCount = selectMode.selectedTabs.size,
shouldShowInactiveButton = isInDebugMode, shouldShowInactiveButton = isInDebugMode,
onExitSelectModeClick = onExitSelectModeClick, onExitSelectModeClick = onExitSelectModeClick,
onSaveToCollectionsClick = onSaveToCollectionClick,
) )
} else { } else {
SingleSelectBanner( SingleSelectBanner(
@ -222,6 +226,7 @@ private fun NormalTabsTabIcon(normalTabCount: Int) {
* @param selectedTabCount Number of selected tabs. * @param selectedTabCount Number of selected tabs.
* @param shouldShowInactiveButton Whether or not to show the inactive tabs menu item. * @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 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") @Suppress("LongMethod")
@Composable @Composable
@ -229,6 +234,7 @@ private fun MultiSelectBanner(
selectedTabCount: Int, selectedTabCount: Int,
shouldShowInactiveButton: Boolean, shouldShowInactiveButton: Boolean,
onExitSelectModeClick: () -> Unit, onExitSelectModeClick: () -> Unit,
onSaveToCollectionsClick: () -> Unit,
) { ) {
var showMenu by remember { mutableStateOf(false) } var showMenu by remember { mutableStateOf(false) }
val menuItems = mutableListOf( val menuItems = mutableListOf(
@ -272,7 +278,7 @@ private fun MultiSelectBanner(
Spacer(modifier = Modifier.weight(1.0f)) Spacer(modifier = Modifier.weight(1.0f))
IconButton(onClick = {}) { IconButton(onClick = onSaveToCollectionsClick) {
Icon( Icon(
painter = painterResource(id = R.drawable.ic_tab_collection), painter = painterResource(id = R.drawable.ic_tab_collection),
contentDescription = stringResource( contentDescription = stringResource(
@ -369,6 +375,7 @@ private fun TabsTrayBannerPreviewRoot(
selectedPageState = page selectedPageState = page
}, },
onExitSelectModeClick = { selectModeState = TabsTrayState.Mode.Normal }, onExitSelectModeClick = { selectModeState = TabsTrayState.Mode.Normal },
onSaveToCollectionClick = {},
) )
} }
} }

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

Loading…
Cancel
Save