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

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: Addressed comments Created 3 years, 8 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
12 import org.chromium.chrome.R;
13
14 /**
15 * Class to decouple ConfirmSyncDataStateMachine from UI code and dialog managem ent.
16 */
17 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
18 /**
19 * Listener to receive events from progress dialog. If the dialog is not dis missed by calling
20 * {@link ConfirmSyncDataStateMachineDelegate#dismissFetchManagementPolicyPr ogressDialog}, then
21 * {@link #onCancel} will be called once.
22 */
23 public interface ProgressDialogListener {
24 /**
25 * This method is called when user cancels the dialog in any way.
26 */
27 void onCancel();
28 }
29
30 /**
31 * Listener to receive events from timeout dialog. If the dialog is not dism issed by calling
32 * {@link ConfirmSyncDataStateMachineDelegate#dismissFetchManagementPolicyTi meoutDialog}, then
33 * either {@link #onCancel} or {@link #onRetry} will be called once.
34 */
35 public interface TimeoutDialogListener {
36 /**
37 * This method is called when user cancels the dialog in any way.
38 */
39 void onCancel();
40
41 /**
42 * This method is called when user clicks retry button.
43 */
44 void onRetry();
45 }
46
47 private final Context mContext;
48
49 private Dialog mProgressDialog;
50 private AlertDialog mTimeoutAlertDialog;
51
52 public ConfirmSyncDataStateMachineDelegate(Context context) {
53 mContext = context;
54 }
55
56 /**
57 * Shows progress dialog. Will dismiss previous progress dialog, if any.
58 *
59 * @param listener The {@link ProgressDialogListener} that will be notified about user actions.
60 */
61 public void showFetchManagementPolicyProgressDialog(final ProgressDialogList ener listener) {
62 dismissFetchManagementPolicyProgressDialog();
63 mProgressDialog = new AlertDialog.Builder(mContext, R.style.AlertDialogT heme)
64 .setView(R.layout.signin_progress_bar_dialog)
65 .setNegativeButton(R.string.cancel,
66 new DialogInterface.OnClickListener() {
67 @Override
68 public void onClick(DialogInterfac e dialog, int i) {
69 dialog.cancel();
70 }
71 })
72 .setOnCancelListener(new DialogInterface.OnCan celListener() {
73 @Override
74 public void onCancel(DialogInterface dialo g) {
75 listener.onCancel();
76 }
77 })
78 .create();
79 mProgressDialog.show();
80 }
81
82 /**
83 * Dismisses progress dialog.
84 */
85 public void dismissFetchManagementPolicyProgressDialog() {
86 if (mProgressDialog != null) mProgressDialog.dismiss();
87 mProgressDialog = null;
88 }
89
90 /**
91 * Shows timeout dialog. Will dismiss previous timeout dialog, if any.
92 *
93 * @param listener The {@link TimeoutDialogListener} that will be notified a bout user actions.
94 */
95 public void showFetchManagementPolicyTimeoutDialog(final TimeoutDialogListen er listener) {
96 dismissFetchManagementPolicyTimeoutDialog();
97 mTimeoutAlertDialog =
98 new AlertDialog.Builder(mContext, R.style.AlertDialogTheme)
99 .setTitle(R.string.sign_in_timeout_title)
100 .setMessage(R.string.sign_in_timeout_message)
101 .setNegativeButton(R.string.cancel,
102 new DialogInterface.OnClickListener() {
103 @Override
104 public void onClick(DialogInterface dialog, int which) {
105 dialog.cancel();
106 }
107 })
108 .setPositiveButton(R.string.retry,
109 new DialogInterface.OnClickListener() {
110 @Override
111 public void onClick(DialogInterface dialog, int which) {
112 listener.onRetry();
113 }
114 })
115 .setOnCancelListener(new DialogInterface.OnCancelListene r() {
116 @Override
117 public void onCancel(DialogInterface dialog) {
118 listener.onCancel();
119 }
120 })
121 .create();
122 mTimeoutAlertDialog.show();
123 }
124
125 /**
126 * Dismisses timeout dialog.
127 */
128 public void dismissFetchManagementPolicyTimeoutDialog() {
129 if (mTimeoutAlertDialog != null) mTimeoutAlertDialog.dismiss();
130 mTimeoutAlertDialog = null;
131 }
132 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698