mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-18 05:39:53 +01:00
simplify
This commit is contained in:
@@ -21,18 +21,17 @@ public class Localizer {
|
|||||||
@Nullable
|
@Nullable
|
||||||
private static Localizer INSTANCE;
|
private static Localizer INSTANCE;
|
||||||
private final Locale systemLocale;
|
private final Locale systemLocale;
|
||||||
@Nullable
|
private final Locale locale;
|
||||||
private final Locale userLocale;
|
|
||||||
|
|
||||||
private Localizer(SharedPreferences sharedPreferences) {
|
private Localizer(SharedPreferences sharedPreferences) {
|
||||||
systemLocale = Locale.getDefault();
|
this(Locale.getDefault(), getLocaleFromTag(
|
||||||
userLocale = getLocaleFromTag(
|
sharedPreferences.getString(LANGUAGE, "default")));
|
||||||
sharedPreferences.getString(LANGUAGE, "default"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Localizer(Locale systemLocale, @Nullable Locale userLocale) {
|
private Localizer(Locale systemLocale, @Nullable Locale userLocale) {
|
||||||
this.systemLocale = systemLocale;
|
this.systemLocale = systemLocale;
|
||||||
this.userLocale = userLocale;
|
if (userLocale == null) locale = systemLocale;
|
||||||
|
else locale = userLocale;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Instantiate the Localizer.
|
// Instantiate the Localizer.
|
||||||
@@ -42,8 +41,9 @@ public class Localizer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Reinstantiate the Localizer with the system locale
|
// Reinstantiate the Localizer with the system locale
|
||||||
private static synchronized void reinitialize(Locale systemLocale) {
|
public static synchronized void reinitialize() {
|
||||||
INSTANCE = new Localizer(systemLocale, null);
|
if (INSTANCE != null)
|
||||||
|
INSTANCE = new Localizer(INSTANCE.systemLocale, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the current instance.
|
// Get the current instance.
|
||||||
@@ -53,11 +53,6 @@ public class Localizer {
|
|||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset to the system locale
|
|
||||||
public void reset() {
|
|
||||||
reinitialize(systemLocale);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get Locale from BCP-47 tag
|
// Get Locale from BCP-47 tag
|
||||||
@Nullable
|
@Nullable
|
||||||
public static Locale getLocaleFromTag(String tag) {
|
public static Locale getLocaleFromTag(String tag) {
|
||||||
@@ -77,18 +72,11 @@ public class Localizer {
|
|||||||
public Context setLocale(Context context) {
|
public Context setLocale(Context context) {
|
||||||
Resources res = context.getResources();
|
Resources res = context.getResources();
|
||||||
Configuration conf = res.getConfiguration();
|
Configuration conf = res.getConfiguration();
|
||||||
Locale locale, currentLocale;
|
Locale currentLocale;
|
||||||
if (SDK_INT >= 24) {
|
if (SDK_INT >= 24) {
|
||||||
currentLocale = conf.getLocales().get(0);
|
currentLocale = conf.getLocales().get(0);
|
||||||
} else
|
} else
|
||||||
currentLocale = conf.locale;
|
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))
|
if (locale.equals(currentLocale))
|
||||||
return context;
|
return context;
|
||||||
Locale.setDefault(locale);
|
Locale.setDefault(locale);
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ public class PasswordActivity extends BaseActivity {
|
|||||||
|
|
||||||
private void deleteAccount() {
|
private void deleteAccount() {
|
||||||
passwordController.deleteAccount(this);
|
passwordController.deleteAccount(this);
|
||||||
Localizer.getInstance().reset();
|
Localizer.reinitialize();
|
||||||
setResult(RESULT_CANCELED);
|
setResult(RESULT_CANCELED);
|
||||||
Intent i = new Intent(this, SetupActivity.class);
|
Intent i = new Intent(this, SetupActivity.class);
|
||||||
i.setFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK);
|
i.setFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK);
|
||||||
|
|||||||
Reference in New Issue
Block a user