Skip to content

Commit 4196975

Browse files
committed
Format tracker count based on Locale
We want to add commas or whatever is appropriate to the number for cases where it goes to 1,000 and above
1 parent b163162 commit 4196975

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

app/src/main/java/com/duckduckgo/app/tabs/ui/TrackerCountAnimator.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import android.view.animation.AccelerateDecelerateInterpolator
2323
import android.widget.TextView
2424
import androidx.annotation.StringRes
2525
import androidx.core.text.HtmlCompat
26+
import java.text.NumberFormat
2627
import javax.inject.Inject
2728
import kotlin.math.roundToInt
2829
import kotlin.time.Duration.Companion.seconds
@@ -39,6 +40,7 @@ class TrackerCountAnimator @Inject constructor() {
3940
@StringRes private var stringRes: Int? = null
4041
private var trackerTextView: TextView? = null
4142
private lateinit var context: Context
43+
private val trackerCountNumberFormatter by lazy(LazyThreadSafetyMode.NONE) { NumberFormat.getNumberInstance() }
4244

4345
private val animator = ValueAnimator().apply {
4446
interpolator = AccelerateDecelerateInterpolator()
@@ -82,7 +84,8 @@ class TrackerCountAnimator @Inject constructor() {
8284
}
8385

8486
private fun getFormattedText(context: Context, @StringRes stringRes: Int, trackerCount: Int): Spanned {
85-
val text = context.getString(stringRes, trackerCount)
87+
val formattedTrackerCount = trackerCountNumberFormatter.format(trackerCount)
88+
val text = context.getString(stringRes, formattedTrackerCount)
8689
return HtmlCompat.fromHtml(text, HtmlCompat.FROM_HTML_MODE_LEGACY)
8790
}
8891
}

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@
114114
<string name="tabSwitcherGridViewMenu">Grid view</string>
115115

116116
<!--Tab Switcher Animation-->
117-
<string name="trackersBlockedInTheLast7days" instruction="Placeholder is the number of trackers blocked">&lt;b&gt;%1$d trackers blocked &lt;/b&gt; in the last 7 days</string>
118-
<string name="trackersBlocked" instruction="Placeholder is the number of trackers blocked">&lt;b&gt;%1$d trackers blocked &lt;/b&gt;</string>
117+
<string name="trackersBlockedInTheLast7days" instruction="Placeholder is the number of trackers blocked">&lt;b&gt;%1$s trackers blocked &lt;/b&gt; in the last 7 days</string>
118+
<string name="trackersBlocked" instruction="Placeholder is the number of trackers blocked">&lt;b&gt;%1$s trackers blocked &lt;/b&gt;</string>
119119
<string name="inTheLast7Days">in the last 7 days</string>
120120

121121
<!-- Fire -->

0 commit comments

Comments
 (0)