Browse Source

fix locales bug

renovate/org.robolectric-robolectric-4.x
Austin Huang 4 years ago
parent
commit
87660b4d3b
No known key found for this signature in database GPG Key ID: 84C23AA04587A91F
  1. 5
      app/src/main/java/awais/instagrabber/utils/FlavorTown.java
  2. 4
      app/src/main/java/awais/instagrabber/utils/LocaleUtils.java

5
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.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);

4
app/src/main/java/awais/instagrabber/utils/LocaleUtils.java

@ -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";

Loading…
Cancel
Save