Skip to content

Commit

Permalink
#101 improved behaviour of automatic language setting
Browse files Browse the repository at this point in the history
  • Loading branch information
bugy committed Apr 22, 2017
1 parent e289947 commit f462749
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
10 changes: 7 additions & 3 deletions shop-list/src/main/java/net/buggy/shoplist/ShopListActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,15 @@ protected void onPostExecute(Object o) {
protected void attachBaseContext(Context newContext) {
final Settings settings = getDataStorage().getSettings();
final Language language = settings.getLanguage();

final Locale locale;
if (language != null) {
Locale locale = new Locale(language.getLocale());
Locale.setDefault(locale);
newContext = ViewUtils.wrap(newContext, locale);
locale = new Locale(language.getLocale());
} else {
locale = ViewUtils.getSystemLocale();
}
Locale.setDefault(locale);
newContext = ViewUtils.wrap(newContext, locale);

super.attachBaseContext(CalligraphyContextWrapper.wrap(newContext));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public void renderTo(ViewGroup parentView, final ShopListActivity activity) {
languageField.setSelectedItem(settings.getLanguage());
languageField.setStringConverter(new LanguageEnumStringifier(activity));
languageField.setNullString(activity.getString(R.string.unit_settings_system_language));
languageField.setShowNullValue(true);


final FloatingActionButton applyButton = (FloatingActionButton) parentView.findViewById(
Expand Down
2 changes: 1 addition & 1 deletion shop-list/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
<string name="unit_edit_product_empty_name_not_allowed">Нужно указать название</string>
<string name="unit_settings_title">Настройки</string>
<string name="unit_settings_language_hint">Язык приложения</string>
<string name="unit_settings_system_language">Язык системы</string>
<string name="unit_settings_system_language">Автоматический</string>
<string name="material_spinner_default_null_string">Не указано</string>

<string name="default_product_apples">Яблоки</string>
Expand Down
2 changes: 1 addition & 1 deletion shop-list/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
<string name="language_en" translatable="false">English</string>
<string name="language_ru" translatable="false">Русский</string>
<string name="unit_settings_language_hint">App language</string>
<string name="unit_settings_system_language">System language</string>
<string name="unit_settings_system_language">Automatic</string>
<string name="material_spinner_default_null_string">None</string>

<string name="default_product_apples">Apples</string>
Expand Down

0 comments on commit f462749

Please sign in to comment.