Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove LocaleManager.getSafeLocale #21560

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading