diff --git a/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/SettingsFragment.java b/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/SettingsFragment.java index a02aaa65..10f5d5a9 100644 --- a/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/SettingsFragment.java +++ b/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/SettingsFragment.java @@ -201,12 +201,22 @@ public class SettingsFragment extends PreferenceFragmentCompat { localePref.setEntries(entries); localePref.setEntryValues(entryValues); - localePref.setDefaultValue(entryValues[0]); - localePref.setSummary(Locale.forLanguageTag(localePref.getValue()).getDisplayLanguage()); + String value = localePref.getValue(); + if ("default".equals(value)) { + localePref.setSummary(requireContext().getString(R.string.settings_system_language)); + } else { + localePref.setSummary(Locale.forLanguageTag(value).getDisplayName()); + } localePref.setOnPreferenceChangeListener((preference, newValue) -> { - LocaleListCompat appLocale = LocaleListCompat.forLanguageTags((String) newValue); - AppCompatDelegate.setApplicationLocales(appLocale); + if ("default".equals(newValue)) { + AppCompatDelegate.setApplicationLocales(LocaleListCompat.getEmptyLocaleList()); + preference.setSummary(requireContext().getString(R.string.settings_system_language)); + } else { + LocaleListCompat appLocale = LocaleListCompat.forLanguageTags((String) newValue); + AppCompatDelegate.setApplicationLocales(appLocale); + preference.setSummary(Locale.forLanguageTag((String) newValue).getDisplayName()); + } return true; }); } diff --git a/app/src/main/java/com/cappielloantonio/tempo/util/UIUtil.java b/app/src/main/java/com/cappielloantonio/tempo/util/UIUtil.java index bbbdf988..f9b7fdba 100644 --- a/app/src/main/java/com/cappielloantonio/tempo/util/UIUtil.java +++ b/app/src/main/java/com/cappielloantonio/tempo/util/UIUtil.java @@ -8,6 +8,7 @@ import android.graphics.drawable.InsetDrawable; import androidx.core.os.LocaleListCompat; import androidx.recyclerview.widget.DividerItemDecoration; +import com.cappielloantonio.tempo.App; import com.cappielloantonio.tempo.R; import org.xmlpull.v1.XmlPullParser; @@ -15,9 +16,10 @@ import org.xmlpull.v1.XmlPullParserException; import java.io.IOException; import java.text.SimpleDateFormat; +import java.util.AbstractMap; import java.util.ArrayList; import java.util.Date; -import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; import java.util.Map; @@ -74,17 +76,32 @@ public class UIUtil { public static Map getLangPreferenceDropdownEntries(Context context) { LocaleListCompat localeList = getLocalesFromResources(context); - Map map = new HashMap<>(); + List> localeArrayList = new ArrayList<>(); + + String systemDefaultLabel = App.getContext().getString(R.string.settings_system_language); + String systemDefaultValue = "default"; for (int i = 0; i < localeList.size(); i++) { Locale locale = localeList.get(i); - if (locale != null) { - map.put(Util.toPascalCase(locale.getDisplayName()), locale.toLanguageTag()); + localeArrayList.add( + new AbstractMap.SimpleEntry<>( + Util.toPascalCase(locale.getDisplayName()), + locale.toLanguageTag() + ) + ); } } - return map; + localeArrayList.sort(Map.Entry.comparingByKey(String.CASE_INSENSITIVE_ORDER)); + + LinkedHashMap orderedMap = new LinkedHashMap<>(); + orderedMap.put(systemDefaultLabel, systemDefaultValue); + for (Map.Entry entry : localeArrayList) { + orderedMap.put(entry.getKey(), entry.getValue()); + } + + return orderedMap; } public static String getReadableDate(Date date) { diff --git a/app/src/main/res/values-es-rES/strings.xml b/app/src/main/res/values-es-rES/strings.xml index 34196d8c..8273df89 100644 --- a/app/src/main/res/values-es-rES/strings.xml +++ b/app/src/main/res/values-es-rES/strings.xml @@ -164,6 +164,7 @@ Artista Resolución de la imagen Idioma + Idioma del sistema Cerrar sesión https://github.com/eddyizm/tempo Siga el desarrollo diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a05234fb..64c71b68 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -319,6 +319,7 @@ If enabled, sets a curvature angle for all rendered covers. The changes will take effect on restart. Scan library Enable music scrobbling + System language Enable music sharing Size of streaming cache Streaming cache storage