Revision 51938302 src/com/rackspacecloud/android/ContainerObjectsActivity.java

b/src/com/rackspacecloud/android/ContainerObjectsActivity.java
67 67
	private Context context;
68 68
	private String currentPath;
69 69
	private ContainerObjects[] curDirFiles;
70
	ProgressDialog dialog;
70
	//private ProgressDialog dialog;
71
	private boolean loadingFiles;
72
	private FileAdapter adapter;
73

  
71 74

  
72 75
	@Override
73 76
	public void onCreate(Bundle savedInstanceState) {
......
89 92
		outState.putSerializable("container", files);
90 93
		outState.putString("path", currentPath);
91 94
		outState.putSerializable("curFiles", curDirFiles);
95
		outState.putBoolean("loadingFiles", loadingFiles);
92 96
	}
97
	
98
	
93 99

  
94 100
	private void restoreState(Bundle state) {
101
		
102
		adapter = (FileAdapter)getLastNonConfigurationInstance();
103
		
95 104
		if(state != null){
96 105
			if(state.containsKey("path")){
97 106
				currentPath = state.getString("path");
......
99 108
			else{
100 109
				currentPath = "";
101 110
			}
102
			if(state.containsKey("container") && state.containsKey("curFiles")){
103
				files = (ContainerObjects[]) state.getSerializable("container");
104
				curDirFiles = (ContainerObjects[]) state.getSerializable("curFiles");
105
				if(curDirFiles.length == 0){
106
					displayNoServersCell();
107
				} else {
108
					getListView().setDividerHeight(1); //restore divider lines
109
					setListAdapter(new FileAdapter());
111
			
112
			if(state.containsKey("loadingFiles") && state.getBoolean("loadingFiles")){
113
				loadFiles();
114
			}
115
			else{
116
				if(state.containsKey("container") && state.containsKey("curFiles")){
117
					files = (ContainerObjects[]) state.getSerializable("container");
118
					curDirFiles = (ContainerObjects[]) state.getSerializable("curFiles");
119
					if(curDirFiles != null){
120
						if(curDirFiles.length == 0){
121
							displayNoServersCell();
122
						} else {
123
							Log.d("info", "captin curDirFiles lenght is: " + curDirFiles.length);
124
							getListView().setDividerHeight(1); //restore divider lines
125
							setListAdapter(new FileAdapter());
126
						}
127
					}
110 128
				}
111 129
			}
112 130
		}
......
115 133
			loadFiles();
116 134
		}	
117 135
	}
136
	
137
	public Object onRetainNonConfigurationInstance(){
138
		return adapter;
139
	}
118 140

  
119 141
	/*
120 142
	 * overriding back button press, because we are not actually changing
......
138 160
		displayCurrentFiles();
139 161
	}
140 162

  
141
	
142 163
	/*
164
	 * load all file that are in the container
165
	 */
143 166
	private void loadFiles() {
144
		//displayLoadingCell();
167
		displayLoadingCell();
145 168
		new LoadFilesTask().execute();
146 169
	}
147
	*/
148 170
	
149
	private void loadFiles(){
150
		CloudServersException exception = null;
151

  
152
		ArrayList<ContainerObjects> result = null;
153
		try {
154
			result = (new ContainerObjectManager(context)).createList(true,
155
					container.getName());
156
		} catch (CloudServersException e) {
157
			exception = e;
158
			e.printStackTrace();
159
		}
160
		if (exception != null) {
161
			showAlert("Error", exception.getMessage());
162
		}
163
		setFileList(result);
171
	private void displayLoadingCell() {
172
		String a[] = new String[1];
173
		a[0] = "Loading...";
174
		setListAdapter(new ArrayAdapter<String>(this, R.layout.loadingcell,
175
				R.id.loading_label, a));
176
		getListView().setTextFilterEnabled(true);
177
		getListView().setDividerHeight(0); // hide the dividers so it won't look
178
											// like a list row
179
		getListView().setItemsCanFocus(false);
164 180
	}
165

  
166

  
167

  
168 181
	
169 182
	/* load only the files that should display for the 
170 183
	 * current directory in the curDirFiles[]
......
227 240
	}
228 241
	
229 242
	private void displayCurrentFiles(){
230
		if(curDirFiles!=null)
231 243
		loadCurrentDirectoryFiles();
232 244
		if (curDirFiles.length == 0) {
233 245
			displayNoServersCell();
234 246
		} else {
235 247
			getListView().setDividerHeight(1); // restore divider lines
236
			setListAdapter(new FileAdapter());
248
			adapter = new FileAdapter();
249
			setListAdapter(adapter);
237 250
		}
238 251
	}
239 252

  
......
429 442
					public void onClick(DialogInterface dialog,
430 443
							int whichButton) {
431 444
						// User clicked OK so do some stuff
432
						new DeleteObjectTask()
433
						.execute();
445
						new DeleteObjectTask().execute();
434 446
					}
435 447
				})
436 448
				.setNegativeButton("Cancel",
......
535 547
	
536 548
		public View getView(int position, View convertView, ViewGroup parent) {
537 549
	
550
			Log.d("info", "captin updating position " + position);
551
			
538 552
			ContainerObjects file = curDirFiles[position];
539 553
			LayoutInflater inflater = getLayoutInflater();
540 554
			View row = inflater.inflate(R.layout.listcontainerobjectcell,
......
563 577

  
564 578
	private class LoadFilesTask extends
565 579
			AsyncTask<String, Void, ArrayList<ContainerObjects>> {
566
	
580

  
567 581
		private CloudServersException exception;
568
		/*
569 582
		protected void onPreExecute(){
570
			dialog = ProgressDialog.show(ContainerObjectsActivity.this, "", "Loading Files...", true);
583
			loadingFiles = true;
571 584
		}
572
		*/
585
		
573 586
		@Override
574 587
		protected ArrayList<ContainerObjects> doInBackground(String... path) {
575 588
			ArrayList<ContainerObjects> files = null;
......
590 603
				showAlert("Error", exception.getMessage());
591 604
			}
592 605
			setFileList(result);
606
			loadingFiles = false;
593 607
		}
608

  
594 609
	}
595 610

  
596 611
	private class DeleteObjectTask extends
......
599 614
		private CloudServersException exception;
600 615
		
601 616
		protected void onPreExecute(){
602
			dialog = ProgressDialog.show(ContainerObjectsActivity.this, "", "Deleting...", true);
617
			//dialog = ProgressDialog.show(ContainerObjectsActivity.this, "", "Deleting...", true);
603 618
		}
604 619
		
605 620
		@Override
......
616 631

  
617 632
		@Override
618 633
		protected void onPostExecute(HttpResponse response) {
619
			dialog.dismiss();
634
			//dialog.dismiss();
620 635
			if (response != null) {
621 636
				int statusCode = response.getStatusLine().getStatusCode();
622 637
				if (statusCode == 409) {

Also available in: Unified diff