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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/signin/ConfirmSyncDataStateMachineDelegate.java

Issue 2772203004: Add progress and timeout dialogs for getting account management policy (Closed)
Patch Set: Created 3 years, 9 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.signin;
6
7 import android.app.Dialog;
8 import android.content.Context;
9 import android.content.DialogInterface;
10 import android.support.v7.app.AlertDialog;
11 import android.view.LayoutInflater;
12
13 import org.chromium.chrome.R;
14
15 /**
16 * Class to decouple ConfirmSyncDataStateMachine from UI code and dialog managem ent.
17 */
18 public class ConfirmSyncDataStateMachineDelegate {
19 /**
20 * Listener to receive events from progress dialog. If dialog is not dismiss ed by calling
msarda 2017/03/28 11:09:02 Nit: I would add a *the* in: "If *the* dialog ..."
bsazonov 2017/03/28 12:59:58 Done. I've also changed the same sentence in Timeo
msarda 2017/03/28 13:41:05 Acknowledged.
21 * {@link ConfirmSyncDataStateMachineDelegate#dismissProgressDialog}, then
22 * {@link #onCancel} will be called once.
23 */
24 public interface ProgressDialogListener {
25 /**
26 * This method is called when user cancels the dialog in any way.
27 */
28 void onCancel();
29 }
30
31 /**
32 * Listener to receive events from timeout dialog. If dialog is not dismisse d by calling
33 * {@link ConfirmSyncDataStateMachineDelegate#dismissTimeoutDialog}, then
34 * either {@link #onCancel} or {@link #onRetry} will be called once.
35 */
36 public interface TimeoutDialogListener {
37 /**
38 * This method is called when user cancels the dialog in any way.
39 */
40 void onCancel();
41
42 /**
43 * This method is called when user clicks retry button.
44 */
45 void onRetry();
46 }
47
48 private final Context mContext;
49
50 private Dialog mProgressDialog;
51 private AlertDialog mTimeoutAlertDialog;
52
53 public ConfirmSyncDataStateMachineDelegate(Context context) {
54 mContext = context;
55 }
56
57 /**
58 * Shows progress dialog. Will dismiss previous progress dialog, if any.
59 *
60 * @param listener The {@link ProgressDialogListener} that will be notified about user actions.
61 */
62 public void showProgressDialog(final ProgressDialogListener listener) {
msarda 2017/03/28 11:09:02 My understand is that this delegate is the generic
bsazonov 2017/03/28 12:59:58 Done. I think that "Management" fits better than "
63 dismissProgressDialog();
msarda 2017/03/28 11:09:02 Why does the previous dialog need to be dismissed
bsazonov 2017/03/28 12:59:58 Thanks for bringing this up. I've made this functi
msarda 2017/03/28 13:41:05 I think we should not have this call be done in th
bsazonov 2017/03/29 13:05:05 Done. I've added dismissAllDialogs instead of sepa
64 AlertDialog.Builder builder = new AlertDialog.Builder(mContext, R.style. AlertDialogTheme);
msarda 2017/03/28 11:09:02 For consistency with the code below (and if it is
bsazonov 2017/03/28 12:59:58 See next comment.
65 LayoutInflater inflater = LayoutInflater.from(builder.getContext());
msarda 2017/03/28 11:09:02 Stupid question: Is builder.getContext() the same
bsazonov 2017/03/28 12:59:58 AFAIK, these context can be different (at least in
66 builder.setView(inflater.inflate(R.layout.signin_progress_bar_dialog, nu ll));
67 builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickLi stener() {
68 @Override
69 public void onClick(DialogInterface dialogInterface, int i) {
msarda 2017/03/28 11:09:02 For consistency, use dialog instead of dialogInter
bsazonov 2017/03/28 12:59:58 Done.
70 listener.onCancel();
msarda 2017/03/28 11:09:02 For consistency, please call dialogInterface.cance
bsazonov 2017/03/28 12:59:58 Done.
71 }
72 });
73 builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
74 @Override
75 public void onCancel(DialogInterface dialogInterface) {
76 listener.onCancel();
77 }
78 });
79 mProgressDialog = builder.create();
80 mProgressDialog.show();
81 }
82
83 /**
84 * Dismisses progress dialog.
85 */
86 public void dismissProgressDialog() {
87 if (mProgressDialog != null) mProgressDialog.dismiss();
88 mProgressDialog = null;
89 }
90
91 /**
92 * Shows timeout dialog. Will dismiss previous timeout dialog, if any.
93 *
94 * @param listener The {@link TimeoutDialogListener} that will be notified a bout user actions.
95 */
96 public void showTimeoutDialog(final TimeoutDialogListener listener) {
msarda 2017/03/28 11:09:02 Same here: showFetchManagedPolicyTimeoutDialog
bsazonov 2017/03/28 12:59:58 Done.
97 dismissTimeoutDialog();
98 mTimeoutAlertDialog =
99 new AlertDialog.Builder(mContext, R.style.AlertDialogTheme)
100 .setTitle(R.string.sign_in_timeout_title)
101 .setMessage(R.string.sign_in_timeout_message)
102 .setNegativeButton(R.string.cancel,
103 new DialogInterface.OnClickListener() {
104 @Override
105 public void onClick(DialogInterface dialog, int which) {
106 dialog.cancel();
107 }
108 })
109 .setPositiveButton(R.string.retry,
110 new DialogInterface.OnClickListener() {
111 @Override
112 public void onClick(DialogInterface dialog, int which) {
113 listener.onRetry();
114 }
115 })
116 .setOnCancelListener(new DialogInterface.OnCancelListene r() {
117 @Override
118 public void onCancel(DialogInterface dialogInterface ) {
119 listener.onCancel();
120 }
121 })
122 .create();
123 mTimeoutAlertDialog.show();
124 }
125
126 /**
127 * Dismisses timeout dialog.
128 */
129 public void dismissTimeoutDialog() {
130 if (mTimeoutAlertDialog != null) mTimeoutAlertDialog.dismiss();
131 mTimeoutAlertDialog = null;
132 }
133 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698