Revision d3ea294b

b/AndroidManifest.xml
92 92
			</intent-filter>
93 93
		</activity>
94 94
		<activity android:name=".AddAccountActivity"></activity>
95
		<activity android:name=".AddFileActivity"></activity>
95 96

  
96 97
	</application>
97 98
	<uses-sdk android:minSdkVersion="4" />
b/res/layout/addtextfile.xml
1
<?xml version="1.0" encoding="utf-8"?>
2

  
3
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/RelativeLayout" android:layout_height="fill_parent" android:layout_width="fill_parent">
4
    <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="Filename" android:id="@+id/filename_textview" android:layout_marginLeft="22dip"></TextView>
5
    <EditText android:id="@+id/file_name_text" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_below="@+id/filename_textview" android:layout_marginLeft="22dip" android:layout_marginRight="30dip"></EditText>
6
    <TextView android:layout_below="@+id/file_name_text" android:layout_height="wrap_content" android:id="@+id/file_contents_view" android:layout_width="wrap_content" android:text="File Content" android:layout_marginLeft="22dip"></TextView>
7
    <EditText android:layout_width="fill_parent" android:id="@+id/new_file_text" android:layout_above="@+id/add_text_file_buttons" android:layout_height="fill_parent" android:layout_below="@+id/file_contents_view" android:layout_marginLeft="22dip" android:layout_marginRight="30dip" android:gravity="top"></EditText>
8
    <LinearLayout android:layout_height="wrap_content" android:id="@+id/add_text_file_buttons" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_alignParentBottom="true">
9
        <Button android:layout_height="wrap_content" android:text="Submit" android:id="@+id/new_file_button" android:layout_gravity="left" android:layout_width="100dip" android:layout_marginLeft="22dip" android:layout_marginTop="10dip"></Button>
10
    </LinearLayout>
11

  
12

  
13
</RelativeLayout>
b/src/com/rackspace/cloud/files/api/client/ContainerObjectManager.java
13 13
import org.apache.http.client.ClientProtocolException;
14 14
import org.apache.http.client.methods.HttpDelete;
15 15
import org.apache.http.client.methods.HttpGet;
16
import org.apache.http.client.methods.HttpPut;
16 17
import org.apache.http.impl.client.BasicResponseHandler;
17 18
import org.apache.http.protocol.RequestExpectContinue;
18 19
import org.xml.sax.InputSource;
......
128 129
		return resp;
129 130
	}
130 131
	
132
	public HttpResponse addObject(String Container, String Path, String Object, String type) throws CloudServersException {
133
		HttpResponse resp = null;
134
		CustomHttpClient httpclient = new CustomHttpClient(context);
135
		HttpPut addObject = new HttpPut(Account.getAccount().getStorageUrl() + "/" + Container + "/" + Path + Object);
136
				
137
		addObject.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
138
		addObject.addHeader("Content-Type", type);
139
		httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class);
140

  
141
		try {			
142
			resp = httpclient.execute(addObject);
143
		} catch (ClientProtocolException e) {
144
			CloudServersException cse = new CloudServersException();
145
			cse.setMessage(e.getLocalizedMessage());
146
			throw cse;
147
		} catch (IOException e) {
148
			CloudServersException cse = new CloudServersException();
149
			cse.setMessage(e.getLocalizedMessage());
150
			throw cse;
151
		} catch (FactoryConfigurationError e) {
152
			CloudServersException cse = new CloudServersException();
153
			cse.setMessage(e.getLocalizedMessage());
154
			throw cse;
155
		}	
156
		return resp;
157
	}
158
	
159
	/*
160
	 * used for adding text files, requires an extra parameter to 
161
	 * store the data for the file
162
	 */
163
	public HttpResponse addObject(String Container, String Path, String Object, String type, String data) throws CloudServersException {
164
		HttpResponse resp = null;
165
		CustomHttpClient httpclient = new CustomHttpClient(context);
166
		HttpPut addObject = new HttpPut(Account.getAccount().getStorageUrl() + "/" + Container + "/" + Path + Object);
167
				
168
		addObject.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
169
		addObject.addHeader("Content-Type", type);
170
		httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class);
171

  
172
		try {			
173
			resp = httpclient.execute(addObject);
174
		} catch (ClientProtocolException e) {
175
			CloudServersException cse = new CloudServersException();
176
			cse.setMessage(e.getLocalizedMessage());
177
			throw cse;
178
		} catch (IOException e) {
179
			CloudServersException cse = new CloudServersException();
180
			cse.setMessage(e.getLocalizedMessage());
181
			throw cse;
182
		} catch (FactoryConfigurationError e) {
183
			CloudServersException cse = new CloudServersException();
184
			cse.setMessage(e.getLocalizedMessage());
185
			throw cse;
186
		}	
187
		return resp;
188
	}
131 189

  
132 190
}
b/src/com/rackspacecloud/android/AddFileActivity.java
1
package com.rackspacecloud.android;
2

  
3
import java.io.IOException;
4
import java.io.StringReader;
5

  
6
import javax.xml.parsers.FactoryConfigurationError;
7
import javax.xml.parsers.ParserConfigurationException;
8
import javax.xml.parsers.SAXParser;
9
import javax.xml.parsers.SAXParserFactory;
10

  
11
import org.apache.http.HttpResponse;
12
import org.apache.http.client.ClientProtocolException;
13
import org.apache.http.impl.client.BasicResponseHandler;
14
import org.xml.sax.InputSource;
15
import org.xml.sax.SAXException;
16
import org.xml.sax.XMLReader;
17

  
18
import com.rackspace.cloud.files.api.client.ContainerObjectManager;
19
import com.rackspace.cloud.servers.api.client.CloudServersException;
20
import com.rackspace.cloud.servers.api.client.parsers.CloudServersFaultXMLParser;
21

  
22
import android.app.Activity;
23
import android.content.Context;
24
import android.os.AsyncTask;
25
import android.os.Bundle;
26
import android.view.View;
27
import android.view.View.OnClickListener;
28
import android.widget.Button;
29
import android.widget.EditText;
30

  
31
public class AddFileActivity extends Activity implements OnClickListener{
32
	
33
	private Context context;	
34
	private EditText fileName;
35
	private EditText contents;
36
	private String containerName;
37
	private String path;
38

  
39
	/** Called when the activity is first created. */
40
    @Override
41
    public void onCreate(Bundle savedInstanceState) {
42
        super.onCreate(savedInstanceState);
43
        setContentView(R.layout.addtextfile);
44
        context = getApplicationContext();
45
        containerName = (String) this.getIntent().getExtras().get("Cname");
46
        path = (String) this.getIntent().getExtras().get("curPath");
47
        setUpInputs();
48
    }
49
    
50
    private void setUpInputs(){
51
    	((Button) findViewById(R.id.save_button)).setOnClickListener(this);
52
    	fileName = ((EditText)findViewById(R.id.file_name_text));
53
    	contents = ((EditText)findViewById(R.id.new_file_text));
54
    }
55
    
56
    public void onClick(View arg0) {
57
		if ("".equals(fileName.getText().toString())) {
58
			showAlert("Required Fields Missing", " File name is required.");
59
		} else {
60
			//showActivityIndicators();
61
			new SaveFileTask().execute((Void[]) null);
62
		}
63
	}
64
    
65
    //using cloudServersException, it works for us too
66
	private CloudServersException parseCloudServersException(HttpResponse response) {
67
		CloudServersException cse = new CloudServersException();
68
		try {
69
		    BasicResponseHandler responseHandler = new BasicResponseHandler();
70
		    String body = responseHandler.handleResponse(response);
71
	    	CloudServersFaultXMLParser parser = new CloudServersFaultXMLParser();
72
	    	SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
73
	    	XMLReader xmlReader = saxParser.getXMLReader();
74
	    	xmlReader.setContentHandler(parser);
75
	    	xmlReader.parse(new InputSource(new StringReader(body)));		    	
76
	    	cse = parser.getException();		    	
77
		} catch (ClientProtocolException e) {
78
			cse = new CloudServersException();
79
			cse.setMessage(e.getLocalizedMessage());
80
		} catch (IOException e) {
81
			cse = new CloudServersException();
82
			cse.setMessage(e.getLocalizedMessage());
83
		} catch (ParserConfigurationException e) {
84
			cse = new CloudServersException();
85
			cse.setMessage(e.getLocalizedMessage());
86
		} catch (SAXException e) {
87
			cse = new CloudServersException();
88
			cse.setMessage(e.getLocalizedMessage());
89
		} catch (FactoryConfigurationError e) {
90
			cse = new CloudServersException();
91
			cse.setMessage(e.getLocalizedMessage());
92
		}
93
		return cse;
94
	}
95
	
96
	private void showAlert(String title, String message) {
97
		/*
98
		AlertDialog alert = new AlertDialog.Builder(this).create();
99
		alert.setTitle(title);
100
		alert.setMessage(message);
101
		alert.setButton("OK", new DialogInterface.OnClickListener() {
102
	      public void onClick(DialogInterface dialog, int which) {
103
	        return;
104
	    } }); 
105
		alert.show();
106
		hideActivityIndicators();
107
		*/
108
    }
109

  
110
	private class SaveFileTask extends AsyncTask<Void, Void, HttpResponse> {
111
    	private CloudServersException exception;
112
    	
113
    	@Override
114
		protected HttpResponse doInBackground(Void... arg0) {
115
			HttpResponse resp = null;
116
			try {
117
				resp = (new ContainerObjectManager(context)).addObject(containerName, path, fileName.getText().toString(), "text/plain", contents.getText().toString());
118
			} catch (CloudServersException e) {
119
				exception = e;
120
			}
121
			return resp;
122
		}
123
    	
124
		@Override
125
		protected void onPostExecute(HttpResponse response) {
126
			if (response != null) {
127
				int statusCode = response.getStatusLine().getStatusCode();
128
				if (statusCode == 201) {
129
					setResult(Activity.RESULT_OK);
130
					finish();
131
				} else {
132
					CloudServersException cse = parseCloudServersException(response);
133
					if ("".equals(cse.getMessage())) {
134
						showAlert("Error", "There was a problem creating your container.");
135
					} else {
136
						showAlert("Error", "There was a problem creating your container: " + cse.getMessage() + " Check container name and try again");
137
					}
138
				}
139
			} else if (exception != null) {
140
				showAlert("Error", "There was a problem creating your container: " + exception.getMessage()+" Check container name and try again");				
141
			}			
142
		}
143
    }
144
}
b/src/com/rackspacecloud/android/ContainerObjectDetails.java
21 21
import android.app.Activity;
22 22
import android.app.AlertDialog;
23 23
import android.app.Dialog;
24
import android.app.ProgressDialog;
24 25
import android.content.Context;
25 26
import android.content.DialogInterface;
26 27
import android.content.Intent;
......
61 62
	private double kiloBytes;
62 63
	public Button previewButton;
63 64
	public Context context;
65
	ProgressDialog dialog;
64 66
	
65 67
    /** Called when the activity is first created. */
66 68
    @Override
......
263 265
	    	 private class ContainerObjectDeleteTask extends AsyncTask<Void, Void, HttpResponse> {
264 266
	    	    	
265 267
	    			private CloudServersException exception;
268
	    			
269
	    			protected void onPreExecute(){
270
	    				dialog = ProgressDialog.show(ContainerObjectDetails.this, "", "Deleting...", true);
271
	    			}
266 272

  
267 273
	    			@Override
268 274
	    			protected HttpResponse doInBackground(Void... arg0) {
......
278 284
	    	    	
279 285
	    			@Override
280 286
	    			protected void onPostExecute(HttpResponse response) {
287
	    				dialog.dismiss();
281 288
	    				if (response != null) {
282 289
	    					int statusCode = response.getStatusLine().getStatusCode();
283 290
	    					if (statusCode == 204) {
b/src/com/rackspacecloud/android/ContainerObjectsActivity.java
3 3
import java.io.IOException;
4 4
import java.io.StringReader;
5 5
import java.util.ArrayList;
6
import java.util.Arrays;
6 7

  
7 8
import javax.xml.parsers.FactoryConfigurationError;
8 9
import javax.xml.parsers.ParserConfigurationException;
......
20 21
import android.app.AlertDialog;
21 22
import android.app.Dialog;
22 23
import android.app.ListActivity;
24
import android.app.ProgressDialog;
23 25
import android.content.Context;
24 26
import android.content.DialogInterface;
25 27
import android.content.Intent;
......
33 35
import android.view.View;
34 36
import android.view.ViewGroup;
35 37
import android.widget.ArrayAdapter;
38
import android.widget.EditText;
36 39
import android.widget.ListView;
37 40
import android.widget.TextView;
38 41

  
......
42 45
import com.rackspace.cloud.files.api.client.ContainerObjects;
43 46
import com.rackspace.cloud.servers.api.client.CloudServersException;
44 47
import com.rackspace.cloud.servers.api.client.parsers.CloudServersFaultXMLParser;
48
//import com.rackspacecloud.android.ViewServerActivity.RenameServerTask;
45 49

  
46 50
/**
47 51
 * 
......
63 67
	private Context context;
64 68
	private String currentPath;
65 69
	private ContainerObjects[] curDirFiles;
70
	ProgressDialog dialog;
66 71

  
67 72
	@Override
68 73
	public void onCreate(Bundle savedInstanceState) {
......
83 88
		super.onSaveInstanceState(outState);
84 89
		outState.putSerializable("container", files);
85 90
		outState.putString("path", currentPath);
91
		outState.putSerializable("curFiles", curDirFiles);
86 92
	}
87 93

  
88 94
	private void restoreState(Bundle state) {
89
		getPath();
90
		
91
		if (state != null && state.containsKey("container")) {
92
			files = (ContainerObjects[]) state.getSerializable("container");
93
			if (files.length == 0) {
94
				displayNoServersCell();
95
			} else {
96
				getListView().setDividerHeight(1); // restore divider lines
97
				setListAdapter(new FileAdapter());
95
		if(state != null){
96
			if(state.containsKey("path")){
97
				currentPath = state.getString("path");
98 98
			}
99
		} 
100
		else {
101
			loadFiles();
102
		}
103
	}
104

  
105
	protected void onListItemClick(ListView l, View v, int position, long id) {
106
		if (curDirFiles != null && curDirFiles.length > 0) {
107
			Intent viewIntent;
108
			if(curDirFiles[position].getContentType().equals("application/directory")){
109
				/*
110
				viewIntent = new Intent(this, ContainerObjectsActivity.class);
111
				viewIntent.putExtra("container", container);
112
				viewIntent.putExtra("cdnUrl", container.getCdnUrl());
113
				viewIntent.putExtra("containerNames", container.getName());
114
				viewIntent.putExtra("isCdnEnabled", cdnEnabledIs);
115
				viewIntent.putExtra("path", files[position].getCName());
116
				Log.d("the path name is: ","captin " + files[position].getCName());
117
				startActivityForResult(viewIntent, 56);
118
				*/
119
				
120
				currentPath = curDirFiles[position].getCName() + "/";
121
				loadCurrentDirectoryFiles();
122
				displayCurrentFiles();
123
			}
124

  
125 99
			else{
126
				viewIntent = new Intent(this, ContainerObjectDetails.class);
127
				viewIntent.putExtra("container", files[position]);
128
				viewIntent.putExtra("cdnUrl", container.getCdnUrl());
129
				viewIntent.putExtra("containerNames", container.getName());
130
				viewIntent.putExtra("isCdnEnabled", cdnEnabledIs);
131
				startActivityForResult(viewIntent, 55); // arbitrary number; never
132
				// used again
100
				currentPath = "";
101
			}
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());
110
				}
133 111
			}
134 112
		}
113
		else {
114
			currentPath = "";
115
			loadFiles();
116
		}	
135 117
	}
136
	
118

  
137 119
	/*
138 120
	 * overriding back button press, because we are not actually changing
139
	 * activites when we navigate the file structure
121
	 * activities when we navigate the file structure
140 122
	 */
141 123
	public void onBackPressed() {
142 124
		if(currentPath.equals("")){
......
156 138
		displayCurrentFiles();
157 139
	}
158 140

  
159
	/*
160
	 * get the path that was stored in the intent
161
	 */
162
	private void getPath(){
163
		if(this.getIntent().getExtras().containsKey("path")){
164
			currentPath = (String)this.getIntent().getExtras().get("path");
165
		}
166
		else{
167
			currentPath = "";
168
		}
169
		
170
	}
171

  
172 141
	private void loadFiles() {
173
		displayLoadingCell();
142
		//displayLoadingCell();
174 143
		new LoadFilesTask().execute();
175 144
	}
145

  
176 146
	
177 147
	/* load only the files that should display for the 
178 148
	 * current directory in the curDirFiles[]
......
242 212
		}
243 213
	}
244 214

  
245
	private void displayLoadingCell() {
246
		String a[] = new String[1];
247
		a[0] = "Loading...";
248
		setListAdapter(new ArrayAdapter<String>(this, R.layout.loadingcell,
249
				R.id.loading_label, a));
250
		getListView().setTextFilterEnabled(true);
251
		getListView().setDividerHeight(0); // hide the dividers so it won't look
252
											// like a list row
253
		getListView().setItemsCanFocus(false);
254
	}
255

  
256 215
	/*
257 216
	 * display a different empty page depending
258 217
	 * of if you are at top of container or
......
295 254
		}
296 255
	}
297 256

  
298
	private class LoadFilesTask extends
299
			AsyncTask<String, Void, ArrayList<ContainerObjects>> {
300

  
301
		private CloudServersException exception;
302

  
303
		@Override
304
		protected ArrayList<ContainerObjects> doInBackground(String... path) {
305
			ArrayList<ContainerObjects> files = null;
306
			try {
307
				files = (new ContainerObjectManager(context)).createList(true,
308
						container.getName());
309
			} catch (CloudServersException e) {
310
				exception = e;
311
				e.printStackTrace();
312
			}
313
			return files;
314
		}
315

  
316
		@Override
317
		protected void onPostExecute(ArrayList<ContainerObjects> result) {
318
			if (exception != null) {
319
				showAlert("Error", exception.getMessage());
320
			}
321
			setFileList(result);
322
		}
323
	}
324

  
325
	class FileAdapter extends ArrayAdapter<ContainerObjects> {
326
		FileAdapter() {
327
			super(ContainerObjectsActivity.this,
328
					R.layout.listcontainerobjectcell, curDirFiles);
329
		}
330

  
331
		public View getView(int position, View convertView, ViewGroup parent) {
332

  
333
			ContainerObjects file = curDirFiles[position];
334
			LayoutInflater inflater = getLayoutInflater();
335
			View row = inflater.inflate(R.layout.listcontainerobjectcell,
336
					parent, false);
337

  
338
			TextView label = (TextView) row.findViewById(R.id.label);
339
			//label.setText(file.getCName());
340
			label.setText(file.getCName());
341

  
342
			if (file.getBytes() >= bConver) {
343
				megaBytes = Math.abs(file.getBytes() / bConver + 0.2);
344
				TextView sublabel = (TextView) row.findViewById(R.id.sublabel);
345
				sublabel.setText(megaBytes + " MB");
346
			} else if (file.getBytes() >= kbConver) {
347
				kiloBytes = Math.abs(file.getBytes() / kbConver + 0.2);
348
				TextView sublabel = (TextView) row.findViewById(R.id.sublabel);
349
				sublabel.setText(kiloBytes + " KB");
350
			} else {
351
				TextView sublabel = (TextView) row.findViewById(R.id.sublabel);
352
				sublabel.setText(file.getBytes() + " B");
353
			}
354

  
355
			return (row);
356
		}
357
	}
358
	
359 257
	/* just get the last part of the filename
360 258
	 * so the entire file path does not show
361 259
	*/
......
365 263
			return s;
366 264
		}
367 265
		else {
368
			return s.substring(s.lastIndexOf('/'));
266
			return s.substring(s.lastIndexOf('/')+1);
267
		}
268
	}
269
	
270
	/*
271
	 * removed a specified object from the array of 
272
	 * all the files in the container
273
	 */
274
	private void removeFromList(String path){
275
		ArrayList<ContainerObjects> temp = new ArrayList<ContainerObjects>(Arrays.asList(files));
276
		for(int i = 0; i < files.length; i++){
277
			if(files[i].getCName().equals(path.substring(0, path.length()-1))){
278
				temp.remove(i);
279
			}
280
		}
281
		files = new ContainerObjects[temp.size()];
282
		for(int i = 0; i < temp.size(); i++){
283
			files[i] = temp.get(i);
284
		}
285
	}
286

  
287
	protected void onListItemClick(ListView l, View v, int position, long id) {
288
		if (curDirFiles != null && curDirFiles.length > 0) {
289
			Intent viewIntent;
290
			if(curDirFiles[position].getContentType().equals("application/directory")){			
291
				currentPath = curDirFiles[position].getCName() + "/";
292
				loadCurrentDirectoryFiles();
293
				displayCurrentFiles();
294
			}
295
	
296
			else{
297
				viewIntent = new Intent(this, ContainerObjectDetails.class);
298
				viewIntent.putExtra("container", curDirFiles[position]);
299
				viewIntent.putExtra("cdnUrl", container.getCdnUrl());
300
				viewIntent.putExtra("containerNames", container.getName());
301
				viewIntent.putExtra("isCdnEnabled", cdnEnabledIs);
302
				startActivityForResult(viewIntent, 55); // arbitrary number; never
303
				// used again
304
			}
369 305
		}
370 306
	}
371 307

  
......
389 325
		switch (item.getItemId()) {
390 326
		case R.id.delete_container:
391 327
			if(currentPath.equals("")){
392
				Log.d("deleting", "captin deleting a container");
393 328
				showDialog(deleteContainer);
394 329
			}
395 330
			else{
396
				Log.d("deleting", "captin deleting a folder");
397 331
				showDialog(deleteFolder);
398 332
			}
399 333
			return true;
......
405 339
		case R.id.refresh:
406 340
			loadFiles();
407 341
			return true;
342
		case R.id.add_folder:
343
			showDialog(R.id.add_folder);
344
		case R.id.add_file:
345
			Intent viewIntent2 = new Intent(this, AddFileActivity.class);
346
			viewIntent2.putExtra("Cname", container.getName());
347
			viewIntent2.putExtra("curPath", currentPath);
348
			startActivityForResult(viewIntent2, 56);
349
			return true;	
408 350
		}
409 351
		return false;
410 352
	}
......
487 429
					}
488 430
				}).create();
489 431
			}
490

  
432
		case R.id.add_folder:
433
			final EditText input = new EditText(this);
434
            return new AlertDialog.Builder(ContainerObjectsActivity.this)
435
        	.setIcon(R.drawable.alert_dialog_icon)
436
            .setView(input)
437
        	.setTitle("Add Folder")
438
        	.setMessage("Enter new name for folder: ")        	         
439
        	.setPositiveButton("Add", new DialogInterface.OnClickListener() {
440
        		public void onClick(DialogInterface dialog, int whichButton) {
441
        			// User clicked OK so do some stuff
442
        			String[] info = {input.getText().toString(), "application/directory"};
443
        			new AddFolderTask().execute(info);
444
        		}
445
        	})
446
        	.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
447
        		public void onClick(DialogInterface dialog, int whichButton) {
448
        			// User clicked Cancel so do some stuff
449
        		}
450
        	})
451
        	.create();     
491 452
		}
492 453
		return null;
493 454
	}
......
539 500
		}
540 501
		return cse;
541 502
	}
503
	
504
	class FileAdapter extends ArrayAdapter<ContainerObjects> {
505
		FileAdapter() {
506
			super(ContainerObjectsActivity.this,
507
					R.layout.listcontainerobjectcell, curDirFiles);
508
		}
509
	
510
		public View getView(int position, View convertView, ViewGroup parent) {
511
	
512
			ContainerObjects file = curDirFiles[position];
513
			LayoutInflater inflater = getLayoutInflater();
514
			View row = inflater.inflate(R.layout.listcontainerobjectcell,
515
					parent, false);
516
	
517
			TextView label = (TextView) row.findViewById(R.id.label);
518
			//label.setText(file.getCName());
519
			label.setText(getShortName(file.getCName()));
520
	
521
			if (file.getBytes() >= bConver) {
522
				megaBytes = Math.abs(file.getBytes() / bConver + 0.2);
523
				TextView sublabel = (TextView) row.findViewById(R.id.sublabel);
524
				sublabel.setText(megaBytes + " MB");
525
			} else if (file.getBytes() >= kbConver) {
526
				kiloBytes = Math.abs(file.getBytes() / kbConver + 0.2);
527
				TextView sublabel = (TextView) row.findViewById(R.id.sublabel);
528
				sublabel.setText(kiloBytes + " KB");
529
			} else {
530
				TextView sublabel = (TextView) row.findViewById(R.id.sublabel);
531
				sublabel.setText(file.getBytes() + " B");
532
			}
533
	
534
			return (row);
535
		}
536
	}
542 537

  
538
	private class LoadFilesTask extends
539
			AsyncTask<String, Void, ArrayList<ContainerObjects>> {
540
	
541
		private CloudServersException exception;
542
		
543
		protected void onPreExecute(){
544
			dialog = ProgressDialog.show(ContainerObjectsActivity.this, "", "Loading Files...", true);
545
		}
543 546
	
547
		@Override
548
		protected ArrayList<ContainerObjects> doInBackground(String... path) {
549
			ArrayList<ContainerObjects> files = null;
550
			try {
551
				files = (new ContainerObjectManager(context)).createList(true,
552
						container.getName());
553
			} catch (CloudServersException e) {
554
				exception = e;
555
				e.printStackTrace();
556
			}
557
			return files;
558
		}
559
	
560
		@Override
561
		protected void onPostExecute(ArrayList<ContainerObjects> result) {
562
			dialog.dismiss();
563
			if (exception != null) {
564
				showAlert("Error", exception.getMessage());
565
			}
566
			setFileList(result);
567
		}
568
	}
569

  
544 570
	private class DeleteObjectTask extends
545 571
	AsyncTask<Void, Void, HttpResponse> {
546 572

  
547 573
		private CloudServersException exception;
548

  
574
		
575
		protected void onPreExecute(){
576
			dialog = ProgressDialog.show(ContainerObjectsActivity.this, "", "Deleting...", true);
577
		}
578
		
549 579
		@Override
550 580
		protected HttpResponse doInBackground(Void... arg0) {
551 581
			HttpResponse resp = null;
......
568 598
				}
569 599
				if (statusCode == 204) {
570 600
					setResult(Activity.RESULT_OK);
601
					removeFromList(currentPath);
571 602
					goUpDirectory();
572
					loadFiles();
573

  
603
					dialog.dismiss();
574 604
				} else {
575 605
					CloudServersException cse = parseCloudServersException(response);
576 606
					if ("".equals(cse.getMessage())) {
......
589 619
		}
590 620
	}
591 621
	
622
	private class AddFolderTask extends
623
	AsyncTask<String, Void, HttpResponse> {
624
	
625
		private CloudServersException exception;
626
		
627
		protected void onPreExecute(){
628
			dialog = ProgressDialog.show(ContainerObjectsActivity.this, "", "Adding Folder...", true);
629
		}
630
	
631
		@Override
632
		protected HttpResponse doInBackground(String... data) {
633
			HttpResponse resp = null;
634
			try {
635
				resp = (new ContainerObjectManager(context)).addObject(container.getName(), currentPath, data[0], data[1]);
636
			} catch (CloudServersException e) {
637
				exception = e;
638
			}
639
			return resp;
640
		}
641
	
642
		@Override
643
		protected void onPostExecute(HttpResponse response) {
644
			dialog.dismiss();
645
			if (response != null) {
646
				int statusCode = response.getStatusLine().getStatusCode();
647
				if (statusCode == 201) {
648
					setResult(Activity.RESULT_OK);
649
					loadFiles();
650
				} else {
651
					CloudServersException cse = parseCloudServersException(response);
652
					if ("".equals(cse.getMessage())) {
653
						showAlert("Error",
654
							"There was a problem deleting your folder.");
655
					} else {
656
						showAlert("Error",
657
								"There was a problem deleting your folder: "
658
									+ cse.getMessage());
659
					}
660
				}
661
			} else if (exception != null) {
662
				showAlert("Error", "There was a problem deleting your folder: "
663
						+ exception.getMessage());
664
			}
665
		}
666
	}
667

  
592 668
	private class DeleteContainerTask extends
593 669
	AsyncTask<String, Void, HttpResponse> {
594 670

  

Also available in: Unified diff