commit 21c577997bc1df1a08e0dac3a0bf95ddbcfe832f
Author: Adam Menz <adam.menz@rackspace.com>
Date:   Tue Aug 9 15:24:54 2011 -0500

    bug fixes for load balancer operations

diff --git a/res/layout/connectionthrottle.xml b/res/layout/connectionthrottle.xml
index 654de36..4a239e1 100644
--- a/res/layout/connectionthrottle.xml
+++ b/res/layout/connectionthrottle.xml
@@ -85,7 +85,7 @@
 					android:text="Seconds"></TextView>
 			</LinearLayout>
 		</LinearLayout>
-		<LinearLayout android:layout_width="fill_parent" android:id="@+id/linearLayout3" android:gravity="center" android:layout_height="wrap_content" android:layout_marginTop="10dip">
+		<LinearLayout android:layout_width="fill_parent" android:id="@+id/linearLayout3" android:gravity="center" android:layout_height="wrap_content" android:layout_marginTop="10dip" android:layout_marginBottom="10dip">
 			<Button android:layout_height="wrap_content" android:layout_gravity="center" android:layout_width="120dip" android:layout_marginRight="5dip" android:id="@+id/enable_throttle_button" android:text="Disable Throttle" android:lines="2"></Button>
 			<Button android:id="@+id/save_throttle_button" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_width="120dip" android:layout_marginLeft="5dip" android:text="Save Throttle Settings"></Button>
 		</LinearLayout>
diff --git a/src/com/rackspacecloud/android/AccessControlActivity.java b/src/com/rackspacecloud/android/AccessControlActivity.java
index 1478a0c..e676ff5 100644
--- a/src/com/rackspacecloud/android/AccessControlActivity.java
+++ b/src/com/rackspacecloud/android/AccessControlActivity.java
@@ -136,6 +136,15 @@ public class AccessControlActivity extends CloudListActivity {
 			setListAdapter(new NetworkItemAdapter());
 		}
 	}
+	
+	 private void displayLoadingCell() {
+	    	String a[] = new String[1];
+	    	a[0] = "Loading...";
+	        setListAdapter(new ArrayAdapter<String>(this, R.layout.loadingcell, R.id.loading_label, a));
+	        getListView().setTextFilterEnabled(true);
+	        getListView().setDividerHeight(0); // hide the dividers so it won't look like a list row
+	        getListView().setItemsCanFocus(false);
+	    }
 
 	private void displayNoRulesCell() {
 		String a[] = new String[1];
@@ -147,6 +156,7 @@ public class AccessControlActivity extends CloudListActivity {
 	}
 
 	private void loadNetworkItems() {
+		displayLoadingCell();
 		new LoadNetworkItemsTask().execute((Void[]) null);
 	}
 
@@ -187,7 +197,8 @@ public class AccessControlActivity extends CloudListActivity {
 
 		@Override
 		protected void onPreExecute(){
-			showDialog();
+			//set to null so will reload on config changes
+			networkItems = null;
 		}
 
 		@Override
@@ -203,7 +214,6 @@ public class AccessControlActivity extends CloudListActivity {
 
 		@Override
 		protected void onPostExecute(ArrayList<NetworkItem> result) {
-			hideDialog();
 			if (exception != null) {
 				showAlert("Error", exception.getMessage());
 			}
@@ -214,17 +224,21 @@ public class AccessControlActivity extends CloudListActivity {
 	private class DeleteNetworkItemTask extends AsyncTask<Void, Void, HttpBundle> {
 
 			private CloudServersException exception;
+			private NetworkItem networkItem;
 
 			@Override
 			//let user know their process has started
 			protected void onPreExecute(){
-				showDialog();
+				networkItem = networkItems.get(lastSelectedRulePosition);
+				displayLoadingCell();
+				//set to null so will reload on config change
+				networkItems = null;
 			}
 			@Override
 			protected HttpBundle doInBackground(Void... arg0) {
 				HttpBundle bundle = null;
 				try {
-					bundle = new NetworkItemManager(getContext()).delete(loadBalancer, networkItems.get(lastSelectedRulePosition));
+					bundle = new NetworkItemManager(getContext()).delete(loadBalancer, networkItem);
 				} catch (CloudServersException e) {
 					exception = e;
 				}
@@ -233,7 +247,6 @@ public class AccessControlActivity extends CloudListActivity {
 
 			@Override
 			protected void onPostExecute(HttpBundle bundle) {
-				hideDialog();
 				HttpResponse response = bundle.getResponse();
 				if (response != null) {
 					int statusCode = response.getStatusLine().getStatusCode();
diff --git a/src/com/rackspacecloud/android/AndroidCloudApplication.java b/src/com/rackspacecloud/android/AndroidCloudApplication.java
index f7c3889..70812c3 100644
--- a/src/com/rackspacecloud/android/AndroidCloudApplication.java
+++ b/src/com/rackspacecloud/android/AndroidCloudApplication.java
@@ -20,6 +20,8 @@ public class AndroidCloudApplication extends Application {
 	private boolean deletingObjectProcessing;
 	private boolean deletingContainerProcessing;
 	private boolean downloadingObject;
+	private boolean isSettingLogs;
+	private boolean isSettingSessionPersistence;
 	private HttpEntity downloadedObject;
 	private ArrayList<ContainerObjects> curDirFiles;
 	
@@ -82,4 +84,20 @@ public class AndroidCloudApplication extends Application {
 	public boolean isLoggingIn(){
 		return isLoggingIn;
 	}
+	
+	public void setIsSettingLogs(Boolean logging){
+		isSettingLogs = logging;
+	}
+	
+	public boolean isSettingLogs(){
+		return isSettingLogs;
+	}
+	
+	public void setSettingSessionPersistence(Boolean setting){
+		isSettingSessionPersistence = setting;
+	}
+	
+	public boolean isSettingSessionPersistence(){
+		return isSettingSessionPersistence;
+	}
 }
diff --git a/src/com/rackspacecloud/android/CloudActivity.java b/src/com/rackspacecloud/android/CloudActivity.java
index 11716ef..12fed40 100644
--- a/src/com/rackspacecloud/android/CloudActivity.java
+++ b/src/com/rackspacecloud/android/CloudActivity.java
@@ -26,6 +26,7 @@ import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.DialogInterface.OnCancelListener;
 import android.os.Bundle;
+import android.util.Log;
 import android.view.WindowManager;
 import android.view.ViewGroup.LayoutParams;
 import android.widget.ProgressBar;
@@ -160,6 +161,7 @@ public abstract class CloudActivity extends GaActivity{
 
 	protected final void hideDialog() {
 		if(pDialog != null){
+			Log.d("info", "dialog hide");
 			isLoading = false;
 			pDialog.dismiss();
 		}
@@ -167,6 +169,7 @@ public abstract class CloudActivity extends GaActivity{
 
 	protected final void showDialog() {
 		if(pDialog == null || !pDialog.isShowing()){
+			Log.d("info", "dialog created");
 			isLoading = true;
 			pDialog = new ProgressDialog(this);
 			pDialog.setProgressStyle(R.style.NewDialog);
diff --git a/src/com/rackspacecloud/android/CloudListActivity.java b/src/com/rackspacecloud/android/CloudListActivity.java
index 3f52037..b02a43b 100644
--- a/src/com/rackspacecloud/android/CloudListActivity.java
+++ b/src/com/rackspacecloud/android/CloudListActivity.java
@@ -26,6 +26,7 @@ import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.DialogInterface.OnCancelListener;
 import android.os.Bundle;
+import android.util.Log;
 import android.view.WindowManager;
 import android.view.ViewGroup.LayoutParams;
 import android.widget.ProgressBar;
@@ -160,6 +161,7 @@ public class CloudListActivity extends GaListActivity{
 
 	protected final void hideDialog() {
 		if(pDialog != null){
+			Log.d("info", "dialog hide");
 			isLoading = false;
 			pDialog.dismiss();
 		}
@@ -167,6 +169,7 @@ public class CloudListActivity extends GaListActivity{
 
 	protected final void showDialog() {
 		if(pDialog == null || !pDialog.isShowing()){
+			Log.d("info", "dialog created");
 			isLoading = true;
 			pDialog = new ProgressDialog(this);
 			pDialog.setProgressStyle(R.style.NewDialog);
diff --git a/src/com/rackspacecloud/android/ConnectionThrottleActivity.java b/src/com/rackspacecloud/android/ConnectionThrottleActivity.java
index 1e9a619..7e28c46 100644
--- a/src/com/rackspacecloud/android/ConnectionThrottleActivity.java
+++ b/src/com/rackspacecloud/android/ConnectionThrottleActivity.java
@@ -43,13 +43,14 @@ public class ConnectionThrottleActivity extends CloudActivity{
 		outState.putSerializable("loadBalancer", loadBalancer);
 	}
 
-	
+
 	protected void restoreState(Bundle state) {
 		super.restoreState(state);
 
 		if(state != null && state.containsKey("loadBalancer")){
 			loadBalancer = (LoadBalancer)state.getSerializable("loadBalancer");
 		}
+		connectionThrottle = loadBalancer.getConnectionThrottle();
 		minCons = (EditText)findViewById(R.id.min_connections_text);
 		maxCons = (EditText)findViewById(R.id.max_connections_text);
 		maxConRate = (EditText)findViewById(R.id.max_connection_rate);
@@ -76,7 +77,7 @@ public class ConnectionThrottleActivity extends CloudActivity{
 					connectionThrottle.setMaxConnections("100");
 					connectionThrottle.setMaxConnectionRate("25");
 					connectionThrottle.setRateInterval("5");
-					
+
 					loadBalancer.setConnectionThrottle(connectionThrottle);
 					//Turn on EditTexts
 					minCons.setEnabled(true);			
@@ -115,13 +116,7 @@ public class ConnectionThrottleActivity extends CloudActivity{
 						new UpdateConnectionThrottleTask().execute();
 					}
 				} else {
-					//if there was no connection throttle before
-					//then no need to delete it
-					if(loadBalancer.getConnectionThrottle() != null){
-						new DeleteConnectionThrottleTask().execute();
-					} else {
-						finish();
-					}
+					new DeleteConnectionThrottleTask().execute();
 				}
 			}
 		}); 
@@ -165,7 +160,6 @@ public class ConnectionThrottleActivity extends CloudActivity{
 		} else {
 			try {
 				int value = Integer.parseInt(result);
-				Log.d("info", min + " <= " + value + " <= " + max);
 				if(value >= min && value <= max){
 					return true;
 				} else {
diff --git a/src/com/rackspacecloud/android/ViewLoadBalancerActivity.java b/src/com/rackspacecloud/android/ViewLoadBalancerActivity.java
index f2178c3..f723ed2 100644
--- a/src/com/rackspacecloud/android/ViewLoadBalancerActivity.java
+++ b/src/com/rackspacecloud/android/ViewLoadBalancerActivity.java
@@ -47,12 +47,16 @@ public class ViewLoadBalancerActivity extends CloudActivity {
 
 	private LoadBalancer loadBalancer;
 	private PollLoadBalancerTask pollLoadBalancerTask;
+	private AndroidCloudApplication app;
+	private LoggingListenerTask loggingListenerTask;
+	private SessionPersistenceListenerTask sessionPersistenceListenerTask;
 
 	@Override
 	public void onCreate(Bundle savedInstanceState) {
 		super.onCreate(savedInstanceState);
 		loadBalancer = (LoadBalancer) this.getIntent().getExtras().get("loadBalancer");
 		setContentView(R.layout.view_loadbalancer);
+		app = (AndroidCloudApplication)this.getApplication();
 		restoreState(savedInstanceState);
 	}
 
@@ -64,7 +68,7 @@ public class ViewLoadBalancerActivity extends CloudActivity {
 
 	protected void restoreState(Bundle state) {
 		super.restoreState(state);
-
+		
 		if (state != null && state.containsKey("loadBalancer") && state.getSerializable("loadBalancer") != null) {
 			loadBalancer = (LoadBalancer) state.getSerializable("loadBalancer");
 			loadLoadBalancerData();
@@ -73,6 +77,19 @@ public class ViewLoadBalancerActivity extends CloudActivity {
 		else{
 			new LoadLoadBalancerTask().execute((Void[]) null);
 		}
+		
+		/*
+		 * if is setting logs we need another listener
+		 */
+		if(app.isSettingLogs()){
+			loggingListenerTask = new LoggingListenerTask();
+			loggingListenerTask.execute();
+		}
+		
+		if(app.isSettingSessionPersistence()){
+			sessionPersistenceListenerTask = new SessionPersistenceListenerTask();
+			sessionPersistenceListenerTask.execute();
+		}
 	}
 
 	@Override
@@ -86,6 +103,23 @@ public class ViewLoadBalancerActivity extends CloudActivity {
 		}
 	}
 
+	@Override
+	protected void onStop(){
+		super.onStop();
+
+		/*
+		 * Need to stop running listener task
+		 * if we exit
+		 */
+		if(loggingListenerTask != null){
+			loggingListenerTask.cancel(true);
+		}
+		
+		if(sessionPersistenceListenerTask != null){
+			sessionPersistenceListenerTask.cancel(true);
+		}
+	}
+	
 	private void setupButton(int resourceId, OnClickListener onClickListener) {
 		Button button = (Button) findViewById(resourceId);
 		button.setOnClickListener(onClickListener);
@@ -275,45 +309,47 @@ public class ViewLoadBalancerActivity extends CloudActivity {
 	//Need to show different message depending on the state
 	//of connection_logs/session_persistence
 	protected void onPrepareDialog(int id, Dialog dialog){
-		switch (id) {
-		case R.id.connection_log_button:
-			String logTitle;
-			String logMessage;
-			String logButton;
-			if(loadBalancer.getIsConnectionLoggingEnabled().equals("true")){
-				logTitle = "Disable Logs";
-				logMessage = "Are you sure you want to disable logs for this Load Balancer?";
-				logButton = "Disable";
-			} else {
-				logTitle = "Enable Logs";
-				logMessage = "Log files will be processed every hour and stored in your Cloud Files account. " +
-				"Standard Cloud Files storage and transfer fees will be accessed for the use of this feature." +
-				"\n\nAre you sure you want to enable logs for this Load Balancer?";
-				logButton = "Enable";
-			}
-			((AlertDialog)dialog).setTitle(logTitle);
-			((AlertDialog)dialog).setMessage(logMessage);
-			Button sessionLogButton = ((AlertDialog)dialog).getButton(AlertDialog.BUTTON1);
-			sessionLogButton.setText(logButton);
-			sessionLogButton.invalidate();
-			break;
-		case R.id.session_persistence_button:
-			String sessionMessage;
-			String sessionButton;
-			if(loadBalancer.getSessionPersistence() != null){
-				Log.d("info", "in sessionpersistence != null");
-				sessionMessage = "Are you sure you want to disable session persistence for this Load Balancer?";
-				sessionButton = "Disable";
-			} else {
-				Log.d("info", "in sessionpersistence == null");
-				sessionMessage = "Are you sure you want to enable session persistence for this Load Balancer?";
-				sessionButton = "Enable";
+		if(loadBalancer != null){
+			switch (id) {
+			case R.id.connection_log_button:
+				String logTitle;
+				String logMessage;
+				String logButton;
+				if(loadBalancer.getIsConnectionLoggingEnabled().equals("true")){
+					logTitle = "Disable Logs";
+					logMessage = "Are you sure you want to disable logs for this Load Balancer?";
+					logButton = "Disable";
+				} else {
+					logTitle = "Enable Logs";
+					logMessage = "Log files will be processed every hour and stored in your Cloud Files account. " +
+					"Standard Cloud Files storage and transfer fees will be accessed for the use of this feature." +
+					"\n\nAre you sure you want to enable logs for this Load Balancer?";
+					logButton = "Enable";
+				}
+				((AlertDialog)dialog).setTitle(logTitle);
+				((AlertDialog)dialog).setMessage(logMessage);
+				Button sessionLogButton = ((AlertDialog)dialog).getButton(AlertDialog.BUTTON1);
+				sessionLogButton.setText(logButton);
+				sessionLogButton.invalidate();
+				break;
+			case R.id.session_persistence_button:
+				String sessionMessage;
+				String sessionButton;
+				if(loadBalancer.getSessionPersistence() != null){
+					Log.d("info", "in sessionpersistence != null");
+					sessionMessage = "Are you sure you want to disable session persistence for this Load Balancer?";
+					sessionButton = "Disable";
+				} else {
+					Log.d("info", "in sessionpersistence == null");
+					sessionMessage = "Are you sure you want to enable session persistence for this Load Balancer?";
+					sessionButton = "Enable";
+				}
+				((AlertDialog)dialog).setMessage(sessionMessage);
+				Button sessionPersistButton = ((AlertDialog)dialog).getButton(AlertDialog.BUTTON1);
+				sessionPersistButton.setText(sessionButton);
+				sessionPersistButton.invalidate();
+				break;
 			}
-			((AlertDialog)dialog).setMessage(sessionMessage);
-			Button sessionPersistButton = ((AlertDialog)dialog).getButton(AlertDialog.BUTTON1);
-			sessionPersistButton.setText(sessionButton);
-			sessionPersistButton.invalidate();
-			break;
 		}
 	}
 
@@ -596,7 +632,10 @@ public class ViewLoadBalancerActivity extends CloudActivity {
 
 		@Override
 		protected void onPreExecute(){
-			showDialog();
+			//showDialog();
+			app.setIsSettingLogs(true);
+			loggingListenerTask = new LoggingListenerTask();
+			loggingListenerTask.execute();
 		}
 
 		@Override
@@ -612,13 +651,17 @@ public class ViewLoadBalancerActivity extends CloudActivity {
 
 		@Override
 		protected void onPostExecute(HttpBundle bundle) {
-			hideDialog();
+			//hideDialog();
+			app.setIsSettingLogs(false);
 			HttpResponse response = bundle.getResponse();
 			if (response != null) {
 				int statusCode = response.getStatusLine().getStatusCode();			
 				if (statusCode == 202 || statusCode == 204) {
-					pollLoadBalancerTask = new PollLoadBalancerTask();
-					pollLoadBalancerTask.execute((Void[]) null);
+					if(Boolean.valueOf(loadBalancer.getIsConnectionLoggingEnabled())){
+						showToast("Logging has been disabled");
+					} else {
+						showToast("Logging has been enabled");
+					}
 				} else {					
 					CloudServersException cse = parseCloudServersException(response);
 					if ("".equals(cse.getMessage())) {
@@ -635,13 +678,47 @@ public class ViewLoadBalancerActivity extends CloudActivity {
 		}
 	}
 
+	/*
+	 * listens for the application to change isSettingLogs
+	 * listens so activity knows when it should display
+	 * the new settings
+	 */
+	private class LoggingListenerTask extends
+	AsyncTask<Void, Void, Void> {
+
+		@Override
+		protected Void doInBackground(Void... arg1) {
+
+			while(app.isSettingLogs()){
+				// wait for process to finish
+				// or have it be canceled
+				if(loggingListenerTask.isCancelled()){
+					return null;
+				}
+			}
+			return null;
+		}
+
+		/*
+		 * when no longer processing, time to load
+		 * the new files
+		 */
+		@Override
+		protected void onPostExecute(Void arg1) {
+			pollLoadBalancerTask = new PollLoadBalancerTask();
+			pollLoadBalancerTask.execute((Void[]) null);
+		}
+	}
+	
 	private class SessionPersistenceTask extends AsyncTask<Void, Void, HttpBundle> {
 
 		private CloudServersException exception;
-
+		
 		@Override
 		protected void onPreExecute(){
-			showDialog();
+			app.setSettingSessionPersistence(true);
+			sessionPersistenceListenerTask = new SessionPersistenceListenerTask();
+			sessionPersistenceListenerTask.execute();
 		}
 
 		@Override
@@ -659,14 +736,20 @@ public class ViewLoadBalancerActivity extends CloudActivity {
 			}
 			return bundle;
 		}
-
+		
 		@Override
 		protected void onPostExecute(HttpBundle bundle) {
-			hideDialog();
+			//hideDialog();
+			app.setSettingSessionPersistence(false);
 			HttpResponse response = bundle.getResponse();
 			if (response != null) {
 				int statusCode = response.getStatusLine().getStatusCode();			
 				if (statusCode == 202 || statusCode == 200) {
+					if(loadBalancer.getSessionPersistence() != null){
+						showToast("Session Persistence has been disabled");
+					} else {
+						showToast("Session Persistence has been enabled");
+					}
 					pollLoadBalancerTask = new PollLoadBalancerTask();
 					pollLoadBalancerTask.execute((Void[]) null);
 				} else {					
@@ -684,6 +767,38 @@ public class ViewLoadBalancerActivity extends CloudActivity {
 
 		}
 	}
+	
+	/*
+	 * listens for the application to change isSettingSessionPersistence
+	 * listens so activity knows when it should display
+	 * the new settings
+	 */
+	private class SessionPersistenceListenerTask extends
+	AsyncTask<Void, Void, Void> {
+
+		@Override
+		protected Void doInBackground(Void... arg1) {
+
+			while(app.isSettingSessionPersistence()){
+				// wait for process to finish
+				// or have it be canceled
+				if(sessionPersistenceListenerTask.isCancelled()){
+					return null;
+				}
+			}
+			return null;
+		}
+
+		/*
+		 * when no longer processing, time to load
+		 * the new files
+		 */
+		@Override
+		protected void onPostExecute(Void arg1) {
+			pollLoadBalancerTask = new PollLoadBalancerTask();
+			pollLoadBalancerTask.execute((Void[]) null);
+		}
+	}
 
 
 }
