Revision 16615abd src/com/rackspacecloud/android/ListAccountsActivity.java

b/src/com/rackspacecloud/android/ListAccountsActivity.java
65 65
	private ProgressDialog dialog;
66 66
	private Context context;
67 67
	private AndroidCloudApplication app;
68
	//used to track the current asynctask
69
	@SuppressWarnings("rawtypes")
70
	private AsyncTask task;
68 71

  
69 72
	//need to store if the user has successfully logged in
70 73
	private boolean loggedIn;
......
415 418
				@Override
416 419
				public void onCancel(DialogInterface dialog) {
417 420
					app.setIsLoggingIn(false);
421
					//need to cancel the old task or we may get a double login
422
					task.cancel(true);
418 423
					hideDialog();
419 424
				}
420 425
			});
......
437 442

  
438 443
		@Override
439 444
		protected void onPreExecute(){
445
			Log.d("info", "Starting authenticate");
446
			task = this;
440 447
			showDialog();
441 448
		}
442 449

  
443 450
		@Override
444 451
		protected Boolean doInBackground(Void... arg0) {
445
			if(isCancelled()){
446
				return false;
447
			}
448 452
			return new Boolean(Authentication.authenticate(context));
449 453
		}
450 454

  
......
452 456
		protected void onPostExecute(Boolean result) {
453 457
			if (result.booleanValue()) {
454 458
				//startActivity(tabViewIntent);
455
				if(app.isLogginIn()){
459
				if(app.isLoggingIn()){
456 460
					new LoadImagesTask().execute((Void[]) null);
457 461
				} else {
458 462
					hideDialog();
459 463
				}
460 464
			} else {
461 465
				hideDialog();
462
				showAlert("Login Failure", "Authentication failed.  Please check your User Name and API Key.");
466
				if(app.isLoggingIn()){
467
					showAlert("Login Failure", "Authentication failed.  Please check your User Name and API Key.");
468
				}
463 469
			}
464 470
		}
465 471
	}
......
467 473
	private class LoadImagesTask extends AsyncTask<Void, Void, ArrayList<Image>> {
468 474
 
469 475
		@Override
476
		protected void onPreExecute(){
477
			Log.d("info", "Starting Images");
478
			task = this;
479
		}
480
		
481
		@Override
470 482
		protected ArrayList<Image> doInBackground(Void... arg0) {
471
			Log.d("info", "LoadImagesTask Started");
472 483
			return (new ImageManager()).createList(true, context);
473 484
		}
474 485

  
......
481 492
					imageMap.put(image.getId(), image);
482 493
				}
483 494
				Image.setImages(imageMap);
484
				if(app.isLogginIn()){
495
				if(app.isLoggingIn()){
485 496
					new LoadProtocolsTask().execute((Void[]) null); 
486 497
				} else {
487 498
					hideDialog();
488 499
				}
489 500
			} else {
490 501
				hideDialog();
491
				showAlert("Login Failure", "There was a problem loading server images.  Please try again.");
502
				if(app.isLoggingIn()){
503
					showAlert("Login Failure", "There was a problem loading server images.  Please try again.");
504
				}
492 505
			}
493 506
		}
494 507
	}
......
496 509
	private class LoadProtocolsTask extends AsyncTask<Void, Void, ArrayList<Protocol>> {
497 510

  
498 511
		@Override
512
		protected void onPreExecute(){
513
			Log.d("info", "Starting protcols");
514
			task = this;
515
		}
516
		
517
		@Override
499 518
		protected ArrayList<Protocol> doInBackground(Void... arg0) {
500
			Log.d("info", "LoadProtocolsTask Started");
501 519
			return (new ProtocolManager()).createList(context);
502 520
		}
503 521

  
......
505 523
		protected void onPostExecute(ArrayList<Protocol> result) {
506 524
			if (result != null && result.size() > 0) {
507 525
				Protocol.setProtocols(result);
508
				if(app.isLogginIn()){
526
				if(app.isLoggingIn()){
509 527
					new LoadAlgorithmsTask().execute((Void[]) null);
510 528
				} else {
511 529
					hideDialog();
512 530
				}
513 531
			} else {
514 532
				hideDialog();
515
				showAlert("Login Failure", "There was a problem loading load balancer protocols.  Please try again.");
533
				if(app.isLoggingIn()){
534
					showAlert("Login Failure", "There was a problem loading load balancer protocols.  Please try again.");
535
				}
516 536
			}
517 537
		}
518 538
	}
519 539

  
520 540
	private class LoadAlgorithmsTask extends AsyncTask<Void, Void, ArrayList<Algorithm>> {
521 541

  
542
		protected void onPreExecute(){
543
			Log.d("info", "Starting algorithms");
544
			task = this;
545
		}
546
		
522 547
		@Override
523 548
		protected ArrayList<Algorithm> doInBackground(Void... arg0) {
524
			Log.d("info", "LoadAlgorithmsTask Started");
525 549
			return (new AlgorithmManager()).createList(context);
526 550
		}
527 551

  
......
529 553
		protected void onPostExecute(ArrayList<Algorithm> result) {
530 554
			if (result != null && result.size() > 0) {
531 555
				Algorithm.setAlgorithms(result);
532
				if(app.isLogginIn()){
556
				if(app.isLoggingIn()){
533 557
					new LoadFlavorsTask().execute((Void[]) null);
534 558
				} else {
535 559
					hideDialog();
536 560
				}
537 561
			} else {
538 562
				hideDialog();
539
				showAlert("Login Failure", "There was a problem loading load balancer algorithms.  Please try again.");
563
				if(app.isLoggingIn()){
564
					showAlert("Login Failure", "There was a problem loading load balancer algorithms.  Please try again.");
565
				}
540 566
			}
541 567
		}
542 568
	}
543 569

  
544 570
	private class LoadFlavorsTask extends AsyncTask<Void, Void, ArrayList<Flavor>> {
545 571

  
572
		protected void onPreExecute(){
573
			Log.d("info", "Starting flavors");
574
			task = this;
575
		}
576
		
546 577
		@Override
547 578
		protected ArrayList<Flavor> doInBackground(Void... arg0) {
548
			Log.d("info", "LoadFlavorsTask Started");
549 579
			return (new FlavorManager()).createList(true, context);
550 580
		}
551 581

  
552 582
		@Override
553 583
		protected void onPostExecute(ArrayList<Flavor> result) {
554
			if(isCancelled()){
555
				return;
556
			}
557
			
558 584
			if (result != null && result.size() > 0) {
559 585
				TreeMap<String, Flavor> flavorMap = new TreeMap<String, Flavor>();
560 586
				for (int i = 0; i < result.size(); i++) {
......
562 588
					flavorMap.put(flavor.getId(), flavor);
563 589
				}
564 590
				Flavor.setFlavors(flavorMap);
565
				if(isCancelled()){
566
					return;
567
				}
568 591
				hideDialog();
569
				Log.d("info", "Starting TabViewIntent");
570
				if(app.isLogginIn()){
592
				if(app.isLoggingIn()){
571 593
					startActivityForResult(tabViewIntent, 187);
572
				} else {
573
					hideDialog();
574 594
				}
575 595
			} else {
576 596
				hideDialog();
577
				showAlert("Login Failure", "There was a problem loading server flavors.  Please try again.");
597
				if(app.isLoggingIn()){
598
					showAlert("Login Failure", "There was a problem loading server flavors.  Please try again.");
599
				}
578 600
			}
579 601
		}
580 602
	}

Also available in: Unified diff