Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2908)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/sync/ui/ConfirmImportSyncDataFragment.java

Issue 1698043006: Created the dialog offering the user to merge their account data or keep it (Closed) Base URL: maybelle.lon.corp.google.com:/usr/local/google/code/clankium/src@sync_settings
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..7e37660cb1fbeb842b8e57d741eeb94ef527ac3f
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/sync/ui/ConfirmImportSyncDataFragment.java
@@ -0,0 +1,110 @@
+// 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.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{
+
+ /**
+ * Callback for completion of the dialog.
+ */
+ public interface Listener {
+ /**
+ * The user has completed the dialog using the positive button.
+ * @param mergeData - True if the user chose to merge sync data.
+ */
+ public void onDialogCompleted(boolean mergeData);
+ }
+
+ 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 listener == null;
Bernhard Bauer 2016/02/17 13:24:56 Should this be |mListener|?
PEConn 2016/02/17 17:16:48 Done.
+ 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();
+ mListener.onDialogCompleted(mConfirmImportOption.isChecked());
+ }
+}
+

Powered by Google App Engine
This is Rietveld 408576698