Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/signin/ConfirmSyncDataStateMachineDelegate.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/signin/ConfirmSyncDataStateMachineDelegate.java b/chrome/android/java/src/org/chromium/chrome/browser/signin/ConfirmSyncDataStateMachineDelegate.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..25541748c85871ccc1bf8432ad4d16dcc52ada6a |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/signin/ConfirmSyncDataStateMachineDelegate.java |
| @@ -0,0 +1,132 @@ |
| +// Copyright 2017 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.signin; |
| + |
| +import android.app.Dialog; |
| +import android.content.Context; |
| +import android.content.DialogInterface; |
| +import android.support.v7.app.AlertDialog; |
| + |
| +import org.chromium.chrome.R; |
| + |
| +/** |
| + * Class to decouple ConfirmSyncDataStateMachine from UI code and dialog management. |
| + */ |
| +public class ConfirmSyncDataStateMachineDelegate { |
|
Bernhard Bauer
2017/03/28 14:19:21
Nit: I'm not sure delegate is the best name for th
bsazonov
2017/03/29 13:05:05
Actually, I was thinking of adding mock delegate t
Bernhard Bauer
2017/03/29 15:01:58
Okay, then we could start to really decouple the t
|
| + /** |
| + * Listener to receive events from progress dialog. If the dialog is not dismissed by calling |
| + * {@link ConfirmSyncDataStateMachineDelegate#dismissFetchManagementPolicyProgressDialog}, then |
| + * {@link #onCancel} will be called once. |
| + */ |
| + public interface ProgressDialogListener { |
| + /** |
| + * This method is called when user cancels the dialog in any way. |
| + */ |
| + void onCancel(); |
| + } |
| + |
| + /** |
| + * Listener to receive events from timeout dialog. If the dialog is not dismissed by calling |
| + * {@link ConfirmSyncDataStateMachineDelegate#dismissFetchManagementPolicyTimeoutDialog}, then |
| + * either {@link #onCancel} or {@link #onRetry} will be called once. |
| + */ |
| + public interface TimeoutDialogListener { |
| + /** |
| + * This method is called when user cancels the dialog in any way. |
| + */ |
| + void onCancel(); |
| + |
| + /** |
| + * This method is called when user clicks retry button. |
| + */ |
| + void onRetry(); |
| + } |
| + |
| + private final Context mContext; |
| + |
| + private Dialog mProgressDialog; |
| + private AlertDialog mTimeoutAlertDialog; |
| + |
| + public ConfirmSyncDataStateMachineDelegate(Context context) { |
| + mContext = context; |
| + } |
| + |
| + /** |
| + * Shows progress dialog. Will dismiss previous progress dialog, if any. |
| + * |
| + * @param listener The {@link ProgressDialogListener} that will be notified about user actions. |
| + */ |
| + public void showFetchManagementPolicyProgressDialog(final ProgressDialogListener listener) { |
| + dismissFetchManagementPolicyProgressDialog(); |
| + mProgressDialog = new AlertDialog.Builder(mContext, R.style.AlertDialogTheme) |
| + .setView(R.layout.signin_progress_bar_dialog) |
| + .setNegativeButton(R.string.cancel, |
| + new DialogInterface.OnClickListener() { |
| + @Override |
| + public void onClick(DialogInterface dialog, int i) { |
| + dialog.cancel(); |
| + } |
| + }) |
| + .setOnCancelListener(new DialogInterface.OnCancelListener() { |
| + @Override |
| + public void onCancel(DialogInterface dialog) { |
| + listener.onCancel(); |
| + } |
| + }) |
| + .create(); |
| + mProgressDialog.show(); |
| + } |
| + |
| + /** |
| + * Dismisses progress dialog. |
| + */ |
| + public void dismissFetchManagementPolicyProgressDialog() { |
| + if (mProgressDialog != null) mProgressDialog.dismiss(); |
| + mProgressDialog = null; |
| + } |
| + |
| + /** |
| + * Shows timeout dialog. Will dismiss previous timeout dialog, if any. |
| + * |
| + * @param listener The {@link TimeoutDialogListener} that will be notified about user actions. |
| + */ |
| + public void showFetchManagementPolicyTimeoutDialog(final TimeoutDialogListener listener) { |
| + dismissFetchManagementPolicyTimeoutDialog(); |
| + mTimeoutAlertDialog = |
| + new AlertDialog.Builder(mContext, R.style.AlertDialogTheme) |
| + .setTitle(R.string.sign_in_timeout_title) |
| + .setMessage(R.string.sign_in_timeout_message) |
| + .setNegativeButton(R.string.cancel, |
| + new DialogInterface.OnClickListener() { |
| + @Override |
| + public void onClick(DialogInterface dialog, int which) { |
| + dialog.cancel(); |
| + } |
| + }) |
| + .setPositiveButton(R.string.retry, |
| + new DialogInterface.OnClickListener() { |
| + @Override |
| + public void onClick(DialogInterface dialog, int which) { |
| + listener.onRetry(); |
| + } |
| + }) |
| + .setOnCancelListener(new DialogInterface.OnCancelListener() { |
| + @Override |
| + public void onCancel(DialogInterface dialog) { |
| + listener.onCancel(); |
| + } |
| + }) |
| + .create(); |
| + mTimeoutAlertDialog.show(); |
| + } |
| + |
| + /** |
| + * Dismisses timeout dialog. |
| + */ |
| + public void dismissFetchManagementPolicyTimeoutDialog() { |
| + if (mTimeoutAlertDialog != null) mTimeoutAlertDialog.dismiss(); |
| + mTimeoutAlertDialog = null; |
| + } |
| +} |