Small fixes
This commit is contained in:
parent
5861a2b017
commit
e1b7175919
3 changed files with 44 additions and 44 deletions
|
@ -514,7 +514,7 @@ public class AppInitializer implements IProgress {
|
|||
return null;
|
||||
}
|
||||
});
|
||||
app.regions.setLocale(app.getLanguage(), app.getCountry());
|
||||
app.regions.setLocale(app.getLanguage(), app.getLocaleHelper().getCountry());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -127,6 +127,7 @@ public class OsmandApplication extends MultiDexApplication {
|
|||
private final SQLiteAPI sqliteAPI = new SQLiteAPIImpl(this);
|
||||
private final OsmAndTaskManager taskManager = new OsmAndTaskManager(this);
|
||||
private final UiUtilities iconsCache = new UiUtilities(this);
|
||||
private final LocaleHelper localeHelper = new LocaleHelper(this);
|
||||
|
||||
// start variables
|
||||
ResourceManager resourceManager;
|
||||
|
@ -166,7 +167,6 @@ public class OsmandApplication extends MultiDexApplication {
|
|||
OprAuthHelper oprAuthHelper;
|
||||
MeasurementEditingContext measurementEditingContext;
|
||||
OnlineRoutingHelper onlineRoutingHelper;
|
||||
LocaleHelper localeHelper = new LocaleHelper(this);
|
||||
|
||||
private Map<String, Builder> customRoutingConfigs = new ConcurrentHashMap<>();
|
||||
private File externalStorageDirectory;
|
||||
|
@ -419,7 +419,7 @@ public class OsmandApplication extends MultiDexApplication {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
public void onConfigurationChanged(@NonNull Configuration newConfig) {
|
||||
Locale preferredLocale = localeHelper.getPreferredLocale();
|
||||
if (preferredLocale != null && !newConfig.locale.getLanguage().equals(preferredLocale.getLanguage())) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
|
@ -434,12 +434,10 @@ public class OsmandApplication extends MultiDexApplication {
|
|||
}
|
||||
}
|
||||
|
||||
public static final int PROGRESS_DIALOG = 5;
|
||||
|
||||
public void checkApplicationIsBeingInitialized(Activity activity, AppInitializeListener listener) {
|
||||
// start application if it was previously closed
|
||||
startApplication();
|
||||
if(listener != null) {
|
||||
if (listener != null) {
|
||||
appInitializer.addListener(listener);
|
||||
}
|
||||
}
|
||||
|
@ -812,29 +810,8 @@ public class OsmandApplication extends MultiDexApplication {
|
|||
return s;
|
||||
}
|
||||
|
||||
public String getCountry() {
|
||||
String country;
|
||||
Locale preferredLocale = localeHelper.getPreferredLocale();
|
||||
if (preferredLocale != null) {
|
||||
country = preferredLocale.getCountry();
|
||||
} else {
|
||||
country = Locale.getDefault().getCountry();
|
||||
}
|
||||
return country;
|
||||
}
|
||||
|
||||
public String getLanguage() {
|
||||
String lang;
|
||||
Locale preferredLocale = localeHelper.getPreferredLocale();
|
||||
if (preferredLocale != null) {
|
||||
lang = preferredLocale.getLanguage();
|
||||
} else {
|
||||
lang = Locale.getDefault().getLanguage();
|
||||
}
|
||||
if (lang != null && lang.length() > 3) {
|
||||
lang = lang.substring(0, 2).toLowerCase();
|
||||
}
|
||||
return lang;
|
||||
return localeHelper.getLanguage();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -12,14 +12,14 @@ import java.util.Locale;
|
|||
|
||||
public class LocaleHelper implements StateChangedListener<String> {
|
||||
|
||||
private Resources localizedResources;
|
||||
private Locale preferredLocale;
|
||||
private final OsmandApplication app;
|
||||
|
||||
private Locale defaultLocale;
|
||||
private Locale preferredLocale;
|
||||
private Resources localizedResources;
|
||||
|
||||
private boolean needRestart = false;
|
||||
|
||||
private OsmandApplication app;
|
||||
|
||||
public LocaleHelper(OsmandApplication app) {
|
||||
this.app = app;
|
||||
}
|
||||
|
@ -83,6 +83,18 @@ public class LocaleHelper implements StateChangedListener<String> {
|
|||
}
|
||||
}
|
||||
|
||||
public Resources getLocalizedResources() {
|
||||
return localizedResources;
|
||||
}
|
||||
|
||||
public Locale getPreferredLocale() {
|
||||
return preferredLocale;
|
||||
}
|
||||
|
||||
public Locale getDefaultLocale() {
|
||||
return defaultLocale;
|
||||
}
|
||||
|
||||
public void listenLocaleChanges() {
|
||||
app.getSettings().PREFERRED_LOCALE.addListener(this);
|
||||
}
|
||||
|
@ -99,21 +111,32 @@ public class LocaleHelper implements StateChangedListener<String> {
|
|||
this.needRestart = needRestart;
|
||||
}
|
||||
|
||||
public Resources getLocalizedResources() {
|
||||
return localizedResources;
|
||||
}
|
||||
|
||||
public Locale getPreferredLocale() {
|
||||
return preferredLocale;
|
||||
}
|
||||
|
||||
public Locale getDefaultLocale() {
|
||||
return defaultLocale;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stateChanged(String change) {
|
||||
needRestart = true;
|
||||
checkPreferredLocale();
|
||||
}
|
||||
|
||||
public String getCountry() {
|
||||
String country;
|
||||
if (preferredLocale != null) {
|
||||
country = preferredLocale.getCountry();
|
||||
} else {
|
||||
country = Locale.getDefault().getCountry();
|
||||
}
|
||||
return country;
|
||||
}
|
||||
|
||||
public String getLanguage() {
|
||||
String lang;
|
||||
if (preferredLocale != null) {
|
||||
lang = preferredLocale.getLanguage();
|
||||
} else {
|
||||
lang = Locale.getDefault().getLanguage();
|
||||
}
|
||||
if (lang != null && lang.length() > 3) {
|
||||
lang = lang.substring(0, 2).toLowerCase();
|
||||
}
|
||||
return lang;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue