Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 20de1e32 authored by Calvin Pan's avatar Calvin Pan Committed by Automerger Merge Worker
Browse files

Merge "Add current system language into suggestion list" into tm-dev am: 895a7b66 am: 58c93e45

parents a003fff8 58c93e45
Loading
Loading
Loading
Loading
+17 −1
Original line number Diff line number Diff line
@@ -129,6 +129,12 @@ public class LocalePickerWithRegion extends ListFragment implements SearchView.O
        boolean isForCountryMode = parent != null;

        if (!TextUtils.isEmpty(appPackageName) && !isForCountryMode) {
            // Filter current system locale to add them into suggestion
            LocaleList systemLangList = LocaleList.getDefault();
            for(int i = 0; i < systemLangList.size(); i++) {
                langTagsToIgnore.add(systemLangList.get(i).toLanguageTag());
            }

            if (appCurrentLocale != null) {
                Log.d(TAG, "appCurrentLocale: " + appCurrentLocale.getLocale().toLanguageTag());
                langTagsToIgnore.add(appCurrentLocale.getLocale().toLanguageTag());
@@ -168,9 +174,20 @@ public class LocalePickerWithRegion extends ListFragment implements SearchView.O
                    result.mLocaleStatus == LocaleStatus.GET_SUPPORTED_LANGUAGE_FROM_LOCAL_CONFIG
                    || result.mLocaleStatus == LocaleStatus.GET_SUPPORTED_LANGUAGE_FROM_ASSET;

            // Add current system language into suggestion list
            for(LocaleStore.LocaleInfo localeInfo: LocaleStore.getSystemCurrentLocaleInfo()) {
                if (appCurrentLocale == null ||
                        !localeInfo.getLocale().equals(appCurrentLocale.getLocale())) {
                    mLocaleList.add(localeInfo);
                }
            }

            // Filter the language not support in app
            mLocaleList = filterTheLanguagesNotSupportedInApp(
                    shouldShowList, result.mAppSupportedLocales);

            Log.d(TAG, "mLocaleList after app-supported filter:  " + mLocaleList.size());

            // Add "system language"
            if (!isForCountryMode && shouldShowList) {
                mLocaleList.add(LocaleStore.getSystemDefaultLocaleInfo(appCurrentLocale == null));
@@ -190,7 +207,6 @@ public class LocalePickerWithRegion extends ListFragment implements SearchView.O
                    }
                }
            }
            Log.d(TAG, "mLocaleList after app-supported filter:  " + filteredList.size());
        }

        return filteredList;
+18 −0
Original line number Diff line number Diff line
@@ -25,9 +25,11 @@ import android.telephony.TelephonyManager;
import android.util.Log;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.IllformedLocaleException;
import java.util.List;
import java.util.Locale;
import java.util.Set;

@@ -277,6 +279,22 @@ public class LocaleStore {
        return null;
    }

    /**
     * Returns a list of system languages with LocaleInfo
     */
    public static List<LocaleInfo> getSystemCurrentLocaleInfo() {
        List<LocaleInfo> localeList = new ArrayList<>();

        LocaleList systemLangList = LocaleList.getDefault();
        for(int i = 0; i < systemLangList.size(); i++) {
            LocaleInfo systemLocaleInfo = new LocaleInfo(systemLangList.get(i));
            systemLocaleInfo.mSuggestionFlags |= LocaleInfo.SUGGESTION_TYPE_SIM;
            systemLocaleInfo.mIsTranslated = true;
            localeList.add(systemLocaleInfo);
        }
        return localeList;
    }

    /**
     * The "system default" is special case for per-app picker. Intentionally keep the locale
     * empty to let activity know "system default" been selected.