From 87660b4d3b41a6c6b1387b09aac80fc0d020ceb3 Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Wed, 13 Jan 2021 11:16:34 -0500 Subject: [PATCH] fix locales bug --- app/src/main/java/awais/instagrabber/utils/FlavorTown.java | 5 ++--- app/src/main/java/awais/instagrabber/utils/LocaleUtils.java | 4 +++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/utils/FlavorTown.java b/app/src/main/java/awais/instagrabber/utils/FlavorTown.java index b63620ae..d37d1ce9 100755 --- a/app/src/main/java/awais/instagrabber/utils/FlavorTown.java +++ b/app/src/main/java/awais/instagrabber/utils/FlavorTown.java @@ -20,6 +20,7 @@ import androidx.appcompat.app.AppCompatActivity; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; +import java.util.Locale; import javax.security.cert.CertificateException; import javax.security.cert.X509Certificate; @@ -102,10 +103,8 @@ public final class FlavorTown { public static void changelogCheck(@NonNull final Context context) { if (settingsHelper.getInteger(Constants.PREV_INSTALL_VERSION) < BuildConfig.VERSION_CODE) { - final String langCode = settingsHelper.getString(Constants.APP_LANGUAGE); - final String lang = LocaleUtils.getCorrespondingLanguageCode(langCode); final int appUaCode = settingsHelper.getInteger(Constants.APP_UA_CODE); - final String appUa = UserAgentUtils.generateAppUA(appUaCode, lang); + final String appUa = UserAgentUtils.generateAppUA(appUaCode, LocaleUtils.getCurrentLocale().getLanguage()); settingsHelper.putString(Constants.APP_UA, appUa); final int browserUaCode = settingsHelper.getInteger(Constants.BROWSER_UA_CODE); final String browserUa = UserAgentUtils.generateBrowserUA(browserUaCode); diff --git a/app/src/main/java/awais/instagrabber/utils/LocaleUtils.java b/app/src/main/java/awais/instagrabber/utils/LocaleUtils.java index c48b3341..b9b25462 100755 --- a/app/src/main/java/awais/instagrabber/utils/LocaleUtils.java +++ b/app/src/main/java/awais/instagrabber/utils/LocaleUtils.java @@ -23,7 +23,7 @@ public final class LocaleUtils { Utils.settingsHelper = new SettingsHelper(baseContext); final String appLanguageSettings = Utils.settingsHelper.getString(Constants.APP_LANGUAGE); - final String lang = TextUtils.isEmpty(appLanguageSettings) ? null : LocaleUtils.getCorrespondingLanguageCode(appLanguageSettings); + final String lang = LocaleUtils.getCorrespondingLanguageCode(appLanguageSettings); currentLocale = TextUtils.isEmpty(lang) ? defaultLocale : (lang.contains("_") ? new Locale(lang.split("_")[0], lang.split("_")[1]) : new Locale(lang)); @@ -54,6 +54,8 @@ public final class LocaleUtils { @Nullable public static String getCorrespondingLanguageCode(final String appLanguageSettings) { + if (TextUtils.isEmpty(appLanguageSettings)) return null; + final int appLanguageIndex = Integer.parseInt(appLanguageSettings); if (appLanguageIndex == 1) return "en"; if (appLanguageIndex == 2) return "fr";