diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index 9c44efd5dca6..093028bcc630 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -4,6 +4,7 @@ ----- * [*] Updates splash screen for Android 12+ [https://github.com/wordpress-mobile/WordPress-Android/pull/17273] * [*] Fix text color of success messages in the QR code login flow [https://github.com/wordpress-mobile/WordPress-Android/pull/17286] +* [*] Stats: Fix Western Arabic Numerals not being shown on every text of the stats screens in Arabic languages [https://github.com/wordpress-mobile/WordPress-Android/pull/17217] 20.9 ----- diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/ViewsAndVisitorsMapper.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/ViewsAndVisitorsMapper.kt index 5b5b2eb4b5a6..2b07e43a1f1f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/ViewsAndVisitorsMapper.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/ViewsAndVisitorsMapper.kt @@ -23,6 +23,7 @@ import org.wordpress.android.ui.stats.refresh.utils.MILLION import org.wordpress.android.ui.stats.refresh.utils.StatsDateFormatter import org.wordpress.android.ui.stats.refresh.utils.StatsUtils import org.wordpress.android.ui.utils.ListItemInteraction +import org.wordpress.android.util.extensions.enforceWesternArabicNumerals import org.wordpress.android.viewmodel.ResourceProvider import javax.inject.Inject @@ -117,7 +118,7 @@ class ViewsAndVisitorsMapper val value = it.getValue(selectedType) val date = statsDateFormatter.parseStatsDate(statsGranularity, it.period) Line( - statsDateFormatter.printDayWithoutYear(date), + statsDateFormatter.printDayWithoutYear(date).enforceWesternArabicNumerals() as String, it.period, value.toInt() ) diff --git a/WordPress/src/main/java/org/wordpress/android/util/extensions/StringExtensions.kt b/WordPress/src/main/java/org/wordpress/android/util/extensions/StringExtensions.kt index d02a46fd0d3e..bc145e659952 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/extensions/StringExtensions.kt +++ b/WordPress/src/main/java/org/wordpress/android/util/extensions/StringExtensions.kt @@ -1,6 +1,9 @@ package org.wordpress.android.util.extensions import android.annotation.SuppressLint +import android.text.SpannableString +import android.text.Spanned +import android.text.TextUtils import java.util.Locale /** @@ -17,3 +20,26 @@ import java.util.Locale fun String.capitalizeWithLocaleWithoutLint(locale: Locale): String { return this.capitalize(locale) } + +/** + * Converts digits to Western Arabic -- Workaround for an issue in Android that shows Eastern Arabic numerals. + * There is an issue in Google's bug tracker for this: [SO Answer](https://stackoverflow.com/a/34612487/4129245). + * The returned String uses the default Locale. + * @return a String with numerals in Western Arabic format persisting spans if available. + */ +fun CharSequence.enforceWesternArabicNumerals(): CharSequence { + val textWithArabicNumerals = this + // Replace Eastern Arabic numerals + .replace(Regex("[٠-٩]")) { match -> (match.value.single() - '٠').toString() } + // Replace Persian/Urdu numerals + .replace(Regex("[۰-۹]")) { match -> (match.value.single() - '۰').toString() } + + // Restore spans if text is an instance of Spanned + if (this is Spanned) { + val spannableText = SpannableString(textWithArabicNumerals) + TextUtils.copySpansFrom(this, 0, this.length, null, spannableText, 0) + return spannableText + } + + return textWithArabicNumerals +} diff --git a/WordPress/src/main/java/org/wordpress/android/widgets/MaterialTextViewWithNumerals.kt b/WordPress/src/main/java/org/wordpress/android/widgets/MaterialTextViewWithNumerals.kt index 18fb04afb591..57f63158c293 100644 --- a/WordPress/src/main/java/org/wordpress/android/widgets/MaterialTextViewWithNumerals.kt +++ b/WordPress/src/main/java/org/wordpress/android/widgets/MaterialTextViewWithNumerals.kt @@ -1,11 +1,9 @@ package org.wordpress.android.widgets import android.content.Context -import android.text.SpannableString -import android.text.Spanned -import android.text.TextUtils import android.util.AttributeSet import com.google.android.material.textview.MaterialTextView +import org.wordpress.android.util.extensions.enforceWesternArabicNumerals /** * MaterialTextView which enforces Western Arabic numerals. @@ -18,21 +16,4 @@ class MaterialTextViewWithNumerals @JvmOverloads constructor( override fun setText(text: CharSequence?, type: BufferType?) { super.setText(text?.enforceWesternArabicNumerals(), type) } - - private fun CharSequence.enforceWesternArabicNumerals(): CharSequence { - val textWithArabicNumerals = this - // Replace Eastern Arabic numerals - .replace(Regex("[٠-٩]")) { match -> (match.value.single() - '٠').toString() } - // Replace Persian/Urdu numerals - .replace(Regex("[۰-۹]")) { match -> (match.value.single() - '۰').toString() } - - val spannableText = SpannableString(textWithArabicNumerals) - - // Restore spans if text is an instance of Spanned - if (this is Spanned) { - TextUtils.copySpansFrom(this, 0, this.length, null, spannableText, 0) - } - - return spannableText - } } diff --git a/WordPress/src/main/res/layout/stats_block_text_item.xml b/WordPress/src/main/res/layout/stats_block_text_item.xml index b4d8043fdaa0..60d8a6842b43 100644 --- a/WordPress/src/main/res/layout/stats_block_text_item.xml +++ b/WordPress/src/main/res/layout/stats_block_text_item.xml @@ -8,7 +8,7 @@ android:paddingStart="@dimen/margin_extra_large" android:paddingEnd="@dimen/margin_extra_large"> - + android:visibility="gone" + tools:text="-7 (-100%)" + android:layoutDirection="ltr" + tools:visibility="visible" />