Skip to content

Commit

Permalink
Removed getSafeLocale
Browse files Browse the repository at this point in the history
  • Loading branch information
nbradbury committed Jan 3, 2025
1 parent 75feb2e commit 5c9abf7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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) {
Expand All @@ -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)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
* `
* <string name="test">%,d likes</string>
`*
* 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.
*
Expand Down

0 comments on commit 5c9abf7

Please sign in to comment.