Fix locale NPE

pull/437/head
Alex Baker 8 years ago
parent 996777951e
commit 26798762f5

@ -35,7 +35,7 @@ public class MultilineListPreference extends ListPreference {
@Override
protected void showDialog(Bundle state) {
super.showDialog(state);
Locale.INSTANCE.applyDirectionality(getDialog());
Locale.getInstance(getContext()).applyDirectionality(getDialog());
}
@Override

@ -30,7 +30,7 @@ public class ApplicationModule {
@Provides
public Locale getLocale() {
return Locale.INSTANCE;
return Locale.getInstance(context);
}
@Provides

@ -14,7 +14,7 @@ public abstract class InjectingAppCompatActivity extends AppCompatActivity imple
@Inject Tracker tracker;
public InjectingAppCompatActivity() {
Locale.INSTANCE.applyOverrideConfiguration(this);
Locale.getInstance(this).applyOverrideConfiguration(this);
}
@Override

@ -1,11 +1,8 @@
package org.tasks.injection;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.support.multidex.MultiDexApplication;
import org.tasks.R;
import org.tasks.locale.Locale;
public abstract class InjectingApplication extends MultiDexApplication {
@ -16,12 +13,7 @@ public abstract class InjectingApplication extends MultiDexApplication {
public void onCreate() {
super.onCreate();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
String language = prefs.getString(getString(R.string.p_language), null);
int directionOverride = Integer.parseInt(prefs.getString(getString(R.string.p_layout_direction), "-1"));
Locale.INSTANCE = new Locale(java.util.Locale.getDefault(), language, directionOverride);
java.util.Locale.setDefault(Locale.INSTANCE.getLocale());
Context context = Locale.INSTANCE.createConfigurationContext(getApplicationContext());
Context context = Locale.getInstance(this).createConfigurationContext(getApplicationContext());
applicationComponent = DaggerApplicationComponent.builder()
.applicationModule(new ApplicationModule(context))

@ -32,7 +32,7 @@ public abstract class InjectingPreferenceActivity extends AppCompatPreferenceAct
@Inject Tracker tracker;
public InjectingPreferenceActivity() {
Locale.INSTANCE.applyOverrideConfiguration(this);
Locale.getInstance(this).applyOverrideConfiguration(this);
}
@Override

@ -16,7 +16,7 @@ public abstract class ThemedInjectingAppCompatActivity extends AppCompatActivity
@Inject Theme theme;
public ThemedInjectingAppCompatActivity() {
Locale.INSTANCE.applyOverrideConfiguration(this);
Locale.getInstance(this).applyOverrideConfiguration(this);
}
@Override

@ -2,7 +2,9 @@ package org.tasks.locale;
import android.app.Dialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.preference.PreferenceManager;
import android.support.v4.text.TextUtilsCompat;
import android.view.ContextThemeWrapper;
import android.view.View;
@ -10,11 +12,30 @@ import android.view.ViewParent;
import com.google.common.base.Strings;
import org.tasks.R;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastJellybeanMR1;
public class Locale {
public static Locale INSTANCE;
private static Locale DEFAULT = new Locale(java.util.Locale.getDefault(), null, -1);
private static Locale INSTANCE;
public static Locale getInstance(Context context) {
if (INSTANCE == null) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
String language = prefs.getString(context.getString(R.string.p_language), null);
int directionOverride = Integer.parseInt(prefs.getString(context.getString(R.string.p_layout_direction), "-1"));
INSTANCE = new Locale(DEFAULT.getLocale(), language, directionOverride);
java.util.Locale.setDefault(INSTANCE.getLocale());
}
return getInstance();
}
public static Locale getInstance() {
return INSTANCE == null ? DEFAULT : INSTANCE;
}
private static final int[] sDialogButtons = new int[] { android.R.id.button1, android.R.id.button2, android.R.id.button3 };
private static final char LEFT_TO_RIGHT_MARK = '\u200e';

@ -275,7 +275,7 @@ public class DateTime {
public String toString(String format) {
Calendar calendar = getCalendar();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format, Locale.INSTANCE.getLocale());
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format, Locale.getInstance().getLocale());
simpleDateFormat.setCalendar(calendar);
return simpleDateFormat.format(calendar.getTime());
}

@ -176,7 +176,7 @@ public class ScrollableViewsFactory implements RemoteViewsService.RemoteViewsFac
}
if (atLeastJellybeanMR1()) {
row.setInt(R.id.widget_row, "setLayoutDirection", Locale.INSTANCE.getDirectionality());
row.setInt(R.id.widget_row, "setLayoutDirection", Locale.getInstance(context).getDirectionality());
}
return row;
@ -211,7 +211,7 @@ public class ScrollableViewsFactory implements RemoteViewsService.RemoteViewsFac
RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.scrollable_widget);
rv.setTextViewText(R.id.widget_title, filter.listingTitle);
if (atLeastJellybeanMR1()) {
rv.setInt(R.id.widget, "setLayoutDirection", Locale.INSTANCE.getDirectionality());
rv.setInt(R.id.widget, "setLayoutDirection", Locale.getInstance(context).getDirectionality());
}
appWidgetManager.partiallyUpdateAppWidget(widgetId, rv);
String query = SortHelper.adjustQueryForFlagsAndSort(preferences, filter.getSqlQuery(), sort).replaceAll("LIMIT \\d+", "");

Loading…
Cancel
Save