Revision 3d654446

b/src/com/rackspacecloud/android/ListAccountsActivity.java
22 22
import android.app.ProgressDialog;
23 23
import android.content.Context;
24 24
import android.content.DialogInterface;
25
import android.content.DialogInterface.OnCancelListener;
25 26
import android.content.Intent;
26 27
import android.os.AsyncTask;
27 28
import android.os.Bundle;
......
57 58
	private Context context;
58 59
	//need to store if the user has successfully logged in
59 60
	private boolean loggedIn;
61
	private AuthenticateTask authTask;
62
	private LoadImagesTask imageTask;
63
	private LoadFlavorsTask flavorTask;
60 64

  
61 65
	public void onCreate(Bundle savedInstanceState) {
62 66
		super.onCreate(savedInstanceState);
......
128 132
		}
129 133
	}
130 134

  
131

  
132 135
	/*
133 136
	 * if the application is password protected,
134 137
	 * the user must provide the password before
......
269 272
	public void login() {
270 273
		//showActivityIndicators();
271 274
		//setLoginPreferences();
272
		new AuthenticateTask().execute((Void[]) null);
275
		authTask = new AuthenticateTask();
276
		authTask.execute((Void[]) null);
273 277
	}
274 278

  
275 279
	//setup menu for when menu button is pressed
......
409 413
		authenticating = true;
410 414
		if(dialog == null || !dialog.isShowing()){
411 415
			dialog = ProgressDialog.show(ListAccountsActivity.this, "", "Authenticating...", true);
416
			dialog.setCancelable(true);
417
			dialog.setOnCancelListener(new OnCancelListener() {
418
				
419
				@Override
420
				public void onCancel(DialogInterface dialog) {
421
					if(authTask != null){ 
422
						authTask.cancel(true);
423
					}
424
					if(imageTask != null){
425
						imageTask.cancel(true);
426
					}
427
					if(flavorTask != null){
428
						flavorTask.cancel(true);
429
					}
430
					hideDialog();
431
				}
432
			});
412 433
		}
413 434
    }
414 435
    
......
428 449

  
429 450
		@Override
430 451
		protected Boolean doInBackground(Void... arg0) {
452
			if(isCancelled()){
453
				return false;
454
			}
431 455
			return new Boolean(Authentication.authenticate(context));
432 456
			//return true;
433 457
		}
......
436 460
		protected void onPostExecute(Boolean result) {
437 461
			if (result.booleanValue()) {
438 462
				//startActivity(tabViewIntent);
439
				new LoadImagesTask().execute((Void[]) null);
463
				imageTask = new LoadImagesTask();
464
				imageTask.execute((Void[]) null);
440 465
			} else {
441 466
				hideDialog();
442 467
				showAlert("Login Failure", "Authentication failed.  Please check your User Name and API Key.");
......
453 478

  
454 479
		@Override
455 480
		protected void onPostExecute(ArrayList<Flavor> result) {
481
			if(isCancelled()){
482
				return;
483
			}
484
			
456 485
			if (result != null && result.size() > 0) {
457 486
				TreeMap<String, Flavor> flavorMap = new TreeMap<String, Flavor>();
458 487
				for (int i = 0; i < result.size(); i++) {
......
460 489
					flavorMap.put(flavor.getId(), flavor);
461 490
				}
462 491
				Flavor.setFlavors(flavorMap);
492
				if(isCancelled()){
493
					return;
494
				}
463 495
				hideDialog();
464 496
				startActivityForResult(tabViewIntent, 187);
465 497
			} else {
......
478 510

  
479 511
		@Override
480 512
		protected void onPostExecute(ArrayList<Image> result) {
513
			if(isCancelled()){
514
				return;
515
			}
516
			
481 517
			if (result != null && result.size() > 0) {
482 518
				TreeMap<String, Image> imageMap = new TreeMap<String, Image>();
483 519
				for (int i = 0; i < result.size(); i++) {
......
485 521
					imageMap.put(image.getId(), image);
486 522
				}
487 523
				Image.setImages(imageMap);
488
				new LoadFlavorsTask().execute((Void[]) null);
489
				//startActivity(tabViewIntent);
524
				
525
				if(isCancelled()){
526
					return;
527
				}
528
				
529
				flavorTask = new LoadFlavorsTask();
530
				flavorTask.execute((Void[]) null);
490 531
			} else {
491 532
				hideDialog();
492 533
				showAlert("Login Failure", "There was a problem loading server images.  Please try again.");

Also available in: Unified diff