mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
Merge pull request #26 from jaime-grj/fix-languageselection
fix: show "System default" language option, sort languages alphabetically, include country when showing language in settings
This commit is contained in:
commit
04580e380b
4 changed files with 38 additions and 9 deletions
|
|
@ -201,12 +201,22 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
||||||
localePref.setEntries(entries);
|
localePref.setEntries(entries);
|
||||||
localePref.setEntryValues(entryValues);
|
localePref.setEntryValues(entryValues);
|
||||||
|
|
||||||
localePref.setDefaultValue(entryValues[0]);
|
String value = localePref.getValue();
|
||||||
localePref.setSummary(Locale.forLanguageTag(localePref.getValue()).getDisplayLanguage());
|
if ("default".equals(value)) {
|
||||||
|
localePref.setSummary(requireContext().getString(R.string.settings_system_language));
|
||||||
|
} else {
|
||||||
|
localePref.setSummary(Locale.forLanguageTag(value).getDisplayName());
|
||||||
|
}
|
||||||
|
|
||||||
localePref.setOnPreferenceChangeListener((preference, newValue) -> {
|
localePref.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||||
LocaleListCompat appLocale = LocaleListCompat.forLanguageTags((String) newValue);
|
if ("default".equals(newValue)) {
|
||||||
AppCompatDelegate.setApplicationLocales(appLocale);
|
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;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import android.graphics.drawable.InsetDrawable;
|
||||||
import androidx.core.os.LocaleListCompat;
|
import androidx.core.os.LocaleListCompat;
|
||||||
import androidx.recyclerview.widget.DividerItemDecoration;
|
import androidx.recyclerview.widget.DividerItemDecoration;
|
||||||
|
|
||||||
|
import com.cappielloantonio.tempo.App;
|
||||||
import com.cappielloantonio.tempo.R;
|
import com.cappielloantonio.tempo.R;
|
||||||
|
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
|
|
@ -15,9 +16,10 @@ import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.AbstractMap;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -74,17 +76,32 @@ public class UIUtil {
|
||||||
public static Map<String, String> getLangPreferenceDropdownEntries(Context context) {
|
public static Map<String, String> getLangPreferenceDropdownEntries(Context context) {
|
||||||
LocaleListCompat localeList = getLocalesFromResources(context);
|
LocaleListCompat localeList = getLocalesFromResources(context);
|
||||||
|
|
||||||
Map<String, String> map = new HashMap<>();
|
List<Map.Entry<String, String>> localeArrayList = new ArrayList<>();
|
||||||
|
|
||||||
|
String systemDefaultLabel = App.getContext().getString(R.string.settings_system_language);
|
||||||
|
String systemDefaultValue = "default";
|
||||||
|
|
||||||
for (int i = 0; i < localeList.size(); i++) {
|
for (int i = 0; i < localeList.size(); i++) {
|
||||||
Locale locale = localeList.get(i);
|
Locale locale = localeList.get(i);
|
||||||
|
|
||||||
if (locale != null) {
|
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<String, String> orderedMap = new LinkedHashMap<>();
|
||||||
|
orderedMap.put(systemDefaultLabel, systemDefaultValue);
|
||||||
|
for (Map.Entry<String, String> entry : localeArrayList) {
|
||||||
|
orderedMap.put(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
return orderedMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getReadableDate(Date date) {
|
public static String getReadableDate(Date date) {
|
||||||
|
|
|
||||||
|
|
@ -164,6 +164,7 @@
|
||||||
<string name="menu_group_by_artist">Artista</string>
|
<string name="menu_group_by_artist">Artista</string>
|
||||||
<string name="settings_image_size">Resolución de la imagen</string>
|
<string name="settings_image_size">Resolución de la imagen</string>
|
||||||
<string name="settings_language">Idioma</string>
|
<string name="settings_language">Idioma</string>
|
||||||
|
<string name="settings_system_language">Idioma del sistema</string>
|
||||||
<string name="settings_logout_title">Cerrar sesión</string>
|
<string name="settings_logout_title">Cerrar sesión</string>
|
||||||
<string name="settings_github_link">https://github.com/eddyizm/tempo</string>
|
<string name="settings_github_link">https://github.com/eddyizm/tempo</string>
|
||||||
<string name="settings_github_summary">Siga el desarrollo</string>
|
<string name="settings_github_summary">Siga el desarrollo</string>
|
||||||
|
|
|
||||||
|
|
@ -319,6 +319,7 @@
|
||||||
<string name="settings_rounded_corner_summary">If enabled, sets a curvature angle for all rendered covers. The changes will take effect on restart.</string>
|
<string name="settings_rounded_corner_summary">If enabled, sets a curvature angle for all rendered covers. The changes will take effect on restart.</string>
|
||||||
<string name="settings_scan_title">Scan library</string>
|
<string name="settings_scan_title">Scan library</string>
|
||||||
<string name="settings_scrobble_title">Enable music scrobbling</string>
|
<string name="settings_scrobble_title">Enable music scrobbling</string>
|
||||||
|
<string name="settings_system_language">System language</string>
|
||||||
<string name="settings_share_title">Enable music sharing</string>
|
<string name="settings_share_title">Enable music sharing</string>
|
||||||
<string name="settings_streaming_cache_size">Size of streaming cache</string>
|
<string name="settings_streaming_cache_size">Size of streaming cache</string>
|
||||||
<string name="settings_streaming_cache_storage_title">Streaming cache storage</string>
|
<string name="settings_streaming_cache_storage_title">Streaming cache storage</string>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue