diff --git a/fenix/app/src/main/java/org/mozilla/fenix/compose/TabCounter.kt b/fenix/app/src/main/java/org/mozilla/fenix/compose/TabCounter.kt index a2f2d070973b..b35235f2f703 100644 --- a/fenix/app/src/main/java/org/mozilla/fenix/compose/TabCounter.kt +++ b/fenix/app/src/main/java/org/mozilla/fenix/compose/TabCounter.kt @@ -4,6 +4,7 @@ package org.mozilla.fenix.compose +import androidx.compose.foundation.background import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.padding import androidx.compose.material.Icon @@ -21,9 +22,11 @@ import androidx.compose.ui.semantics.semantics import androidx.compose.ui.semantics.testTag import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import org.mozilla.fenix.R import org.mozilla.fenix.compose.annotation.LightDarkPreview +import org.mozilla.fenix.compose.ext.toLocaleString import org.mozilla.fenix.tabstray.TabsTrayTestTag import org.mozilla.fenix.theme.FirefoxTheme @@ -48,19 +51,20 @@ private const val TAB_TEXT_BOTTOM_PADDING_RATIO = 4 @Composable fun TabCounter(tabCount: Int) { + val formattedTabCount = tabCount.toLocaleString() val normalTabCountText: String val tabCountTextRatio: Float val needsBottomPaddingForInfiniteTabs: Boolean when (tabCount) { in MIN_SINGLE_DIGIT..MAX_SINGLE_DIGIT -> { - normalTabCountText = tabCount.toString() + normalTabCountText = formattedTabCount tabCountTextRatio = ONE_DIGIT_SIZE_RATIO needsBottomPaddingForInfiniteTabs = false } in TWO_DIGIT_THRESHOLD..MAX_VISIBLE_TABS -> { - normalTabCountText = tabCount.toString() + normalTabCountText = formattedTabCount tabCountTextRatio = TWO_DIGITS_SIZE_RATIO needsBottomPaddingForInfiniteTabs = false } @@ -77,7 +81,7 @@ fun TabCounter(tabCount: Int) { } else { stringResource( id = R.string.mozac_tab_counter_open_tab_tray_plural, - tabCount.toString(), + formattedTabCount, ) } @@ -119,9 +123,14 @@ fun TabCounter(tabCount: Int) { } @LightDarkPreview +@Preview(locale = "ar") @Composable private fun TabCounterPreview() { FirefoxTheme { - TabCounter(tabCount = 55) + Box( + modifier = Modifier.background(color = FirefoxTheme.colors.layer1), + ) { + TabCounter(tabCount = 55) + } } } diff --git a/fenix/app/src/main/java/org/mozilla/fenix/compose/ext/Int.kt b/fenix/app/src/main/java/org/mozilla/fenix/compose/ext/Int.kt new file mode 100644 index 000000000000..7d09419cc687 --- /dev/null +++ b/fenix/app/src/main/java/org/mozilla/fenix/compose/ext/Int.kt @@ -0,0 +1,15 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package org.mozilla.fenix.compose.ext + +import androidx.compose.ui.text.intl.Locale +import java.text.NumberFormat +import java.util.Locale as JavaLocale + +/** + * Returns a localized string representation of the value. + */ +fun Int.toLocaleString(): String = + NumberFormat.getNumberInstance(JavaLocale(Locale.current.language)).format(this) diff --git a/fenix/app/src/main/java/org/mozilla/fenix/debugsettings/tabs/TabTools.kt b/fenix/app/src/main/java/org/mozilla/fenix/debugsettings/tabs/TabTools.kt index c6daa5d80e7e..5fa97b7c0393 100644 --- a/fenix/app/src/main/java/org/mozilla/fenix/debugsettings/tabs/TabTools.kt +++ b/fenix/app/src/main/java/org/mozilla/fenix/debugsettings/tabs/TabTools.kt @@ -43,6 +43,7 @@ import org.mozilla.fenix.R import org.mozilla.fenix.compose.Divider import org.mozilla.fenix.compose.annotation.LightDarkPreview import org.mozilla.fenix.compose.button.PrimaryButton +import org.mozilla.fenix.compose.ext.toLocaleString import org.mozilla.fenix.debugsettings.ui.DebugDrawer import org.mozilla.fenix.ext.maxActiveTime import org.mozilla.fenix.tabstray.ext.isNormalTabInactive @@ -152,19 +153,19 @@ private fun TabCounter( TabCountRow( tabType = stringResource(R.string.debug_drawer_tab_tools_tab_count_normal), - count = activeTabCount.toString(), + count = activeTabCount, ) if (inactiveTabsEnabled) { TabCountRow( tabType = stringResource(R.string.debug_drawer_tab_tools_tab_count_inactive), - count = inactiveTabCount.toString(), + count = inactiveTabCount, ) } TabCountRow( tabType = stringResource(R.string.debug_drawer_tab_tools_tab_count_private), - count = privateTabCount.toString(), + count = privateTabCount, ) Spacer(modifier = Modifier.height(8.dp)) @@ -175,7 +176,7 @@ private fun TabCounter( TabCountRow( tabType = stringResource(R.string.debug_drawer_tab_tools_tab_count_total), - count = totalTabCount.toString(), + count = totalTabCount, ) } } @@ -183,7 +184,7 @@ private fun TabCounter( @Composable private fun TabCountRow( tabType: String, - count: String, + count: Int, ) { Row( modifier = Modifier @@ -198,14 +199,14 @@ private fun TabCountRow( ) Text( - text = count, + text = count.toLocaleString(), color = FirefoxTheme.colors.textSecondary, style = FirefoxTheme.typography.headline6, ) } } -private const val DEFAULT_TABS_TO_ADD = "1" +private const val DEFAULT_TABS_TO_ADD = 1 @OptIn(ExperimentalComposeUiApi::class) @Composable @@ -213,7 +214,7 @@ private fun TabCreationTool( inactiveTabsEnabled: Boolean, onCreateTabsClick: ((quantity: Int, isInactive: Boolean, isPrivate: Boolean) -> Unit), ) { - var tabQuantityToCreate by rememberSaveable { mutableStateOf(DEFAULT_TABS_TO_ADD) } + var tabQuantityToCreate by rememberSaveable { mutableStateOf(DEFAULT_TABS_TO_ADD.toLocaleString()) } var hasError by rememberSaveable { mutableStateOf(false) } val keyboardController = LocalSoftwareKeyboardController.current