mirror of
https://github.com/M66B/FairEmail.git
synced 2026-01-03 19:34:15 +01:00
Added advanced option to force English language
This commit is contained in:
@@ -20,6 +20,7 @@ package eu.faircode.email;
|
||||
*/
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
@@ -38,6 +39,11 @@ import androidx.preference.PreferenceManager;
|
||||
abstract class ActivityBase extends AppCompatActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
private boolean contacts;
|
||||
|
||||
@Override
|
||||
protected void attachBaseContext(Context base) {
|
||||
super.attachBaseContext(ApplicationEx.getLocalizedContext(base));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
Log.i("Create " + this.getClass().getName() + " version=" + BuildConfig.VERSION_NAME);
|
||||
|
||||
@@ -25,12 +25,15 @@ import android.app.NotificationChannel;
|
||||
import android.app.NotificationChannelGroup;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.media.Ringtone;
|
||||
import android.media.RingtoneManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.DeadSystemException;
|
||||
import android.os.RemoteException;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.webkit.CookieManager;
|
||||
|
||||
import org.json.JSONArray;
|
||||
@@ -44,6 +47,7 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import androidx.annotation.RequiresApi;
|
||||
|
||||
@@ -54,6 +58,11 @@ public class ApplicationEx extends Application {
|
||||
"service", "notification", "warning", "error"
|
||||
));
|
||||
|
||||
@Override
|
||||
protected void attachBaseContext(Context base) {
|
||||
super.attachBaseContext(getLocalizedContext(base));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
@@ -86,6 +95,18 @@ public class ApplicationEx extends Application {
|
||||
Core.init(this);
|
||||
}
|
||||
|
||||
static Context getLocalizedContext(Context context) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
boolean english = prefs.getBoolean("english", false);
|
||||
|
||||
if (english) {
|
||||
Configuration config = new Configuration(context.getResources().getConfiguration());
|
||||
config.setLocale(Locale.US);
|
||||
return context.createConfigurationContext(config);
|
||||
} else
|
||||
return context;
|
||||
}
|
||||
|
||||
private void createNotificationChannels() {
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
||||
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
|
||||
@@ -105,6 +105,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
|
||||
private SwitchCompat swLight;
|
||||
private Button btnSound;
|
||||
|
||||
private SwitchCompat swEnglish;
|
||||
private SwitchCompat swUpdates;
|
||||
private SwitchCompat swDebug;
|
||||
|
||||
@@ -182,6 +183,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
|
||||
swLight = view.findViewById(R.id.swLight);
|
||||
btnSound = view.findViewById(R.id.btnSound);
|
||||
|
||||
swEnglish = view.findViewById(R.id.swEnglish);
|
||||
swUpdates = view.findViewById(R.id.swUpdates);
|
||||
swDebug = view.findViewById(R.id.swDebug);
|
||||
|
||||
@@ -247,6 +249,18 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
|
||||
}
|
||||
});
|
||||
|
||||
swEnglish.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||
prefs.edit().putBoolean("english", checked).commit(); // apply won't work here
|
||||
|
||||
Intent intent = new Intent(getContext(), ActivityMain.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
startActivity(intent);
|
||||
Runtime.getRuntime().exit(0);
|
||||
}
|
||||
});
|
||||
|
||||
swUpdates.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||
@@ -634,6 +648,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
|
||||
swNotifyPreview.setEnabled(Helper.isPro(getContext()));
|
||||
swSearchLocal.setChecked(prefs.getBoolean("search_local", false));
|
||||
swLight.setChecked(prefs.getBoolean("light", false));
|
||||
swEnglish.setChecked(prefs.getBoolean("english", false));
|
||||
swUpdates.setChecked(prefs.getBoolean("updates", true));
|
||||
swUpdates.setVisibility(Helper.isPlayStoreInstall(getContext()) ? View.GONE : View.VISIBLE);
|
||||
swDebug.setChecked(prefs.getBoolean("debug", false));
|
||||
|
||||
Reference in New Issue
Block a user