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

Commit 225beade authored by Zoey Chen's avatar Zoey Chen Committed by Android (Google) Code Review
Browse files

Merge "[Settings] Change the title of the dialog when user delete the system laguage" into main

parents 7fdf11da de399bbf
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -631,9 +631,11 @@
        =1      {Remove selected language?}
        other   {Remove selected languages?}
        }</string>
    <!-- The title of the confirmation dialog shown when the user selects system languages and tries to remove it [CHAR LIMIT=60] -->
    <string name="dlg_remove_system_locales_title">Change system language to %s?</string>
    <!-- The text of the confirmation dialog shown when the user selects several languages and tries to remove them [CHAR LIMIT=NONE] -->
    <string name="dlg_remove_locales_message">Text will be displayed in another language.</string>
    <string name="dlg_remove_locales_message"><xliff:g id="Language" example="English (United States)">%s</xliff:g> will be removed from your preferred languages</string>
    <!-- The title of the error dialog shown when the user selects all the languages and tries to remove them [CHAR LIMIT=60] -->
    <string name="dlg_remove_locales_error_title">Can’t remove all languages</string>
+8 −3
Original line number Diff line number Diff line
@@ -395,13 +395,18 @@ public class LocaleListEditor extends RestrictedSettingsFragment implements View
            return;
        }

        final String title = StringUtil.getIcuPluralsString(getContext(), checkedCount,
        String title = StringUtil.getIcuPluralsString(getContext(), checkedCount,
                R.string.dlg_remove_locales_title);
        int buttonResId = R.string.locale_remove_menu;
        mShowingRemoveDialog = true;

        final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        if (mAdapter.isFirstLocaleChecked()) {
            builder.setMessage(R.string.dlg_remove_locales_message);
            title = getContext().getString(R.string.dlg_remove_system_locales_title,
                    mAdapter.getFeedItemList().get(1).getFullNameNative());
            builder.setMessage(getContext().getString(R.string.dlg_remove_locales_message,
                            mAdapter.getFeedItemList().get(0).getFullNameNative()));
            buttonResId = R.string.button_label_confirmation_of_system_locale_change;
        }

        builder.setTitle(title)
@@ -411,7 +416,7 @@ public class LocaleListEditor extends RestrictedSettingsFragment implements View
                        setRemoveMode(false);
                    }
                })
                .setPositiveButton(R.string.locale_remove_menu,
                .setPositiveButton(buttonResId,
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(@NonNull DialogInterface dialog, int which) {
+3 −35
Original line number Diff line number Diff line
@@ -233,6 +233,7 @@ public class LocaleListEditorTest {
    @Test
    public void showRemoveLocaleWarningDialog_mainLocaleSelected_shouldShowLocaleChangeDialog() {
        //pre-condition
        setUpLocaleConditions2();
        when(mAdapter.getCheckedCount()).thenReturn(1);
        when(mAdapter.getItemCount()).thenReturn(2);
        when(mAdapter.isFirstLocaleChecked()).thenReturn(true);
@@ -249,7 +250,7 @@ public class LocaleListEditorTest {
        final ShadowAlertDialogCompat shadowDialog = ShadowAlertDialogCompat.shadowOf(dialog);

        assertThat(shadowDialog.getMessage().toString()).isEqualTo(
                mContext.getString(R.string.dlg_remove_locales_message));
                mContext.getString(R.string.dlg_remove_locales_message, "Anii (Benin)"));
    }

    @Test
@@ -273,40 +274,6 @@ public class LocaleListEditorTest {
        assertThat(shadowDialog.getMessage()).isNull();
    }

    @Test
    public void showConfirmDialog_systemLocaleSelected_shouldShowLocaleChangeDialog()
            throws Exception {
        //pre-condition
        Locale.setDefault(Locale.forLanguageTag("zh-TW"));
        setUpLocaleConditions(true);
        final Configuration config = new Configuration();
        config.setLocales((LocaleList.forLanguageTags("zh-TW,en-US")));
        when(mActivityService.getConfiguration()).thenReturn(config);
        when(mAdapter.getFeedItemList()).thenReturn(mLocaleList);
        when(mAdapter.getCheckedCount()).thenReturn(1);
        when(mAdapter.getItemCount()).thenReturn(2);
        when(mAdapter.isFirstLocaleChecked()).thenReturn(true);
        ReflectionHelpers.setField(mLocaleListEditor, "mRemoveMode", true);
        ReflectionHelpers.setField(mLocaleListEditor, "mShowingRemoveDialog", true);

        //launch the first dialog
        mLocaleListEditor.showRemoveLocaleWarningDialog();

        final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();

        assertThat(dialog).isNotNull();

        // click the remove button
        dialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
        ShadowLooper.idleMainLooper();

        assertThat(dialog.isShowing()).isFalse();

        // check the second dialog is showing
        verify(mFragmentTransaction).add(any(LocaleDialogFragment.class),
                eq(TAG_DIALOG_CONFIRM_SYSTEM_DEFAULT));
    }

    @Test
    public void showConfirmDialog_2ndLocaleSelected_shouldShowLocaleChangeDialog()
            throws Exception {
@@ -553,6 +520,7 @@ public class LocaleListEditorTest {
        mLocaleList.add(mLocaleInfo2);
        when(mLocaleInfo.getLocale()).thenReturn(Locale.forLanguageTag("blo-BJ"));
        when(mLocaleInfo.isTranslated()).thenReturn(false);
        when(mLocaleInfo.getFullNameNative()).thenReturn("Anii (Benin)");
        when(mLocaleInfo2.getLocale()).thenReturn(Locale.forLanguageTag("zh-TW"));
        when(mLocaleInfo2.isTranslated()).thenReturn(true);
        when(mAdapter.getFeedItemList()).thenReturn(mLocaleList);