1
1
package com .zulip .android .activities ;
2
2
3
- import android .app .ProgressDialog ;
4
3
import android .content .Context ;
5
4
import android .content .DialogInterface ;
6
5
import android .content .Intent ;
42
41
import com .zulip .android .networking .util .DefaultCallback ;
43
42
import com .zulip .android .util .AnimationHelper ;
44
43
import com .zulip .android .util .Constants ;
44
+ import com .zulip .android .util .CommonProgressDialog ;
45
45
46
46
import org .json .JSONException ;
47
47
import org .json .JSONObject ;
@@ -65,7 +65,7 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener,
65
65
private static final String TAG = "LoginActivity" ;
66
66
private static final int REQUEST_CODE_RESOLVE_ERR = 9000 ;
67
67
private static final int REQUEST_CODE_SIGN_IN = 9001 ;
68
- private ProgressDialog connectionProgressDialog ;
68
+ private CommonProgressDialog commonProgressDialog ;
69
69
private GoogleApiClient mGoogleApiClient ;
70
70
private EditText mServerEditText ;
71
71
private EditText mUserName ;
@@ -88,9 +88,7 @@ protected void onCreate(Bundle savedInstanceState) {
88
88
setSupportActionBar (toolbar );
89
89
90
90
// Progress bar to be displayed if the connection failure is not resolved.
91
- connectionProgressDialog = new ProgressDialog (this );
92
- connectionProgressDialog .setMessage (getString (R .string .signing_in ));
93
-
91
+ commonProgressDialog = new CommonProgressDialog (this );
94
92
mServerEditText = (EditText ) findViewById (R .id .server_url );
95
93
mGoogleSignInButton = findViewById (R .id .google_sign_in_button );
96
94
findViewById (R .id .google_sign_in_button ).setOnClickListener (this );
@@ -264,6 +262,7 @@ private boolean isUrlValid(String url) {
264
262
}
265
263
266
264
private void showBackends (String httpScheme , String serverURL ) {
265
+ commonProgressDialog .showWithMessage (getString (R .string .connecting_to_server ));
267
266
// if server url does not end with "/", then append it
268
267
if (!serverURL .endsWith ("/" )) {
269
268
serverURL = serverURL + "/" ;
@@ -317,12 +316,14 @@ public void onSuccess(Call<ZulipBackendResponse> call, Response<ZulipBackendResp
317
316
if (response .body ().isDev ()) {
318
317
findViewById (R .id .local_server_button ).setVisibility (View .VISIBLE );
319
318
}
319
+ commonProgressDialog .dismiss ();
320
320
showLoginFields ();
321
321
}
322
322
323
323
@ Override
324
324
public void onError (Call <ZulipBackendResponse > call , Response <ZulipBackendResponse > response ) {
325
325
Toast .makeText (LoginActivity .this , R .string .toast_login_failed_fetching_backends , Toast .LENGTH_SHORT ).show ();
326
+ commonProgressDialog .dismiss ();
326
327
}
327
328
328
329
@ Override
@@ -333,6 +334,7 @@ public void onFailure(Call<ZulipBackendResponse> call, Throwable t) {
333
334
} else {
334
335
Toast .makeText (LoginActivity .this , R .string .invalid_url , Toast .LENGTH_SHORT ).show ();
335
336
}
337
+ commonProgressDialog .dismiss ();
336
338
}
337
339
});
338
340
@@ -377,7 +379,7 @@ private void handleSignInResult(final GoogleSignInResult result) {
377
379
378
380
// if there's a problem with fetching the account, bail
379
381
if (account == null ) {
380
- connectionProgressDialog .dismiss ();
382
+ commonProgressDialog .dismiss ();
381
383
Toast .makeText (LoginActivity .this , R .string .google_app_login_failed , Toast .LENGTH_SHORT ).show ();
382
384
return ;
383
385
}
@@ -388,26 +390,26 @@ private void handleSignInResult(final GoogleSignInResult result) {
388
390
389
391
@ Override
390
392
public void onSuccess (Call <LoginResponse > call , Response <LoginResponse > response ) {
391
- connectionProgressDialog .dismiss ();
393
+ commonProgressDialog .dismiss ();
392
394
getApp ().setLoggedInApiKey (response .body ().getApiKey (), response .body ().getEmail ());
393
395
openHome ();
394
396
}
395
397
396
398
@ Override
397
399
public void onError (Call <LoginResponse > call , Response <LoginResponse > response ) {
398
- connectionProgressDialog .dismiss ();
400
+ commonProgressDialog .dismiss ();
399
401
}
400
402
401
403
@ Override
402
404
public void onFailure (Call <LoginResponse > call , Throwable t ) {
403
405
super .onFailure (call , t );
404
- connectionProgressDialog .dismiss ();
406
+ commonProgressDialog .dismiss ();
405
407
}
406
408
});
407
409
408
410
} else {
409
411
// something bad happened. whoops.
410
- connectionProgressDialog .dismiss ();
412
+ commonProgressDialog .dismiss ();
411
413
Toast .makeText (LoginActivity .this , R .string .google_app_login_failed , Toast .LENGTH_SHORT ).show ();
412
414
}
413
415
}
@@ -419,15 +421,15 @@ private void openLegal() {
419
421
420
422
public void openHome () {
421
423
// Cancel before leaving activity to avoid leaking windows
422
- connectionProgressDialog .dismiss ();
424
+ commonProgressDialog .dismiss ();
423
425
Intent i = new Intent (this , ZulipActivity .class );
424
426
startActivity (i );
425
427
finish ();
426
428
}
427
429
428
430
@ Override
429
431
public void onConnectionFailed (ConnectionResult result ) {
430
- if (connectionProgressDialog .isShowing ()) {
432
+ if (commonProgressDialog .isShowing ()) {
431
433
// The user clicked the sign-in button already. Start to resolve
432
434
// connection errors. Wait until onConnected() to dismiss the
433
435
// connection dialog.
@@ -437,11 +439,11 @@ public void onConnectionFailed(ConnectionResult result) {
437
439
} catch (SendIntentException e ) {
438
440
Log .e (TAG , e .getMessage (), e );
439
441
// Yeah, no idea what to do here.
440
- connectionProgressDialog .dismiss ();
442
+ commonProgressDialog .dismiss ();
441
443
Toast .makeText (LoginActivity .this , R .string .google_app_login_failed , Toast .LENGTH_SHORT ).show ();
442
444
}
443
445
} else {
444
- connectionProgressDialog .dismiss ();
446
+ commonProgressDialog .dismiss ();
445
447
if (!isNetworkAvailable ()) {
446
448
Toast .makeText (LoginActivity .this , R .string .toast_no_internet_connection , Toast .LENGTH_SHORT ).show ();
447
449
} else {
@@ -482,14 +484,14 @@ private void allowUserToPickAccount() {
482
484
public void onClick (View v ) {
483
485
switch (v .getId ()) {
484
486
case R .id .google_sign_in_button :
485
- connectionProgressDialog . show ( );
487
+ commonProgressDialog . showWithMessage ( getString ( R . string . signing_in ) );
486
488
setupGoogleSignIn ();
487
489
break ;
488
490
case R .id .zulip_login :
489
491
if (!isInputValid ()) {
490
492
return ;
491
493
}
492
- connectionProgressDialog . show ( );
494
+ commonProgressDialog . showWithMessage ( getString ( R . string . signing_in ) );
493
495
String username = mUserName .getText ().toString ();
494
496
String password = mPassword .getText ().toString ();
495
497
getServices ()
@@ -498,15 +500,15 @@ public void onClick(View v) {
498
500
499
501
@ Override
500
502
public void onSuccess (Call <LoginResponse > call , Response <LoginResponse > response ) {
501
- connectionProgressDialog .dismiss ();
503
+ commonProgressDialog .dismiss ();
502
504
getApp ().setLoggedInApiKey (response .body ().getApiKey (), response .body ().getEmail ());
503
505
openHome ();
504
506
}
505
507
506
508
507
509
@ Override
508
510
public void onError (Call <LoginResponse > call , Response <LoginResponse > response ) {
509
- connectionProgressDialog .dismiss ();
511
+ commonProgressDialog .dismiss ();
510
512
if (response != null && response .errorBody () != null ) {
511
513
try {
512
514
JSONObject message = new JSONObject (response .errorBody ().string ());
@@ -528,7 +530,7 @@ public void onError(Call<LoginResponse> call, Response<LoginResponse> response)
528
530
@ Override
529
531
public void onFailure (Call <LoginResponse > call , Throwable t ) {
530
532
super .onFailure (call , t );
531
- connectionProgressDialog .dismiss ();
533
+ commonProgressDialog .dismiss ();
532
534
if (!isNetworkAvailable ()) {
533
535
Toast .makeText (LoginActivity .this , R .string .toast_no_internet_connection , Toast .LENGTH_LONG ).show ();
534
536
} else {
@@ -543,17 +545,17 @@ public void onFailure(Call<LoginResponse> call, Throwable t) {
543
545
break ;
544
546
case R .id .local_server_button :
545
547
if (!isInputValidForDevAuth ()) return ;
546
- connectionProgressDialog . show ( );
548
+ commonProgressDialog . showWithMessage ( getString ( R . string . signing_in ) );
547
549
AsyncDevGetEmails asyncDevGetEmails = new AsyncDevGetEmails (LoginActivity .this );
548
550
asyncDevGetEmails .setCallback (new ZulipAsyncPushTask .AsyncTaskCompleteListener () {
549
551
@ Override
550
552
public void onTaskComplete (String result , JSONObject jsonObject ) {
551
- connectionProgressDialog .dismiss ();
553
+ commonProgressDialog .dismiss ();
552
554
}
553
555
554
556
@ Override
555
557
public void onTaskFailure (String result ) {
556
- connectionProgressDialog .dismiss ();
558
+ commonProgressDialog .dismiss ();
557
559
}
558
560
});
559
561
asyncDevGetEmails .execute ();
0 commit comments