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

Commit 44080ac5 authored by Mihai Nita's avatar Mihai Nita Committed by android-build-merger
Browse files

Merge \"Fix for NullPointerException in SuggestedLocaleAdapter\" into nyc-dev

am: c8c9afea

Change-Id: Iaa4df1af4a18ad0bc4e99a5bd47aa8f6c1357e50
parents c5ffdb9e c8c9afea
Loading
Loading
Loading
Loading
+16 −4
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import java.util.Set;
 * default locale.</p>
 */
public class LocalePickerWithRegion extends ListFragment implements SearchView.OnQueryTextListener {
    private static final String PARENT_FRAGMENT_NAME = "localeListEditor";

    private SuggestedLocaleAdapter mAdapter;
    private LocaleSelectedListener mListener;
@@ -130,11 +131,24 @@ public class LocalePickerWithRegion extends ListFragment implements SearchView.O
        return true;
    }

    private void returnToParentFrame() {
        getFragmentManager().popBackStack(PARENT_FRAGMENT_NAME,
                FragmentManager.POP_BACK_STACK_INCLUSIVE);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setHasOptionsMenu(true);

        if (mLocaleList == null) {
            // The fragment was killed and restored by the FragmentManager.
            // At this point we have no data, no listener. Just return, to prevend a NPE.
            // Fixes b/28748150. Created b/29400003 for a cleaner solution.
            returnToParentFrame();
            return;
        }

        final boolean countryMode = mParentLocale != null;
        final Locale sortingLocale = countryMode ? mParentLocale.getLocale() : Locale.getDefault();
        mAdapter = new SuggestedLocaleAdapter(mLocaleList, countryMode);
@@ -197,8 +211,7 @@ public class LocalePickerWithRegion extends ListFragment implements SearchView.O
            if (mListener != null) {
                mListener.onLocaleSelected(locale);
            }
            getFragmentManager().popBackStack("localeListEditor",
                    FragmentManager.POP_BACK_STACK_INCLUSIVE);
            returnToParentFrame();
        } else {
            LocalePickerWithRegion selector = LocalePickerWithRegion.createCountryPicker(
                    getContext(), mListener, locale, mTranslatedOnly /* translate only */);
@@ -208,8 +221,7 @@ public class LocalePickerWithRegion extends ListFragment implements SearchView.O
                        .replace(getId(), selector).addToBackStack(null)
                        .commit();
            } else {
                getFragmentManager().popBackStack("localeListEditor",
                        FragmentManager.POP_BACK_STACK_INCLUSIVE);
                returnToParentFrame();
            }
        }
    }