1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-26 08:37:29 +00:00

fix locales bug

This commit is contained in:
Austin Huang 2021-01-13 11:16:34 -05:00
parent 3795ff2420
commit 87660b4d3b
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
2 changed files with 5 additions and 4 deletions

View File

@ -20,6 +20,7 @@ import androidx.appcompat.app.AppCompatActivity;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.Locale;
import javax.security.cert.CertificateException; import javax.security.cert.CertificateException;
import javax.security.cert.X509Certificate; import javax.security.cert.X509Certificate;
@ -102,10 +103,8 @@ public final class FlavorTown {
public static void changelogCheck(@NonNull final Context context) { public static void changelogCheck(@NonNull final Context context) {
if (settingsHelper.getInteger(Constants.PREV_INSTALL_VERSION) < BuildConfig.VERSION_CODE) { 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 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); settingsHelper.putString(Constants.APP_UA, appUa);
final int browserUaCode = settingsHelper.getInteger(Constants.BROWSER_UA_CODE); final int browserUaCode = settingsHelper.getInteger(Constants.BROWSER_UA_CODE);
final String browserUa = UserAgentUtils.generateBrowserUA(browserUaCode); final String browserUa = UserAgentUtils.generateBrowserUA(browserUaCode);

View File

@ -23,7 +23,7 @@ public final class LocaleUtils {
Utils.settingsHelper = new SettingsHelper(baseContext); Utils.settingsHelper = new SettingsHelper(baseContext);
final String appLanguageSettings = Utils.settingsHelper.getString(Constants.APP_LANGUAGE); 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 : currentLocale = TextUtils.isEmpty(lang) ? defaultLocale :
(lang.contains("_") ? new Locale(lang.split("_")[0], lang.split("_")[1]) : new Locale(lang)); (lang.contains("_") ? new Locale(lang.split("_")[0], lang.split("_")[1]) : new Locale(lang));
@ -54,6 +54,8 @@ public final class LocaleUtils {
@Nullable @Nullable
public static String getCorrespondingLanguageCode(final String appLanguageSettings) { public static String getCorrespondingLanguageCode(final String appLanguageSettings) {
if (TextUtils.isEmpty(appLanguageSettings)) return null;
final int appLanguageIndex = Integer.parseInt(appLanguageSettings); final int appLanguageIndex = Integer.parseInt(appLanguageSettings);
if (appLanguageIndex == 1) return "en"; if (appLanguageIndex == 1) return "en";
if (appLanguageIndex == 2) return "fr"; if (appLanguageIndex == 2) return "fr";