From 7a2df3d6cb9f80f079447583e77758624d51a6df Mon Sep 17 00:00:00 2001
From: goapunk <goapunk@riseup.net>
Date: Wed, 13 Jun 2018 13:38:15 +0200
Subject: [PATCH] simplify

---
 .../briarproject/briar/android/Localizer.java | 30 ++++++-------------
 .../briar/android/login/PasswordActivity.java |  2 +-
 2 files changed, 10 insertions(+), 22 deletions(-)

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 93b27fa199..2b51659bb3 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 d7a2a88019..55f08b204b 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);
-- 
GitLab