root / src / com / rackspacecloud / android / ContainerObjectsActivity.java @ d3ea294b
History | View | Annotate | Download (20.6 kB)
1 |
package com.rackspacecloud.android; |
---|---|
2 |
|
3 |
import java.io.IOException; |
4 |
import java.io.StringReader; |
5 |
import java.util.ArrayList; |
6 |
import java.util.Arrays; |
7 |
|
8 |
import javax.xml.parsers.FactoryConfigurationError; |
9 |
import javax.xml.parsers.ParserConfigurationException; |
10 |
import javax.xml.parsers.SAXParser; |
11 |
import javax.xml.parsers.SAXParserFactory; |
12 |
|
13 |
import org.apache.http.HttpResponse; |
14 |
import org.apache.http.client.ClientProtocolException; |
15 |
import org.apache.http.impl.client.BasicResponseHandler; |
16 |
import org.xml.sax.InputSource; |
17 |
import org.xml.sax.SAXException; |
18 |
import org.xml.sax.XMLReader; |
19 |
|
20 |
import android.app.Activity; |
21 |
import android.app.AlertDialog; |
22 |
import android.app.Dialog; |
23 |
import android.app.ListActivity; |
24 |
import android.app.ProgressDialog; |
25 |
import android.content.Context; |
26 |
import android.content.DialogInterface; |
27 |
import android.content.Intent; |
28 |
import android.os.AsyncTask; |
29 |
import android.os.Bundle; |
30 |
import android.util.Log; |
31 |
import android.view.LayoutInflater; |
32 |
import android.view.Menu; |
33 |
import android.view.MenuInflater; |
34 |
import android.view.MenuItem; |
35 |
import android.view.View; |
36 |
import android.view.ViewGroup; |
37 |
import android.widget.ArrayAdapter; |
38 |
import android.widget.EditText; |
39 |
import android.widget.ListView; |
40 |
import android.widget.TextView; |
41 |
|
42 |
import com.rackspace.cloud.files.api.client.Container; |
43 |
import com.rackspace.cloud.files.api.client.ContainerManager; |
44 |
import com.rackspace.cloud.files.api.client.ContainerObjectManager; |
45 |
import com.rackspace.cloud.files.api.client.ContainerObjects; |
46 |
import com.rackspace.cloud.servers.api.client.CloudServersException; |
47 |
import com.rackspace.cloud.servers.api.client.parsers.CloudServersFaultXMLParser; |
48 |
//import com.rackspacecloud.android.ViewServerActivity.RenameServerTask;
|
49 |
|
50 |
/**
|
51 |
*
|
52 |
* @author Phillip Toohill
|
53 |
*
|
54 |
*/
|
55 |
public class ContainerObjectsActivity extends ListActivity { |
56 |
|
57 |
private static final int deleteContainer = 0; |
58 |
private static final int deleteFolder = 1; |
59 |
private ContainerObjects[] files; |
60 |
private static Container container; |
61 |
public String LOG = "viewFilesActivity"; |
62 |
private String cdnEnabledIs; |
63 |
public Object megaBytes; |
64 |
public Object kiloBytes; |
65 |
public int bConver = 1048576; |
66 |
public int kbConver = 1024; |
67 |
private Context context; |
68 |
private String currentPath; |
69 |
private ContainerObjects[] curDirFiles; |
70 |
ProgressDialog dialog; |
71 |
|
72 |
@Override
|
73 |
public void onCreate(Bundle savedInstanceState) { |
74 |
super.onCreate(savedInstanceState);
|
75 |
container = (Container) this.getIntent().getExtras().get("container"); |
76 |
Log.v(LOG, "CDNEnabled:" + container.isCdnEnabled());
|
77 |
context = getApplicationContext(); |
78 |
if (container.isCdnEnabled() == true) { |
79 |
cdnEnabledIs = "true";
|
80 |
} else {
|
81 |
cdnEnabledIs = "false";
|
82 |
} |
83 |
restoreState(savedInstanceState); |
84 |
} |
85 |
|
86 |
@Override
|
87 |
protected void onSaveInstanceState(Bundle outState) { |
88 |
super.onSaveInstanceState(outState);
|
89 |
outState.putSerializable("container", files);
|
90 |
outState.putString("path", currentPath);
|
91 |
outState.putSerializable("curFiles", curDirFiles);
|
92 |
} |
93 |
|
94 |
private void restoreState(Bundle state) { |
95 |
if(state != null){ |
96 |
if(state.containsKey("path")){ |
97 |
currentPath = state.getString("path");
|
98 |
} |
99 |
else{
|
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 |
} |
111 |
} |
112 |
} |
113 |
else {
|
114 |
currentPath = "";
|
115 |
loadFiles(); |
116 |
} |
117 |
} |
118 |
|
119 |
/*
|
120 |
* overriding back button press, because we are not actually changing
|
121 |
* activities when we navigate the file structure
|
122 |
*/
|
123 |
public void onBackPressed() { |
124 |
if(currentPath.equals("")){ |
125 |
finish(); |
126 |
} |
127 |
else{
|
128 |
goUpDirectory(); |
129 |
} |
130 |
} |
131 |
|
132 |
/*
|
133 |
* go to the current directory's parent and display that data
|
134 |
*/
|
135 |
private void goUpDirectory(){ |
136 |
currentPath = currentPath.substring(0, currentPath.substring(0, currentPath.length()-2).lastIndexOf("/")+1); |
137 |
loadCurrentDirectoryFiles(); |
138 |
displayCurrentFiles(); |
139 |
} |
140 |
|
141 |
private void loadFiles() { |
142 |
//displayLoadingCell();
|
143 |
new LoadFilesTask().execute();
|
144 |
} |
145 |
|
146 |
|
147 |
/* load only the files that should display for the
|
148 |
* current directory in the curDirFiles[]
|
149 |
*/
|
150 |
private void loadCurrentDirectoryFiles(){ |
151 |
ArrayList<ContainerObjects> curFiles = new ArrayList<ContainerObjects>(); |
152 |
|
153 |
if(files != null){ |
154 |
for(int i = 0 ; i < files.length; i ++){ |
155 |
if(fileBelongsInDir(files[i])){
|
156 |
curFiles.add(files[i]); |
157 |
} |
158 |
} |
159 |
|
160 |
curDirFiles = new ContainerObjects[curFiles.size()];
|
161 |
for(int i = 0; i < curFiles.size(); i++){ |
162 |
curDirFiles[i] = curFiles.get(i); |
163 |
} |
164 |
} |
165 |
} |
166 |
|
167 |
/*
|
168 |
* determines if a file should be displayed in current
|
169 |
* directory
|
170 |
*/
|
171 |
private Boolean fileBelongsInDir(ContainerObjects obj){ |
172 |
String objPath = obj.getCName();
|
173 |
if(!objPath.startsWith(currentPath)){
|
174 |
return false; |
175 |
} |
176 |
else{
|
177 |
objPath = objPath.substring(currentPath.length()); |
178 |
return !objPath.contains("/"); |
179 |
} |
180 |
} |
181 |
|
182 |
|
183 |
/*
|
184 |
* loads all the files that are in the container
|
185 |
* into one array
|
186 |
*/
|
187 |
private void setFileList(ArrayList<ContainerObjects> files) { |
188 |
if (files == null) { |
189 |
files = new ArrayList<ContainerObjects>(); |
190 |
} |
191 |
String[] fileNames = new String[files.size()]; |
192 |
this.files = new ContainerObjects[files.size()]; |
193 |
|
194 |
if (files != null) { |
195 |
for (int i = 0; i < files.size(); i++) { |
196 |
ContainerObjects file = files.get(i); |
197 |
this.files[i] = file;
|
198 |
fileNames[i] = file.getName(); |
199 |
} |
200 |
} |
201 |
|
202 |
displayCurrentFiles(); |
203 |
} |
204 |
|
205 |
private void displayCurrentFiles(){ |
206 |
loadCurrentDirectoryFiles(); |
207 |
if (curDirFiles.length == 0) { |
208 |
displayNoServersCell(); |
209 |
} else {
|
210 |
getListView().setDividerHeight(1); // restore divider lines |
211 |
setListAdapter(new FileAdapter());
|
212 |
} |
213 |
} |
214 |
|
215 |
/*
|
216 |
* display a different empty page depending
|
217 |
* of if you are at top of container or
|
218 |
* in a folder
|
219 |
*/
|
220 |
private void displayNoServersCell() { |
221 |
String a[] = new String[1]; |
222 |
if(currentPath.equals("")){ |
223 |
a[0] = "Empty Container"; |
224 |
setListAdapter(new ArrayAdapter<String>(this, R.layout.noobjectscell, |
225 |
R.id.no_files_label, a)); |
226 |
} |
227 |
else{
|
228 |
a[0] = "No Files"; |
229 |
setListAdapter(new ArrayAdapter<String>(this, R.layout.nofilescell, |
230 |
R.id.no_files_label, a)); |
231 |
} |
232 |
getListView().setTextFilterEnabled(true);
|
233 |
getListView().setDividerHeight(0); // hide the dividers so it won't look |
234 |
// like a list row
|
235 |
getListView().setItemsCanFocus(false);
|
236 |
} |
237 |
|
238 |
private void showAlert(String title, String message) { |
239 |
// Can't create handler inside thread that has not called
|
240 |
// Looper.prepare()
|
241 |
// Looper.prepare();
|
242 |
try {
|
243 |
AlertDialog alert = new AlertDialog.Builder(this).create(); |
244 |
alert.setTitle(title); |
245 |
alert.setMessage(message); |
246 |
alert.setButton("OK", new DialogInterface.OnClickListener() { |
247 |
public void onClick(DialogInterface dialog, int which) { |
248 |
return;
|
249 |
} |
250 |
}); |
251 |
alert.show(); |
252 |
} catch (Exception e) { |
253 |
e.printStackTrace(); |
254 |
} |
255 |
} |
256 |
|
257 |
/* just get the last part of the filename
|
258 |
* so the entire file path does not show
|
259 |
*/
|
260 |
private String getShortName(String longName){ |
261 |
String s = longName;
|
262 |
if(!s.contains("/")){ |
263 |
return s;
|
264 |
} |
265 |
else {
|
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 |
} |
305 |
} |
306 |
} |
307 |
|
308 |
/*
|
309 |
* Create the Menu options
|
310 |
*/
|
311 |
@Override
|
312 |
public boolean onCreateOptionsMenu(Menu menu) { |
313 |
super.onCreateOptionsMenu(menu);
|
314 |
MenuInflater inflater = getMenuInflater(); |
315 |
inflater.inflate(R.menu.view_container_object_list_menu, menu); |
316 |
return true; |
317 |
} |
318 |
|
319 |
@Override
|
320 |
/*
|
321 |
* option performed for delete depends on if you
|
322 |
* are at the top of a container or in a folder
|
323 |
*/
|
324 |
public boolean onOptionsItemSelected(MenuItem item) { |
325 |
switch (item.getItemId()) {
|
326 |
case R.id.delete_container:
|
327 |
if(currentPath.equals("")){ |
328 |
showDialog(deleteContainer); |
329 |
} |
330 |
else{
|
331 |
showDialog(deleteFolder); |
332 |
} |
333 |
return true; |
334 |
case R.id.enable_cdn:
|
335 |
Intent viewIntent1 = new Intent(this, EnableCDNActivity.class); |
336 |
viewIntent1.putExtra("Cname", container.getName());
|
337 |
startActivityForResult(viewIntent1, 56);
|
338 |
return true; |
339 |
case R.id.refresh:
|
340 |
loadFiles(); |
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; |
350 |
} |
351 |
return false; |
352 |
} |
353 |
|
354 |
@Override
|
355 |
protected Dialog onCreateDialog(int id) { |
356 |
switch (id) {
|
357 |
case deleteContainer:
|
358 |
if(curDirFiles.length == 0){ |
359 |
return new AlertDialog.Builder(ContainerObjectsActivity.this) |
360 |
.setIcon(R.drawable.alert_dialog_icon) |
361 |
.setTitle("Delete Container")
|
362 |
.setMessage( |
363 |
"Are you sure you want to delete this Container?")
|
364 |
.setPositiveButton("Delete Container",
|
365 |
new DialogInterface.OnClickListener() {
|
366 |
public void onClick(DialogInterface dialog, |
367 |
int whichButton) {
|
368 |
// User clicked OK so do some stuff
|
369 |
new DeleteContainerTask()
|
370 |
.execute(currentPath); |
371 |
} |
372 |
}) |
373 |
.setNegativeButton("Cancel",
|
374 |
new DialogInterface.OnClickListener() {
|
375 |
public void onClick(DialogInterface dialog, |
376 |
int whichButton) {
|
377 |
// User clicked Cancel so do some stuff
|
378 |
} |
379 |
}).create(); |
380 |
} |
381 |
else{
|
382 |
return new AlertDialog.Builder(ContainerObjectsActivity.this) |
383 |
.setIcon(R.drawable.alert_dialog_icon) |
384 |
.setTitle("Delete Container")
|
385 |
.setMessage("Container must be empty to delete")
|
386 |
.setNegativeButton("OK",
|
387 |
new DialogInterface.OnClickListener() {
|
388 |
public void onClick(DialogInterface dialog, |
389 |
int whichButton) {
|
390 |
// User clicked Cancel so do some stuff
|
391 |
} |
392 |
}).create(); |
393 |
} |
394 |
case deleteFolder:
|
395 |
if(curDirFiles.length == 0){ |
396 |
return new AlertDialog.Builder(ContainerObjectsActivity.this) |
397 |
.setIcon(R.drawable.alert_dialog_icon) |
398 |
.setTitle("Delete Folder")
|
399 |
.setMessage( |
400 |
"Are you sure you want to delete this Folder?")
|
401 |
.setPositiveButton("Delete Folder",
|
402 |
new DialogInterface.OnClickListener() {
|
403 |
public void onClick(DialogInterface dialog, |
404 |
int whichButton) {
|
405 |
// User clicked OK so do some stuff
|
406 |
new DeleteObjectTask()
|
407 |
.execute(); |
408 |
} |
409 |
}) |
410 |
.setNegativeButton("Cancel",
|
411 |
new DialogInterface.OnClickListener() {
|
412 |
public void onClick(DialogInterface dialog, |
413 |
int whichButton) {
|
414 |
// User clicked Cancel so do some stuff
|
415 |
} |
416 |
}).create(); |
417 |
} |
418 |
else{
|
419 |
return new AlertDialog.Builder(ContainerObjectsActivity.this) |
420 |
.setIcon(R.drawable.alert_dialog_icon) |
421 |
.setTitle("Delete Folder")
|
422 |
.setMessage( |
423 |
"Folder must be empty to delete")
|
424 |
.setNegativeButton("OK",
|
425 |
new DialogInterface.OnClickListener() {
|
426 |
public void onClick(DialogInterface dialog, |
427 |
int whichButton) {
|
428 |
// User clicked Cancel so do some stuff
|
429 |
} |
430 |
}).create(); |
431 |
} |
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(); |
452 |
} |
453 |
return null; |
454 |
} |
455 |
|
456 |
@Override
|
457 |
public void onActivityResult(int requestCode, int resultCode, Intent data) { |
458 |
super.onActivityResult(requestCode, resultCode, data);
|
459 |
|
460 |
if (resultCode == RESULT_OK) {
|
461 |
// a sub-activity kicked back, so we want to refresh the server list
|
462 |
loadFiles(); |
463 |
} |
464 |
if (requestCode == 56) { |
465 |
if (resultCode == RESULT_OK) {
|
466 |
Intent viewIntent1 = new Intent(this, |
467 |
ListContainerActivity.class); |
468 |
startActivityForResult(viewIntent1, 56);
|
469 |
} |
470 |
} |
471 |
} |
472 |
|
473 |
private CloudServersException parseCloudServersException(
|
474 |
HttpResponse response) { |
475 |
CloudServersException cse = new CloudServersException();
|
476 |
try {
|
477 |
BasicResponseHandler responseHandler = new BasicResponseHandler();
|
478 |
String body = responseHandler.handleResponse(response);
|
479 |
CloudServersFaultXMLParser parser = new CloudServersFaultXMLParser();
|
480 |
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); |
481 |
XMLReader xmlReader = saxParser.getXMLReader(); |
482 |
xmlReader.setContentHandler(parser); |
483 |
xmlReader.parse(new InputSource(new StringReader(body))); |
484 |
cse = parser.getException(); |
485 |
} catch (ClientProtocolException e) {
|
486 |
cse = new CloudServersException();
|
487 |
cse.setMessage(e.getLocalizedMessage()); |
488 |
} catch (IOException e) { |
489 |
cse = new CloudServersException();
|
490 |
cse.setMessage(e.getLocalizedMessage()); |
491 |
} catch (ParserConfigurationException e) { |
492 |
cse = new CloudServersException();
|
493 |
cse.setMessage(e.getLocalizedMessage()); |
494 |
} catch (SAXException e) {
|
495 |
cse = new CloudServersException();
|
496 |
cse.setMessage(e.getLocalizedMessage()); |
497 |
} catch (FactoryConfigurationError e) { |
498 |
cse = new CloudServersException();
|
499 |
cse.setMessage(e.getLocalizedMessage()); |
500 |
} |
501 |
return cse;
|
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 |
} |
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 |
} |
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 |
|
570 |
private class DeleteObjectTask extends |
571 |
AsyncTask<Void, Void, HttpResponse> { |
572 |
|
573 |
private CloudServersException exception;
|
574 |
|
575 |
protected void onPreExecute(){ |
576 |
dialog = ProgressDialog.show(ContainerObjectsActivity.this, "", "Deleting...", true); |
577 |
} |
578 |
|
579 |
@Override
|
580 |
protected HttpResponse doInBackground(Void... arg0) { |
581 |
HttpResponse resp = null;
|
582 |
try {
|
583 |
//subtring because the current directory contains a "/" at the end of the string
|
584 |
resp = (new ContainerObjectManager(context)).deleteObject(container.getName(), currentPath.substring(0, currentPath.length()-1)); |
585 |
} catch (CloudServersException e) {
|
586 |
exception = e; |
587 |
} |
588 |
return resp;
|
589 |
} |
590 |
|
591 |
@Override
|
592 |
protected void onPostExecute(HttpResponse response) { |
593 |
if (response != null) { |
594 |
int statusCode = response.getStatusLine().getStatusCode();
|
595 |
if (statusCode == 409) { |
596 |
showAlert("Error",
|
597 |
"Folder must be empty in order to delete");
|
598 |
} |
599 |
if (statusCode == 204) { |
600 |
setResult(Activity.RESULT_OK); |
601 |
removeFromList(currentPath); |
602 |
goUpDirectory(); |
603 |
dialog.dismiss(); |
604 |
} else {
|
605 |
CloudServersException cse = parseCloudServersException(response); |
606 |
if ("".equals(cse.getMessage())) { |
607 |
showAlert("Error",
|
608 |
"There was a problem deleting your folder.");
|
609 |
} else {
|
610 |
showAlert("Error",
|
611 |
"There was a problem deleting your folder: "
|
612 |
+ cse.getMessage()); |
613 |
} |
614 |
} |
615 |
} else if (exception != null) { |
616 |
showAlert("Error", "There was a problem deleting your folder: " |
617 |
+ exception.getMessage()); |
618 |
} |
619 |
} |
620 |
} |
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 |
|
668 |
private class DeleteContainerTask extends |
669 |
AsyncTask<String, Void, HttpResponse> { |
670 |
|
671 |
private CloudServersException exception;
|
672 |
|
673 |
@Override
|
674 |
protected HttpResponse doInBackground(String... object) { |
675 |
HttpResponse resp = null;
|
676 |
try {
|
677 |
resp = (new ContainerManager(context)).delete(container.getName());
|
678 |
Log.v(LOG, "container's name " + container.getName());
|
679 |
} catch (CloudServersException e) {
|
680 |
exception = e; |
681 |
} |
682 |
return resp;
|
683 |
} |
684 |
|
685 |
@Override
|
686 |
protected void onPostExecute(HttpResponse response) { |
687 |
if (response != null) { |
688 |
int statusCode = response.getStatusLine().getStatusCode();
|
689 |
if (statusCode == 409) { |
690 |
showAlert("Error",
|
691 |
"Container must be empty in order to delete");
|
692 |
} |
693 |
if (statusCode == 204) { |
694 |
setResult(Activity.RESULT_OK); |
695 |
loadFiles(); |
696 |
finish(); |
697 |
|
698 |
} else {
|
699 |
CloudServersException cse = parseCloudServersException(response); |
700 |
if ("".equals(cse.getMessage())) { |
701 |
showAlert("Error",
|
702 |
"There was a problem deleting your container.");
|
703 |
} else {
|
704 |
showAlert("Error",
|
705 |
"There was a problem deleting your container: "
|
706 |
+ cse.getMessage()); |
707 |
} |
708 |
} |
709 |
} else if (exception != null) { |
710 |
showAlert("Error", "There was a problem deleting your server: " |
711 |
+ exception.getMessage()); |
712 |
} |
713 |
} |
714 |
} |
715 |
|
716 |
} |