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

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

Merge "Fix app language show "Und" when all languages in the suggestion list"...

Merge "Fix app language show "Und" when all languages in the suggestion list" into tm-dev am: 8848ca6f am: 62d3c470

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18570256



Change-Id: I3d0ecdeb5def98f3a4da1b1b54e62a2dcd0ee971
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 92f25749 62d3c470
Loading
Loading
Loading
Loading
+68 −25
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.android.internal.R;
@@ -104,6 +105,13 @@ public class SuggestedLocaleAdapter extends BaseAdapter implements Filterable {
    @Override
    public int getItemViewType(int position) {
        if (!showHeaders()) {
            LocaleStore.LocaleInfo item = (LocaleStore.LocaleInfo) getItem(position);
            if (item.isSystemLocale()) {
                return TYPE_SYSTEM_LANGUAGE_FOR_APP_LANGUAGE_PICKER;
            }
            if (item.isAppCurrentLocale()) {
                return TYPE_CURRENT_LOCALE;
            }
            return TYPE_LOCALE;
        } else {
            if (position == 0) {
@@ -193,15 +201,11 @@ public class SuggestedLocaleAdapter extends BaseAdapter implements Filterable {
        }

        int itemType = getItemViewType(position);
        View itemView = getNewViewIfNeeded(convertView, parent, itemType, position);
        switch (itemType) {
            case TYPE_HEADER_SUGGESTED: // intentional fallthrough
            case TYPE_HEADER_ALL_OTHERS:
                // Covers both null, and "reusing" a wrong kind of view
                if (!(convertView instanceof TextView)) {
                    convertView = mInflater.inflate(R.layout.language_picker_section_header,
                            parent, false);
                }
                TextView textView = (TextView) convertView;
                TextView textView = (TextView) itemView;
                if (itemType == TYPE_HEADER_SUGGESTED) {
                    setTextTo(textView, R.string.language_picker_section_suggested);
                } else {
@@ -215,38 +219,77 @@ public class SuggestedLocaleAdapter extends BaseAdapter implements Filterable {
                        mDisplayLocale != null ? mDisplayLocale : Locale.getDefault());
                break;
            case TYPE_SYSTEM_LANGUAGE_FOR_APP_LANGUAGE_PICKER:
                if (!(convertView instanceof ViewGroup)) {
                TextView title;
                if (((LocaleStore.LocaleInfo)getItem(position)).isAppCurrentLocale()) {
                        convertView = mInflater.inflate(
                                R.layout.app_language_picker_current_locale_item, parent, false);
                        title = convertView.findViewById(R.id.language_picker_item);
                    title = itemView.findViewById(R.id.language_picker_item);
                } else {
                    title = itemView.findViewById(R.id.locale);
                }
                title.setText(R.string.system_locale_title);
                break;
            case TYPE_CURRENT_LOCALE:
                updateTextView(itemView,
                        itemView.findViewById(R.id.language_picker_item), position);
                break;
            default:
                updateTextView(itemView, itemView.findViewById(R.id.locale), position);
                break;
        }
        return itemView;
    }

    /** Check if the old view can be reused, otherwise create a new one. */
    private View getNewViewIfNeeded(
            View convertView, ViewGroup parent, int itemType, int position) {
        View updatedView = convertView;
        boolean shouldReuseView;
        switch (itemType) {
            case TYPE_HEADER_SUGGESTED: // intentional fallthrough
            case TYPE_HEADER_ALL_OTHERS:
                shouldReuseView = convertView instanceof TextView
                        && convertView.findViewById(R.id.language_picker_header) != null;
                if (!shouldReuseView) {
                    updatedView = mInflater.inflate(
                            R.layout.language_picker_section_header, parent, false);
                }
                break;
            case TYPE_SYSTEM_LANGUAGE_FOR_APP_LANGUAGE_PICKER:
                if (((LocaleStore.LocaleInfo) getItem(position)).isAppCurrentLocale()) {
                    shouldReuseView = convertView instanceof LinearLayout
                            && convertView.findViewById(R.id.language_picker_item) != null;
                    if (!shouldReuseView) {
                        updatedView = mInflater.inflate(
                                R.layout.app_language_picker_current_locale_item,
                                parent, false);
                        addStateDescriptionIntoCurrentLocaleItem(convertView);
                    }
                } else {
                        convertView = mInflater.inflate(
                    shouldReuseView = convertView instanceof TextView
                            && convertView.findViewById(R.id.locale) != null;
                    if (!shouldReuseView) {
                        updatedView = mInflater.inflate(
                                R.layout.language_picker_item, parent, false);
                        title = convertView.findViewById(R.id.locale);
                    }
                    title.setText(R.string.system_locale_title);
                }
                break;
            case TYPE_CURRENT_LOCALE:
                if (!(convertView instanceof ViewGroup)) {
                    convertView = mInflater.inflate(
                shouldReuseView = convertView instanceof LinearLayout
                        && convertView.findViewById(R.id.language_picker_item) != null;
                if (!shouldReuseView) {
                    updatedView = mInflater.inflate(
                            R.layout.app_language_picker_current_locale_item, parent, false);
                    addStateDescriptionIntoCurrentLocaleItem(convertView);
                }
                updateTextView(
                        convertView, convertView.findViewById(R.id.language_picker_item), position);
                break;
            default:
                // Covers both null, and "reusing" a wrong kind of view
                if (!(convertView instanceof ViewGroup)) {
                    convertView = mInflater.inflate(R.layout.language_picker_item, parent, false);
                shouldReuseView = convertView instanceof TextView
                        && convertView.findViewById(R.id.locale) != null;
                if (!shouldReuseView) {
                    updatedView = mInflater.inflate(R.layout.language_picker_item, parent, false);
                }
                updateTextView(convertView, convertView.findViewById(R.id.locale), position);
                break;
        }
        return convertView;
        return updatedView;
    }

    private boolean showHeaders() {
+1 −0
Original line number Diff line number Diff line
@@ -24,4 +24,5 @@
          android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
          android:textColor="?android:attr/colorAccent"
          android:textStyle="bold"
          android:id="@+id/language_picker_header"
          tools:text="@string/language_picker_section_all"/>
+1 −0
Original line number Diff line number Diff line
@@ -4796,6 +4796,7 @@
  <java-symbol type="layout" name="app_language_picker_current_locale_item" />
  <java-symbol type="id" name="system_locale_subtitle" />
  <java-symbol type="id" name="language_picker_item" />
  <java-symbol type="id" name="language_picker_header" />

  <java-symbol type="dimen" name="status_bar_height_default" />
</resources>