| Index: chrome/android/java/src/org/chromium/chrome/browser/sync/ui/ConfirmImportSyncDataFragment.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/sync/ui/ConfirmImportSyncDataFragment.java b/chrome/android/java/src/org/chromium/chrome/browser/sync/ui/ConfirmImportSyncDataFragment.java
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..91f4c3b08c563c51b690c382474bd90e5fb2ab5c
|
| --- /dev/null
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/sync/ui/ConfirmImportSyncDataFragment.java
|
| @@ -0,0 +1,133 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +package org.chromium.chrome.browser.sync.ui;
|
| +
|
| +import android.app.AlertDialog;
|
| +import android.app.Dialog;
|
| +import android.app.DialogFragment;
|
| +import android.content.DialogInterface;
|
| +import android.os.Bundle;
|
| +import android.view.LayoutInflater;
|
| +import android.view.View;
|
| +import android.widget.TextView;
|
| +
|
| +import org.chromium.chrome.R;
|
| +import org.chromium.chrome.browser.BrowsingDataType;
|
| +import org.chromium.chrome.browser.ChromeBrowserProviderClient;
|
| +import org.chromium.chrome.browser.preferences.PrefServiceBridge;
|
| +import org.chromium.chrome.browser.preferences.PrefServiceBridge.OnClearBrowsingDataListener;
|
| +import org.chromium.ui.widget.RadioButtonWithDescription;
|
| +
|
| +import java.util.Arrays;
|
| +import java.util.List;
|
| +
|
| +/**
|
| + * A dialog that is displayed when the user switches the account they are syncing to. It gives the
|
| + * option to merge the data of the two accounts or to keep them separate.
|
| + */
|
| +public class ConfirmImportSyncDataFragment extends DialogFragment
|
| + implements DialogInterface.OnClickListener, OnClearBrowsingDataListener {
|
| +
|
| + private static final int[] SYNC_DATA_TYPES = {
|
| + BrowsingDataType.HISTORY,
|
| + BrowsingDataType.CACHE,
|
| + BrowsingDataType.COOKIES,
|
| + BrowsingDataType.PASSWORDS,
|
| + BrowsingDataType.FORM_DATA
|
| + };
|
| +
|
| + /**
|
| + * Callback for completion of the dialog.
|
| + */
|
| + public interface Listener {
|
| + /**
|
| + * The user has completed the dialog using the positive button. If requested, the previous
|
| + * sync data has been cleared.
|
| + */
|
| + public void onConfirm();
|
| + }
|
| +
|
| + private static final String KEY_OLD_ACCOUNT_NAME = "lastAccountName";
|
| + private static final String KEY_NEW_ACCOUNT_NAME = "newAccountName";
|
| +
|
| + private RadioButtonWithDescription mConfirmImportOption;
|
| + private RadioButtonWithDescription mKeepSeparateOption;
|
| +
|
| + private Listener mListener;
|
| +
|
| + public static ConfirmImportSyncDataFragment newInstance(
|
| + String oldAccountName, String newAccountName) {
|
| +
|
| + ConfirmImportSyncDataFragment fragment = new ConfirmImportSyncDataFragment();
|
| + Bundle args = new Bundle();
|
| + args.putString(KEY_OLD_ACCOUNT_NAME, oldAccountName);
|
| + args.putString(KEY_NEW_ACCOUNT_NAME, newAccountName);
|
| + fragment.setArguments(args);
|
| + return fragment;
|
| + }
|
| +
|
| + @Override
|
| + public Dialog onCreateDialog(Bundle savedInstanceState) {
|
| + String oldAccountName = getArguments().getString(KEY_OLD_ACCOUNT_NAME);
|
| + String newAccountName = getArguments().getString(KEY_NEW_ACCOUNT_NAME);
|
| +
|
| + LayoutInflater inflater = getActivity().getLayoutInflater();
|
| + View v = inflater.inflate(R.layout.confirm_import_sync_data, null);
|
| +
|
| + TextView prompt = (TextView) v.findViewById(R.id.sync_import_data_prompt);
|
| + prompt.setText(getActivity().getString(R.string.sync_import_data_prompt,
|
| + newAccountName, oldAccountName));
|
| +
|
| + mConfirmImportOption = (RadioButtonWithDescription)
|
| + v.findViewById(R.id.sync_confirm_import_choice);
|
| + mKeepSeparateOption = (RadioButtonWithDescription)
|
| + v.findViewById(R.id.sync_keep_separate_choice);
|
| +
|
| + mConfirmImportOption.setDescriptionText(getActivity().getString(
|
| + R.string.sync_import_existing_data_subtext, newAccountName));
|
| + mKeepSeparateOption.setDescriptionText(getActivity().getString(
|
| + R.string.sync_keep_existing_data_separate_subtext, newAccountName, oldAccountName));
|
| +
|
| + List<RadioButtonWithDescription> radioGroup =
|
| + Arrays.asList(mConfirmImportOption, mKeepSeparateOption);
|
| + mConfirmImportOption.setRadioButtonGroup(radioGroup);
|
| + mKeepSeparateOption.setRadioButtonGroup(radioGroup);
|
| +
|
| + mConfirmImportOption.setChecked(true);
|
| +
|
| + return new AlertDialog.Builder(getActivity(), R.style.AlertDialogTheme)
|
| + .setTitle(getActivity().getString(R.string.sync_import_data_title))
|
| + .setPositiveButton(getActivity().getString(R.string.cont), this)
|
| + .setNegativeButton(getActivity().getString(R.string.cancel), this)
|
| + .setView(v)
|
| + .create();
|
| + }
|
| +
|
| + public void setListener(Listener listener) {
|
| + assert mListener == null;
|
| + mListener = listener;
|
| + }
|
| +
|
| + @Override
|
| + public void onClick(DialogInterface dialog, int which) {
|
| + if (which != AlertDialog.BUTTON_POSITIVE) return;
|
| + if (mListener == null) return;
|
| +
|
| + assert mConfirmImportOption.isChecked() ^ mKeepSeparateOption.isChecked();
|
| +
|
| + if (mConfirmImportOption.isChecked()) {
|
| + mListener.onConfirm();
|
| + } else {
|
| + ChromeBrowserProviderClient.removeAllUserBookmarks(getActivity());
|
| + PrefServiceBridge.getInstance().clearBrowsingData(this, SYNC_DATA_TYPES);
|
| + }
|
| + }
|
| +
|
| + @Override
|
| + public void onBrowsingDataCleared() {
|
| + mListener.onConfirm();
|
| + }
|
| +}
|
| +
|
|
|