diff --git a/android/app/src/main/java/app/organicmaps/car/screens/download/DownloaderScreen.java b/android/app/src/main/java/app/organicmaps/car/screens/download/DownloaderScreen.java index bf898b5e66..b65924aedf 100644 --- a/android/app/src/main/java/app/organicmaps/car/screens/download/DownloaderScreen.java +++ b/android/app/src/main/java/app/organicmaps/car/screens/download/DownloaderScreen.java @@ -150,12 +150,11 @@ class DownloaderScreen extends BaseScreen return getCarContext().getString(R.string.downloader_loading_ios); final long downloadedSize = getDownloadedSize(); - final float progress = (float) downloadedSize / mTotalSize * 100; + final String progressPercent = StringUtils.formatPercent((double) downloadedSize / mTotalSize); final String totalSizeStr = StringUtils.getFileSizeString(getCarContext(), mTotalSize); final String downloadedSizeStr = StringUtils.getFileSizeString(getCarContext(), downloadedSize); - return StringUtils.formatUsingSystemLocale("%.2f%%\n%s", - progress, downloadedSizeStr + " / " + totalSizeStr); + return progressPercent + "\n" + downloadedSizeStr + " / " + totalSizeStr; } private long getDownloadedSize() diff --git a/android/app/src/main/java/app/organicmaps/downloader/CountryItem.java b/android/app/src/main/java/app/organicmaps/downloader/CountryItem.java index 7fd0e8eee4..8f0e276626 100644 --- a/android/app/src/main/java/app/organicmaps/downloader/CountryItem.java +++ b/android/app/src/main/java/app/organicmaps/downloader/CountryItem.java @@ -63,7 +63,9 @@ public final class CountryItem implements Comparable public int errorCode; public boolean present; - // Progress + /** + * This value represents the percentage of download (values span from 0 to 100) + */ public float progress; public long downloadedBytes; public long bytesToDownload; diff --git a/android/app/src/main/java/app/organicmaps/downloader/CountrySuggestFragment.java b/android/app/src/main/java/app/organicmaps/downloader/CountrySuggestFragment.java index 803e9a28ae..3a843fb4c2 100644 --- a/android/app/src/main/java/app/organicmaps/downloader/CountrySuggestFragment.java +++ b/android/app/src/main/java/app/organicmaps/downloader/CountrySuggestFragment.java @@ -192,8 +192,7 @@ public class CountrySuggestFragment extends BaseMwmFragment implements View.OnCl private void updateProgress() { - String text = StringUtils.formatUsingSystemLocale("%1$s %2$.2f%%", getString(R.string.downloader_downloading), - mDownloadingCountry.progress); + String text = getString(R.string.downloader_downloading) + " " + StringUtils.formatPercent(mDownloadingCountry.progress / 100); mTvProgress.setText(text); mWpvDownloadProgress.setProgress(Math.round(mDownloadingCountry.progress)); } diff --git a/android/app/src/main/java/app/organicmaps/downloader/OnmapDownloader.java b/android/app/src/main/java/app/organicmaps/downloader/OnmapDownloader.java index c61f92e631..f637a2d49f 100644 --- a/android/app/src/main/java/app/organicmaps/downloader/OnmapDownloader.java +++ b/android/app/src/main/java/app/organicmaps/downloader/OnmapDownloader.java @@ -140,8 +140,7 @@ public class OnmapDownloader implements MwmActivity.LeftAnimationTrackListener { mProgress.setPending(false); mProgress.setProgress(Math.round(mCurrentCountry.progress)); - sizeText = StringUtils.formatUsingSystemLocale("%1$s %2$.2f%%", - mActivity.getString(R.string.downloader_downloading), mCurrentCountry.progress); + sizeText = mActivity.getString(R.string.downloader_downloading) + " " + StringUtils.formatPercent(mCurrentCountry.progress / 100); } else { diff --git a/android/app/src/main/java/app/organicmaps/util/StringUtils.java b/android/app/src/main/java/app/organicmaps/util/StringUtils.java index d82b80a092..8f991fb30f 100644 --- a/android/app/src/main/java/app/organicmaps/util/StringUtils.java +++ b/android/app/src/main/java/app/organicmaps/util/StringUtils.java @@ -10,6 +10,7 @@ import androidx.annotation.NonNull; import app.organicmaps.MwmApplication; import app.organicmaps.R; +import java.text.NumberFormat; import java.util.Locale; public class StringUtils @@ -24,6 +25,25 @@ public class StringUtils return String.format(Locale.getDefault(), pattern, args); } + /** + * This method returns correct string representation of % (percent number) for different locales + * For example, that's how the result of would look like: + * — formatPercent(0.2319) will return 23.19% (in US locale) + * — formatPercent(0.2319) will return %23.19 (in Turkish locale) + * — formatPercent(0.2319) will return 23,19% (in Latvian locale) + * — formatPercent(1.23) will return 123% + * — formatPercent(0.000145) will return 0.01% + * — formatPercent(0.37) will return 37% + * + * @param fraction a double value, that represents a fraction of a whole + * @return correct string representation of percent for different locales + */ + public static String formatPercent(double fraction) { + NumberFormat percentFormat = NumberFormat.getPercentInstance(); + percentFormat.setMaximumFractionDigits(2); + return percentFormat.format(fraction); + } + public static native boolean nativeIsHtml(String text); public static native boolean nativeContainsNormalized(String str, String substr);