mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-19 04:53:36 +00:00
[android] Improve map language settings
Signed-off-by: gekeleda <git@davidgekeler.eu> Co-authored-by: gekeleda <git@davidgekeler.eu> Co-committed-by: gekeleda <git@davidgekeler.eu>
This commit is contained in:
@@ -1,7 +1,10 @@
|
|||||||
package app.organicmaps.editor;
|
package app.organicmaps.editor;
|
||||||
|
|
||||||
|
import android.content.res.Configuration;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.core.os.ConfigurationCompat;
|
||||||
|
import androidx.core.os.LocaleListCompat;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import app.organicmaps.base.BaseMwmRecyclerFragment;
|
import app.organicmaps.base.BaseMwmRecyclerFragment;
|
||||||
import app.organicmaps.sdk.editor.Editor;
|
import app.organicmaps.sdk.editor.Editor;
|
||||||
@@ -11,6 +14,7 @@ import java.util.Collections;
|
|||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class LanguagesFragment extends BaseMwmRecyclerFragment<LanguagesAdapter>
|
public class LanguagesFragment extends BaseMwmRecyclerFragment<LanguagesAdapter>
|
||||||
@@ -32,10 +36,23 @@ public class LanguagesFragment extends BaseMwmRecyclerFragment<LanguagesAdapter>
|
|||||||
Set<String> existingLanguages =
|
Set<String> existingLanguages =
|
||||||
args != null ? new HashSet<>(args.getStringArrayList(EXISTING_LOCALIZED_NAMES)) : new HashSet<>();
|
args != null ? new HashSet<>(args.getStringArrayList(EXISTING_LOCALIZED_NAMES)) : new HashSet<>();
|
||||||
|
|
||||||
|
Configuration config = requireContext().getResources().getConfiguration();
|
||||||
|
LocaleListCompat systemLocales = ConfigurationCompat.getLocales(config);
|
||||||
|
|
||||||
List<Language> languages = new ArrayList<>();
|
List<Language> languages = new ArrayList<>();
|
||||||
|
List<Language> systemLanguages = new ArrayList<>();
|
||||||
|
|
||||||
for (Language lang : Editor.nativeGetSupportedLanguages(false))
|
for (Language lang : Editor.nativeGetSupportedLanguages(false))
|
||||||
{
|
{
|
||||||
if (existingLanguages.contains(lang.code))
|
// Separately extract system languages
|
||||||
|
for (int i = 0; i < systemLocales.size(); i++)
|
||||||
|
{
|
||||||
|
Locale locale = systemLocales.get(i);
|
||||||
|
if (locale != null && locale.getLanguage().equals(lang.code))
|
||||||
|
systemLanguages.add(lang);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (existingLanguages.contains(lang.code) || systemLanguages.contains(lang))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
languages.add(lang);
|
languages.add(lang);
|
||||||
@@ -43,6 +60,8 @@ public class LanguagesFragment extends BaseMwmRecyclerFragment<LanguagesAdapter>
|
|||||||
|
|
||||||
Collections.sort(languages, Comparator.comparing(lhs -> lhs.name));
|
Collections.sort(languages, Comparator.comparing(lhs -> lhs.name));
|
||||||
|
|
||||||
|
languages.addAll(0, systemLanguages);
|
||||||
|
|
||||||
return new LanguagesAdapter(this, languages.toArray(new Language[languages.size()]));
|
return new LanguagesAdapter(this, languages.toArray(new Language[languages.size()]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user