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

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

Merge "[Language] Should show confirm dialog when deleting the system language...

Merge "[Language] Should show confirm dialog when deleting the system language and making the second language automatically become the system language" into udc-qpr-dev
parents 43bd9db3 4900bcfa
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -395,11 +395,14 @@ class LocaleDragAndDropAdapter
                // drag locale's original position to the top.
                mDragLocale = (LocaleStore.LocaleInfo) savedInstanceState.getSerializable(
                        CFGKEY_DRAG_LOCALE);
                if (mDragLocale != null) {
                    mFeedItemList.removeIf(
                        localeInfo -> TextUtils.equals(localeInfo.getId(), mDragLocale.getId()));
                            localeInfo -> TextUtils.equals(localeInfo.getId(),
                                    mDragLocale.getId()));
                    mFeedItemList.add(0, mDragLocale);
                    notifyItemRangeChanged(0, mFeedItemList.size());
                }
            }
        }
    }
}
+23 −12
Original line number Diff line number Diff line
@@ -322,7 +322,13 @@ public class LocaleListEditor extends RestrictedSettingsFragment implements View
                                // to remove.
                                mRemoveMode = false;
                                mShowingRemoveDialog = false;
                                LocaleStore.LocaleInfo firstLocale =
                                        mAdapter.getFeedItemList().get(0);
                                mAdapter.removeChecked();
                                boolean isFirstRemoved =
                                        firstLocale != mAdapter.getFeedItemList().get(0);
                                showConfirmDialog(isFirstRemoved, isFirstRemoved ? firstLocale
                                        : mAdapter.getFeedItemList().get(0));
                                setRemoveMode(false);
                            }
                        })
@@ -388,21 +394,26 @@ public class LocaleListEditor extends RestrictedSettingsFragment implements View
    public boolean onTouch(View v, MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_UP
                || event.getAction() == MotionEvent.ACTION_CANCEL) {
            LocaleStore.LocaleInfo localeInfo = mAdapter.getFeedItemList().get(0);
            if (!localeInfo.getLocale().equals(LocalePicker.getLocales().get(0))) {
            showConfirmDialog(false, mAdapter.getFeedItemList().get(0));
        }
        return false;
    }

    private void showConfirmDialog(boolean isFirstRemoved, LocaleStore.LocaleInfo localeInfo) {
        Locale currentSystemLocale = LocalePicker.getLocales().get(0);
        if (!localeInfo.getLocale().equals(currentSystemLocale)) {
            final LocaleDialogFragment localeDialogFragment =
                    LocaleDialogFragment.newInstance();
            Bundle args = new Bundle();
            args.putInt(LocaleDialogFragment.ARG_DIALOG_TYPE, DIALOG_CONFIRM_SYSTEM_DEFAULT);
                args.putSerializable(LocaleDialogFragment.ARG_TARGET_LOCALE, localeInfo);
            args.putSerializable(LocaleDialogFragment.ARG_TARGET_LOCALE,
                    isFirstRemoved ? LocaleStore.getLocaleInfo(currentSystemLocale) : localeInfo);
            localeDialogFragment.setArguments(args);
            localeDialogFragment.show(mFragmentManager, TAG_DIALOG_CONFIRM_SYSTEM_DEFAULT);
        } else {
            mAdapter.doTheUpdate();
        }
    }
        return false;
    }

    // Hide the "Remove" menu if there is only one locale in the list, show it otherwise
    // This is called when the menu is first created, and then one add / remove locale
+38 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import static org.mockito.Mockito.when;
import android.app.Activity;
import android.app.IActivityManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
@@ -57,6 +58,7 @@ import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;

import java.util.ArrayList;
import java.util.List;
@@ -91,6 +93,8 @@ public class LocaleListEditorTest {
    private View mView;
    @Mock
    private IActivityManager mActivityService;
    @Mock
    private MetricsFeatureProvider mMetricsFeatureProvider;

    @Before
    public void setUp() throws Exception {
@@ -108,6 +112,8 @@ public class LocaleListEditorTest {
                RuntimeEnvironment.application.getSystemService(Context.USER_SERVICE));
        ReflectionHelpers.setField(mLocaleListEditor, "mAdapter", mAdapter);
        ReflectionHelpers.setField(mLocaleListEditor, "mFragmentManager", mFragmentManager);
        ReflectionHelpers.setField(mLocaleListEditor, "mMetricsFeatureProvider",
                mMetricsFeatureProvider);
        when(mFragmentManager.beginTransaction()).thenReturn(mFragmentTransaction);
        FakeFeatureFactory.setupForTest();
    }
@@ -199,6 +205,38 @@ public class LocaleListEditorTest {
        assertThat(shadowDialog.getMessage()).isNull();
    }

    @Test
    public void showConfirmDialog_systemLocaleSelected_shouldShowLocaleChangeDialog()
            throws Exception {
        //pre-condition
        setUpLocaleConditions();
        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();

        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 mayAppendUnicodeTags_appendUnicodeTags_success() {
        LocaleStore.LocaleInfo localeInfo = LocaleStore.fromLocale(Locale.forLanguageTag("en-US"));