diff --git a/briar-android/src/main/java/org/briarproject/briar/android/Localizer.java b/briar-android/src/main/java/org/briarproject/briar/android/Localizer.java index 93b27fa199ea08ef68b4f8c99fb7a0e60f9f9608..2b51659bb314900a00188048af6ab9beac8ef530 100644 --- a/briar-android/src/main/java/org/briarproject/briar/android/Localizer.java +++ b/briar-android/src/main/java/org/briarproject/briar/android/Localizer.java @@ -21,18 +21,17 @@ public class Localizer { @Nullable private static Localizer INSTANCE; private final Locale systemLocale; - @Nullable - private final Locale userLocale; + private final Locale locale; private Localizer(SharedPreferences sharedPreferences) { - systemLocale = Locale.getDefault(); - userLocale = getLocaleFromTag( - sharedPreferences.getString(LANGUAGE, "default")); + this(Locale.getDefault(), getLocaleFromTag( + sharedPreferences.getString(LANGUAGE, "default"))); } private Localizer(Locale systemLocale, @Nullable Locale userLocale) { this.systemLocale = systemLocale; - this.userLocale = userLocale; + if (userLocale == null) locale = systemLocale; + else locale = userLocale; } // Instantiate the Localizer. @@ -42,8 +41,9 @@ public class Localizer { } // Reinstantiate the Localizer with the system locale - private static synchronized void reinitialize(Locale systemLocale) { - INSTANCE = new Localizer(systemLocale, null); + public static synchronized void reinitialize() { + if (INSTANCE != null) + INSTANCE = new Localizer(INSTANCE.systemLocale, null); } // Get the current instance. @@ -53,11 +53,6 @@ public class Localizer { return INSTANCE; } - // Reset to the system locale - public void reset() { - reinitialize(systemLocale); - } - // Get Locale from BCP-47 tag @Nullable public static Locale getLocaleFromTag(String tag) { @@ -77,18 +72,11 @@ public class Localizer { public Context setLocale(Context context) { Resources res = context.getResources(); Configuration conf = res.getConfiguration(); - Locale locale, currentLocale; + Locale currentLocale; if (SDK_INT >= 24) { currentLocale = conf.getLocales().get(0); } else currentLocale = conf.locale; - if (userLocale == null) { - // Detect if the user changed the system language - if (systemLocale.equals(currentLocale)) - return context; - locale = systemLocale; - } else - locale = userLocale; if (locale.equals(currentLocale)) return context; Locale.setDefault(locale); diff --git a/briar-android/src/main/java/org/briarproject/briar/android/login/PasswordActivity.java b/briar-android/src/main/java/org/briarproject/briar/android/login/PasswordActivity.java index d7a2a88019bbf21c9d04681d35d3082ea41590dc..55f08b204b584e8bd573acce1ae6363bd14368c2 100644 --- a/briar-android/src/main/java/org/briarproject/briar/android/login/PasswordActivity.java +++ b/briar-android/src/main/java/org/briarproject/briar/android/login/PasswordActivity.java @@ -106,7 +106,7 @@ public class PasswordActivity extends BaseActivity { private void deleteAccount() { passwordController.deleteAccount(this); - Localizer.getInstance().reset(); + Localizer.reinitialize(); setResult(RESULT_CANCELED); Intent i = new Intent(this, SetupActivity.class); i.setFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK);