From 5c9abf7a0b991d72f3959f5739240d923545838b Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Fri, 3 Jan 2025 14:18:01 -0500 Subject: [PATCH] Removed getSafeLocale --- .../wordpress/android/ui/posts/PostUtils.java | 19 +++++-------- .../android/ui/reader/utils/ReaderUtils.java | 6 ++--- .../ui/reader/views/ReaderSiteHeaderView.java | 9 ++++--- .../wordpress/android/util/LocaleManager.kt | 27 ------------------- 4 files changed, 14 insertions(+), 47 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostUtils.java b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostUtils.java index 818e10c1063c..6b6e085097be 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostUtils.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostUtils.java @@ -29,7 +29,6 @@ import org.wordpress.android.util.AppLog.T; import org.wordpress.android.util.DateTimeUtils; import org.wordpress.android.util.HtmlUtils; -import org.wordpress.android.util.LocaleManager; import org.wordpress.android.util.SiteUtils; import org.wordpress.android.util.UrlUtils; import org.wordpress.android.util.analytics.AnalyticsUtils; @@ -489,9 +488,9 @@ public static String getConflictedPostCustomStringForDialog(PostModel post) { String secondPart = String.format(context.getString(R.string.dialog_confirm_load_remote_post_body_2), getFormattedDateForLastModified( - context, DateTimeUtils.timestampFromIso8601Millis(lastModified)), + DateTimeUtils.timestampFromIso8601Millis(lastModified)), getFormattedDateForLastModified( - context, DateTimeUtils.timestampFromIso8601Millis(post.getRemoteLastModified()))); + DateTimeUtils.timestampFromIso8601Millis(post.getRemoteLastModified()))); return firstPart + secondPart; } @@ -505,24 +504,20 @@ public static UiStringText getCustomStringForAutosaveRevisionDialog(PostModel po String secondPart = String.format(context.getString(R.string.dialog_confirm_autosave_body_second_part), getFormattedDateForLastModified( - context, DateTimeUtils.timestampFromIso8601Millis(lastModified)), + DateTimeUtils.timestampFromIso8601Millis(lastModified)), getFormattedDateForLastModified( - context, DateTimeUtils.timestampFromIso8601Millis(post.getAutoSaveModified()))); + DateTimeUtils.timestampFromIso8601Millis(post.getAutoSaveModified()))); return new UiStringText(firstPart + secondPart); } /** * E.g. Jul 2, 2013 @ 21:57 */ - public static String getFormattedDateForLastModified(Context context, long timeSinceLastModified) { + public static String getFormattedDateForLastModified(long timeSinceLastModified) { Date date = new Date(timeSinceLastModified); - DateFormat dateFormat = DateFormat.getDateInstance( - DateFormat.MEDIUM, - LocaleManager.getSafeLocale(context)); - DateFormat timeFormat = DateFormat.getTimeInstance( - DateFormat.SHORT, - LocaleManager.getSafeLocale(context)); + DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM); + DateFormat timeFormat = DateFormat.getTimeInstance(DateFormat.SHORT); dateFormat.setTimeZone(Calendar.getInstance().getTimeZone()); timeFormat.setTimeZone(Calendar.getInstance().getTimeZone()); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/utils/ReaderUtils.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/utils/ReaderUtils.java index 3090e254e266..12f36e575d3f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/utils/ReaderUtils.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/utils/ReaderUtils.java @@ -19,7 +19,6 @@ import org.wordpress.android.ui.reader.ReaderConstants; import org.wordpress.android.ui.reader.services.update.TagUpdateClientUtilsProvider; import org.wordpress.android.util.FormatUtils; -import org.wordpress.android.util.LocaleManager; import org.wordpress.android.util.PhotonUtils; import org.wordpress.android.util.StringUtils; import org.wordpress.android.util.UrlUtils; @@ -167,15 +166,14 @@ public static String getLongLikeLabelText(Context context, int numLikes, boolean return context.getString(R.string.reader_likes_you_and_one); default: String youAndMultiLikes = context.getString(R.string.reader_likes_you_and_multi); - return String.format( - LocaleManager.getSafeLocale(context), youAndMultiLikes, numLikes - 1); + return String.format(youAndMultiLikes, numLikes - 1); } } else { if (numLikes == 1) { return context.getString(R.string.reader_likes_one); } else { String likes = context.getString(R.string.reader_likes_multi); - return String.format(LocaleManager.getSafeLocale(context), likes, numLikes); + return String.format(likes, numLikes); } } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/views/ReaderSiteHeaderView.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/views/ReaderSiteHeaderView.java index 5ef68491adea..a3a6bcee1414 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/views/ReaderSiteHeaderView.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/views/ReaderSiteHeaderView.java @@ -22,7 +22,6 @@ import org.wordpress.android.ui.reader.actions.ReaderBlogActions; import org.wordpress.android.ui.reader.tracker.ReaderTracker; import org.wordpress.android.ui.reader.utils.ReaderUtils; -import org.wordpress.android.util.LocaleManager; import org.wordpress.android.util.NetworkUtils; import org.wordpress.android.util.PhotonUtils; import org.wordpress.android.util.PhotonUtils.Quality; @@ -32,6 +31,7 @@ import org.wordpress.android.util.image.BlavatarShape; import org.wordpress.android.util.image.ImageManager; +import java.util.Locale; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -213,8 +213,10 @@ public void onClick(View v) { private void loadFollowCount(ReaderBlog blogInfo, TextView txtFollowCount) { final CompactDecimalFormat compactDecimalFormat = - CompactDecimalFormat.getInstance(LocaleManager.getSafeLocale(getContext()), - CompactDecimalFormat.CompactStyle.SHORT); + CompactDecimalFormat.getInstance( + Locale.getDefault(), + CompactDecimalFormat.CompactStyle.SHORT + ); final int followersStringRes; if (blogInfo.numSubscribers == 1) { @@ -231,7 +233,6 @@ private void loadFollowCount(ReaderBlog blogInfo, TextView txtFollowCount) { formattedNumberSubscribers = NumberFormat.getInstance().format(blogInfo.numSubscribers); } txtFollowCount.setText(String.format( - LocaleManager.getSafeLocale(getContext()), getContext().getString(followersStringRes), formattedNumberSubscribers) ); } diff --git a/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.kt b/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.kt index 07796d28d9a3..a9d935e97c21 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.kt +++ b/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.kt @@ -44,33 +44,6 @@ object LocaleManager { return langID ?: deviceLanguageCode } - @Suppress("ForbiddenComment") - /** - * Method gets around a bug in the java.util.Formatter for API 7.x as detailed here - * [https://bugs.openjdk.java.net/browse/JDK-8167567]. Any strings that contain - * locale-specific grouping separators should use: - * - * `String.format(LocaleManager.getSafeLocale(context), baseString, val)` - * - * An example of a string that contains locale-specific grouping separators: - * ` - * %,d likes - `* - * TODO: This is a workaround for a bug in API 7, which we no longer support. Investigate removing this. - */ - @JvmStatic - fun getSafeLocale(context: Context?): Locale { - val baseLocale: Locale - if (context == null) { - baseLocale = Locale.getDefault() - } else { - val config = context.resources.configuration - baseLocale = config.locales[0] - } - - return languageLocale(baseLocale.language) - } - /** * Gets a locale for the given language code. *