Skip to content

Commit

Permalink
Revert "Apply preferred language on orientation change."
Browse files Browse the repository at this point in the history
This reverts commit 9ea3b66.
  • Loading branch information
tonyr59h committed Sep 1, 2015
1 parent 03cf11d commit 807ae24
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 50 deletions.
16 changes: 0 additions & 16 deletions WordPress/src/main/java/org/wordpress/android/WordPress.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
import org.wordpress.android.util.ProfilingUtils;
import org.wordpress.android.util.RateLimitedTask;
import org.wordpress.android.util.VolleyUtils;
import org.wordpress.android.util.WPActivityUtils;
import org.wordpress.passcodelock.AbstractAppLock;
import org.wordpress.passcodelock.AppLockManager;
import org.xmlrpc.android.ApiHelper;
Expand Down Expand Up @@ -682,10 +681,6 @@ private class ApplicationLifecycleMonitor implements Application.ActivityLifecyc
private Date mApplicationOpenedDate;
boolean isInBackground = true;

// To apply app language preference
private Class<?> mClass;
private int mOrientation = -1;

@Override
public void onConfigurationChanged(final Configuration newConfig) {
}
Expand Down Expand Up @@ -797,17 +792,6 @@ public void onFromBackground() {

@Override
public void onActivityResumed(Activity activity) {
// Need to track orientation to apply preferred language on rotation
int orientation = activity.getResources().getConfiguration().orientation;
boolean shouldRestart =
mOrientation == -1 || mOrientation != orientation || !mClass.equals(activity.getClass());

if (shouldRestart) {
mOrientation = orientation;
mClass = activity.getClass();
}
WPActivityUtils.applyLocale(activity, shouldRestart);

if (isInBackground) {
// was in background before
onFromBackground();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;
import android.preference.PreferenceManager;

import org.wordpress.android.R;
import org.wordpress.android.WordPress;
import org.wordpress.android.ui.main.WPMainActivity;
import org.wordpress.android.ui.prefs.SettingsFragment;
import org.wordpress.android.util.ToastUtils;

import java.util.Locale;

public class WPLaunchActivity extends Activity {

/*
Expand All @@ -21,6 +28,8 @@ public class WPLaunchActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

applyLocale();

if (WordPress.wpDB == null) {
ToastUtils.showToast(this, R.string.fatal_db_error, ToastUtils.Duration.LONG);
finish();
Expand All @@ -32,4 +41,23 @@ protected void onCreate(Bundle savedInstanceState) {
startActivity(intent);
finish();
}

private void applyLocale() {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

if (sharedPreferences.contains(SettingsFragment.SETTINGS_PREFERENCES)) {
String locale = sharedPreferences.getString(SettingsFragment.SETTINGS_PREFERENCES, "");

if (!locale.equals(Locale.getDefault().getDisplayLanguage())) {
Resources resources = getResources();
Configuration conf = resources.getConfiguration();
conf.locale = new Locale(locale);
resources.updateConfiguration(conf, resources.getDisplayMetrics());

Intent refresh = new Intent(this, WPLaunchActivity.class);
startActivity(refresh);
finish();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
@SuppressWarnings("deprecation")
public class SettingsFragment extends PreferenceFragment implements OnPreferenceClickListener {
public static final String SETTINGS_PREFERENCES = "settings-pref";
public static final String LANGUAGE_PREF_KEY = "language-pref";
public static final int LANGUAGE_CHANGED = 1000;

private AlertDialog mDialog;
Expand Down Expand Up @@ -238,7 +237,7 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
conf.locale = new Locale(localString);
}
res.updateConfiguration(conf, dm);
mSettings.edit().putString(LANGUAGE_PREF_KEY, localeMap.get(values[position])).apply();
mSettings.edit().putString(SETTINGS_PREFERENCES, localeMap.get(values[position])).apply();

// Track the change only if the user selected a non default Device language. This is only used in
// Mixpanel, because we have both the device language and app selected language data in Tracks
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,10 @@
package org.wordpress.android.util;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.preference.PreferenceManager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;

import org.wordpress.android.ui.prefs.SettingsFragment;

import java.util.Locale;

public class WPActivityUtils {
public static void applyLocale(Activity context, boolean restart) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);

if (sharedPreferences.contains(SettingsFragment.LANGUAGE_PREF_KEY)) {
String contextLocale = context.getResources().getConfiguration().locale.getLanguage();
String locale = sharedPreferences.getString(SettingsFragment.LANGUAGE_PREF_KEY, "");

if (!locale.equals(contextLocale)) {
Resources resources = context.getResources();
Configuration conf = resources.getConfiguration();
conf.locale = new Locale(locale);
resources.updateConfiguration(conf, resources.getDisplayMetrics());

if (restart) {
Intent refresh = new Intent(context, context.getClass());
context.startActivity(refresh);
context.finish();
context.overridePendingTransition(0, 0);
}
}
}
}

public static Context getThemedContext(Context context) {
if (context instanceof AppCompatActivity) {
Expand Down

0 comments on commit 807ae24

Please sign in to comment.