Bug 1816517 - Add functionality for the three-dot button in the tabs tray page indicator

fenix/115.2.0
Alexandru2909 1 year ago committed by mergify[bot]
parent 4ffee2c338
commit c93819b91c

@ -29,6 +29,7 @@ import com.google.accompanist.pager.ExperimentalPagerApi
import com.google.accompanist.pager.HorizontalPager import com.google.accompanist.pager.HorizontalPager
import com.google.accompanist.pager.rememberPagerState import com.google.accompanist.pager.rememberPagerState
import mozilla.components.browser.state.selector.normalTabs import mozilla.components.browser.state.selector.normalTabs
import mozilla.components.browser.state.selector.privateTabs
import mozilla.components.browser.state.state.BrowserState import mozilla.components.browser.state.state.BrowserState
import mozilla.components.browser.state.state.ContentState import mozilla.components.browser.state.state.ContentState
import mozilla.components.browser.state.state.TabSessionState import mozilla.components.browser.state.state.TabSessionState
@ -75,6 +76,11 @@ import mozilla.components.browser.storage.sync.Tab as SyncTab
* the multi select banner. * the multi select banner.
* @param onShareSelectedTabsClick Invoked when the user clicks on the share button from the * @param onShareSelectedTabsClick Invoked when the user clicks on the share button from the
* multi select banner. * multi select banner.
* @param onShareAllTabsClick Invoked when the user clicks on the share all tabs banner menu item.
* @param onTabSettingsClick Invoked when the user clicks on the tab settings banner menu item.
* @param onRecentlyClosedClick Invoked when the user clicks on the recently closed banner menu item.
* @param onAccountSettingsClick Invoked when the user clicks on the account settings banner menu item.
* @param onDeleteAllTabsClick Invoked when the user clicks on the close all tabs banner menu item.
*/ */
@OptIn(ExperimentalPagerApi::class) @OptIn(ExperimentalPagerApi::class)
@Suppress("LongMethod", "LongParameterList", "ComplexMethod") @Suppress("LongMethod", "LongParameterList", "ComplexMethod")
@ -102,9 +108,16 @@ fun TabsTray(
onSyncedTabClick: (SyncTab) -> Unit, onSyncedTabClick: (SyncTab) -> Unit,
onSaveToCollectionClick: () -> Unit, onSaveToCollectionClick: () -> Unit,
onShareSelectedTabsClick: () -> Unit, onShareSelectedTabsClick: () -> Unit,
onShareAllTabsClick: () -> Unit,
onTabSettingsClick: () -> Unit,
onRecentlyClosedClick: () -> Unit,
onAccountSettingsClick: () -> Unit,
onDeleteAllTabsClick: () -> Unit,
) { ) {
val normalTabCount = browserStore val normalTabCount = browserStore
.observeAsComposableState { state -> state.normalTabs.size }.value ?: 0 .observeAsComposableState { state -> state.normalTabs.size }.value ?: 0
val privateTabCount = browserStore
.observeAsComposableState { state -> state.privateTabs.size }.value ?: 0
val multiselectMode = tabsTrayStore val multiselectMode = tabsTrayStore
.observeAsComposableState { state -> state.mode }.value ?: TabsTrayState.Mode.Normal .observeAsComposableState { state -> state.mode }.value ?: TabsTrayState.Mode.Normal
val selectedPage = tabsTrayStore val selectedPage = tabsTrayStore
@ -141,11 +154,18 @@ fun TabsTray(
selectMode = multiselectMode, selectMode = multiselectMode,
selectedPage = selectedPage, selectedPage = selectedPage,
normalTabCount = normalTabCount, normalTabCount = normalTabCount,
privateTabCount = privateTabCount,
isInDebugMode = isInDebugMode, isInDebugMode = isInDebugMode,
onTabPageIndicatorClicked = onTabPageClick, onTabPageIndicatorClicked = onTabPageClick,
onExitSelectModeClick = { tabsTrayStore.dispatch(TabsTrayAction.ExitSelectMode) }, onExitSelectModeClick = { tabsTrayStore.dispatch(TabsTrayAction.ExitSelectMode) },
onSaveToCollectionClick = onSaveToCollectionClick, onSaveToCollectionClick = onSaveToCollectionClick,
onShareSelectedTabsClick = onShareSelectedTabsClick, onShareSelectedTabsClick = onShareSelectedTabsClick,
onEnterMultiselectModeClick = { tabsTrayStore.dispatch(TabsTrayAction.EnterSelectMode) },
onShareAllTabsClick = onShareAllTabsClick,
onTabSettingsClick = onTabSettingsClick,
onRecentlyClosedClick = onRecentlyClosedClick,
onAccountSettingsClick = onAccountSettingsClick,
onDeleteAllTabsClick = onDeleteAllTabsClick,
) )
} }
@ -500,6 +520,11 @@ private fun TabsTrayPreviewRoot(
onSyncedTabClick = {}, onSyncedTabClick = {},
onSaveToCollectionClick = {}, onSaveToCollectionClick = {},
onShareSelectedTabsClick = {}, onShareSelectedTabsClick = {},
onShareAllTabsClick = {},
onTabSettingsClick = {},
onRecentlyClosedClick = {},
onAccountSettingsClick = {},
onDeleteAllTabsClick = {},
) )
} }
} }

@ -35,6 +35,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.dimensionResource import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
@ -59,6 +60,7 @@ private val ICON_SIZE = 24.dp
* @param selectMode Current [TabsTrayState.Mode] used in the tabs tray. * @param selectMode Current [TabsTrayState.Mode] used in the tabs tray.
* @param selectedPage The active [Page] of the Tabs Tray. * @param selectedPage The active [Page] of the Tabs Tray.
* @param normalTabCount The total amount of normal browsing tabs currently open. * @param normalTabCount The total amount of normal browsing tabs currently open.
* @param privateTabCount The number of private browsing tabs currently open.
* @param isInDebugMode True for debug variant or if secret menu is enabled for this session. * @param isInDebugMode True for debug variant or if secret menu is enabled for this session.
* @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
@ -66,6 +68,12 @@ private val ICON_SIZE = 24.dp
* @param onSaveToCollectionClick Invoked when the user clicks on the save to collection button from * @param onSaveToCollectionClick Invoked when the user clicks on the save to collection button from
* the multi select banner. * the multi select banner.
* @param onShareSelectedTabsClick Invoked when the user clicks on the share button from the multi select banner. * @param onShareSelectedTabsClick Invoked when the user clicks on the share button from the multi select banner.
* @param onEnterMultiselectModeClick Invoked when the user clicks on the enter multiselect mode menu item.
* @param onShareAllTabsClick Invoked when the user clicks on the share menu item.
* @param onTabSettingsClick Invoked when the user clicks on the tab settings menu item.
* @param onRecentlyClosedClick Invoked when the user clicks on the recently closed tabs menu item.
* @param onAccountSettingsClick Invoked when the user clicks on the account settings menu item.
* @param onDeleteAllTabsClick Invoked when user interacts with the close all tabs menu item.
*/ */
@Suppress("LongParameterList") @Suppress("LongParameterList")
@Composable @Composable
@ -73,11 +81,18 @@ fun TabsTrayBanner(
selectMode: TabsTrayState.Mode, selectMode: TabsTrayState.Mode,
selectedPage: Page, selectedPage: Page,
normalTabCount: Int, normalTabCount: Int,
privateTabCount: Int,
isInDebugMode: Boolean, isInDebugMode: Boolean,
onTabPageIndicatorClicked: (Page) -> Unit, onTabPageIndicatorClicked: (Page) -> Unit,
onExitSelectModeClick: () -> Unit, onExitSelectModeClick: () -> Unit,
onSaveToCollectionClick: () -> Unit, onSaveToCollectionClick: () -> Unit,
onShareSelectedTabsClick: () -> Unit, onShareSelectedTabsClick: () -> Unit,
onEnterMultiselectModeClick: () -> Unit,
onShareAllTabsClick: () -> Unit,
onTabSettingsClick: () -> Unit,
onRecentlyClosedClick: () -> Unit,
onAccountSettingsClick: () -> Unit,
onDeleteAllTabsClick: () -> Unit,
) { ) {
if (selectMode is TabsTrayState.Mode.Select) { if (selectMode is TabsTrayState.Mode.Select) {
MultiSelectBanner( MultiSelectBanner(
@ -92,19 +107,34 @@ fun TabsTrayBanner(
onTabPageIndicatorClicked = onTabPageIndicatorClicked, onTabPageIndicatorClicked = onTabPageIndicatorClicked,
selectedPage = selectedPage, selectedPage = selectedPage,
normalTabCount = normalTabCount, normalTabCount = normalTabCount,
privateTabCount = privateTabCount,
onEnterMultiselectModeClick = onEnterMultiselectModeClick,
onShareAllTabsClick = onShareAllTabsClick,
onTabSettingsClick = onTabSettingsClick,
onRecentlyClosedClick = onRecentlyClosedClick,
onAccountSettingsClick = onAccountSettingsClick,
onDeleteAllTabsClick = onDeleteAllTabsClick,
) )
} }
} }
@Suppress("LongMethod") @Suppress("LongMethod", "LongParameterList")
@Composable @Composable
private fun SingleSelectBanner( private fun SingleSelectBanner(
selectedPage: Page, selectedPage: Page,
normalTabCount: Int, normalTabCount: Int,
privateTabCount: Int,
onTabPageIndicatorClicked: (Page) -> Unit, onTabPageIndicatorClicked: (Page) -> Unit,
onEnterMultiselectModeClick: () -> Unit,
onShareAllTabsClick: () -> Unit,
onTabSettingsClick: () -> Unit,
onRecentlyClosedClick: () -> Unit,
onAccountSettingsClick: () -> Unit,
onDeleteAllTabsClick: () -> Unit,
) { ) {
val selectedColor = FirefoxTheme.colors.iconActive val selectedColor = FirefoxTheme.colors.iconActive
val inactiveColor = FirefoxTheme.colors.iconPrimaryInactive val inactiveColor = FirefoxTheme.colors.iconPrimaryInactive
var showMenu by remember { mutableStateOf(false) }
Column { Column {
Spacer(modifier = Modifier.height(dimensionResource(id = R.dimen.bottom_sheet_handle_top_margin))) Spacer(modifier = Modifier.height(dimensionResource(id = R.dimen.bottom_sheet_handle_top_margin)))
@ -174,9 +204,25 @@ private fun SingleSelectBanner(
Spacer(modifier = Modifier.weight(1.0f)) Spacer(modifier = Modifier.weight(1.0f))
IconButton( IconButton(
onClick = {}, onClick = { showMenu = true },
modifier = Modifier.align(Alignment.CenterVertically), modifier = Modifier.align(Alignment.CenterVertically),
) { ) {
DropdownMenu(
menuItems = generateSingleSelectBannerMenuItems(
selectedPage,
normalTabCount,
privateTabCount,
onTabSettingsClick,
onRecentlyClosedClick,
onEnterMultiselectModeClick,
onShareAllTabsClick,
onDeleteAllTabsClick,
onAccountSettingsClick,
),
showMenu = showMenu,
offset = DpOffset(x = 0.dp, y = -ICON_SIZE),
onDismissRequest = { showMenu = false },
)
Icon( Icon(
painter = painterResource(R.drawable.ic_menu), painter = painterResource(R.drawable.ic_menu),
contentDescription = stringResource(id = R.string.open_tabs_menu), contentDescription = stringResource(id = R.string.open_tabs_menu),
@ -187,6 +233,79 @@ private fun SingleSelectBanner(
} }
} }
@Suppress("LongParameterList")
@Composable
private fun generateSingleSelectBannerMenuItems(
selectedPage: Page,
normalTabCount: Int,
privateTabCount: Int,
onTabSettingsClick: () -> Unit,
onRecentlyClosedClick: () -> Unit,
onEnterMultiselectModeClick: () -> Unit,
onShareAllTabsClick: () -> Unit,
onDeleteAllTabsClick: () -> Unit,
onAccountSettingsClick: () -> Unit,
): List<MenuItem> {
val tabSettingsItem = MenuItem(
stringResource(id = R.string.tab_tray_menu_tab_settings),
colorResource(id = R.color.fx_mobile_text_color_primary),
onTabSettingsClick,
)
val recentlyClosedTabsItem = MenuItem(
stringResource(id = R.string.tab_tray_menu_recently_closed),
colorResource(id = R.color.fx_mobile_text_color_primary),
onRecentlyClosedClick,
)
val enterSelectModeItem = MenuItem(
stringResource(id = R.string.tabs_tray_select_tabs),
colorResource(id = R.color.fx_mobile_text_color_primary),
onEnterMultiselectModeClick,
)
val shareAllTabsItem = MenuItem(
stringResource(id = R.string.tab_tray_menu_item_share),
colorResource(id = R.color.fx_mobile_text_color_primary),
onShareAllTabsClick,
)
val deleteAllTabsItem = MenuItem(
stringResource(id = R.string.tab_tray_menu_item_close),
colorResource(id = R.color.fx_mobile_text_color_primary),
onDeleteAllTabsClick,
)
val accountSettingsItem = MenuItem(
stringResource(id = R.string.tab_tray_menu_account_settings),
colorResource(id = R.color.fx_mobile_text_color_primary),
onAccountSettingsClick,
)
return when {
selectedPage == Page.NormalTabs && normalTabCount == 0 ||
selectedPage == Page.PrivateTabs && privateTabCount == 0 -> listOf(
tabSettingsItem,
recentlyClosedTabsItem,
)
selectedPage == Page.NormalTabs -> listOf(
enterSelectModeItem,
shareAllTabsItem,
tabSettingsItem,
recentlyClosedTabsItem,
deleteAllTabsItem,
)
selectedPage == Page.PrivateTabs -> listOf(
tabSettingsItem,
recentlyClosedTabsItem,
deleteAllTabsItem,
)
selectedPage == Page.SyncedTabs -> listOf(
accountSettingsItem,
recentlyClosedTabsItem,
)
else -> emptyList()
}
}
@Composable @Composable
private fun NormalTabsTabIcon(normalTabCount: Int) { private fun NormalTabsTabIcon(normalTabCount: Int) {
val normalTabCountText: String val normalTabCountText: String
@ -375,6 +494,7 @@ private fun TabsTrayBannerPreviewRoot(
selectMode = selectModeState, selectMode = selectModeState,
selectedPage = selectedPageState, selectedPage = selectedPageState,
normalTabCount = normalTabCount, normalTabCount = normalTabCount,
privateTabCount = 10,
isInDebugMode = true, isInDebugMode = true,
onTabPageIndicatorClicked = { page -> onTabPageIndicatorClicked = { page ->
selectedPageState = page selectedPageState = page
@ -382,6 +502,12 @@ private fun TabsTrayBannerPreviewRoot(
onExitSelectModeClick = { selectModeState = TabsTrayState.Mode.Normal }, onExitSelectModeClick = { selectModeState = TabsTrayState.Mode.Normal },
onSaveToCollectionClick = {}, onSaveToCollectionClick = {},
onShareSelectedTabsClick = {}, onShareSelectedTabsClick = {},
onEnterMultiselectModeClick = {},
onShareAllTabsClick = {},
onTabSettingsClick = {},
onRecentlyClosedClick = {},
onAccountSettingsClick = {},
onDeleteAllTabsClick = {},
) )
} }
} }

@ -260,6 +260,21 @@ class TabsTrayFragment : AppCompatDialogFragment() {
onSyncedTabClick = tabsTrayInteractor::onSyncedTabClicked, onSyncedTabClick = tabsTrayInteractor::onSyncedTabClicked,
onSaveToCollectionClick = tabsTrayInteractor::onAddSelectedTabsToCollectionClicked, onSaveToCollectionClick = tabsTrayInteractor::onAddSelectedTabsToCollectionClicked,
onShareSelectedTabsClick = tabsTrayInteractor::onShareSelectedTabs, onShareSelectedTabsClick = tabsTrayInteractor::onShareSelectedTabs,
onShareAllTabsClick = {
TabsTray.shareAllTabs.record(NoExtras())
navigationInteractor.onShareTabsOfTypeClicked(
private = tabsTrayStore.state.selectedPage == Page.PrivateTabs,
)
},
onTabSettingsClick = navigationInteractor::onTabSettingsClicked,
onRecentlyClosedClick = navigationInteractor::onOpenRecentlyClosedClicked,
onAccountSettingsClick = navigationInteractor::onAccountSettingsClicked,
onDeleteAllTabsClick = {
TabsTray.closeAllTabs.record(NoExtras())
navigationInteractor.onCloseAllTabsClicked(
private = tabsTrayStore.state.selectedPage == Page.PrivateTabs,
)
},
) )
} }
} }

Loading…
Cancel
Save