root / src / com / rackspacecloud / android / ContainerObjectsActivity.java @ 44ac7bea
History | View | Annotate | Download (20.9 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 |
|
142 |
/*
|
143 |
private void loadFiles() {
|
144 |
//displayLoadingCell();
|
145 |
new LoadFilesTask().execute();
|
146 |
}
|
147 |
*/
|
148 |
|
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); |
164 |
} |
165 |
|
166 |
|
167 |
|
168 |
|
169 |
/* load only the files that should display for the
|
170 |
* current directory in the curDirFiles[]
|
171 |
*/
|
172 |
private void loadCurrentDirectoryFiles(){ |
173 |
ArrayList<ContainerObjects> curFiles = new ArrayList<ContainerObjects>(); |
174 |
|
175 |
if(files != null){ |
176 |
for(int i = 0 ; i < files.length; i ++){ |
177 |
if(fileBelongsInDir(files[i])){
|
178 |
curFiles.add(files[i]); |
179 |
} |
180 |
} |
181 |
|
182 |
curDirFiles = new ContainerObjects[curFiles.size()];
|
183 |
for(int i = 0; i < curFiles.size(); i++){ |
184 |
curDirFiles[i] = curFiles.get(i); |
185 |
} |
186 |
} |
187 |
} |
188 |
|
189 |
/*
|
190 |
* determines if a file should be displayed in current
|
191 |
* directory
|
192 |
*/
|
193 |
private Boolean fileBelongsInDir(ContainerObjects obj){ |
194 |
String objPath = obj.getCName();
|
195 |
if(!objPath.startsWith(currentPath)){
|
196 |
return false; |
197 |
} |
198 |
else{
|
199 |
objPath = objPath.substring(currentPath.length()); |
200 |
return !objPath.contains("/"); |
201 |
} |
202 |
} |
203 |
|
204 |
|
205 |
/*
|
206 |
* loads all the files that are in the container
|
207 |
* into one array
|
208 |
*/
|
209 |
private void setFileList(ArrayList<ContainerObjects> files) { |
210 |
if (files == null) { |
211 |
files = new ArrayList<ContainerObjects>(); |
212 |
} |
213 |
String[] fileNames = new String[files.size()]; |
214 |
this.files = new ContainerObjects[files.size()]; |
215 |
|
216 |
|
217 |
|
218 |
if (files != null) { |
219 |
for (int i = 0; i < files.size(); i++) { |
220 |
ContainerObjects file = files.get(i); |
221 |
this.files[i] = file;
|
222 |
fileNames[i] = file.getName(); |
223 |
} |
224 |
} |
225 |
|
226 |
displayCurrentFiles(); |
227 |
} |
228 |
|
229 |
private void displayCurrentFiles(){ |
230 |
if(curDirFiles!=null) |
231 |
loadCurrentDirectoryFiles(); |
232 |
if (curDirFiles.length == 0) { |
233 |
displayNoServersCell(); |
234 |
} else {
|
235 |
getListView().setDividerHeight(1); // restore divider lines |
236 |
setListAdapter(new FileAdapter());
|
237 |
} |
238 |
} |
239 |
|
240 |
/*
|
241 |
* display a different empty page depending
|
242 |
* of if you are at top of container or
|
243 |
* in a folder
|
244 |
*/
|
245 |
private void displayNoServersCell() { |
246 |
String a[] = new String[1]; |
247 |
if(currentPath.equals("")){ |
248 |
a[0] = "Empty Container"; |
249 |
setListAdapter(new ArrayAdapter<String>(this, R.layout.noobjectscell, |
250 |
R.id.no_files_label, a)); |
251 |
} |
252 |
else{
|
253 |
a[0] = "No Files"; |
254 |
setListAdapter(new ArrayAdapter<String>(this, R.layout.nofilescell, |
255 |
R.id.no_files_label, a)); |
256 |
} |
257 |
getListView().setTextFilterEnabled(true);
|
258 |
getListView().setDividerHeight(0); // hide the dividers so it won't look |
259 |
// like a list row
|
260 |
getListView().setItemsCanFocus(false);
|
261 |
} |
262 |
|
263 |
private void showAlert(String title, String message) { |
264 |
// Can't create handler inside thread that has not called
|
265 |
// Looper.prepare()
|
266 |
// Looper.prepare();
|
267 |
try {
|
268 |
AlertDialog alert = new AlertDialog.Builder(this).create(); |
269 |
alert.setTitle(title); |
270 |
alert.setMessage(message); |
271 |
alert.setButton("OK", new DialogInterface.OnClickListener() { |
272 |
public void onClick(DialogInterface dialog, int which) { |
273 |
return;
|
274 |
} |
275 |
}); |
276 |
alert.show(); |
277 |
} catch (Exception e) { |
278 |
e.printStackTrace(); |
279 |
} |
280 |
} |
281 |
|
282 |
/* just get the last part of the filename
|
283 |
* so the entire file path does not show
|
284 |
*/
|
285 |
private String getShortName(String longName){ |
286 |
String s = longName;
|
287 |
if(!s.contains("/")){ |
288 |
return s;
|
289 |
} |
290 |
else {
|
291 |
return s.substring(s.lastIndexOf('/')+1); |
292 |
} |
293 |
} |
294 |
|
295 |
/*
|
296 |
* removed a specified object from the array of
|
297 |
* all the files in the container
|
298 |
*/
|
299 |
private void removeFromList(String path){ |
300 |
ArrayList<ContainerObjects> temp = new ArrayList<ContainerObjects>(Arrays.asList(files)); |
301 |
for(int i = 0; i < files.length; i++){ |
302 |
if(files[i].getCName().equals(path.substring(0, path.length()-1))){ |
303 |
temp.remove(i); |
304 |
} |
305 |
} |
306 |
files = new ContainerObjects[temp.size()];
|
307 |
for(int i = 0; i < temp.size(); i++){ |
308 |
files[i] = temp.get(i); |
309 |
} |
310 |
} |
311 |
|
312 |
protected void onListItemClick(ListView l, View v, int position, long id) { |
313 |
if (curDirFiles != null && curDirFiles.length > 0) { |
314 |
Intent viewIntent; |
315 |
if(curDirFiles[position].getContentType().equals("application/directory")){ |
316 |
currentPath = curDirFiles[position].getCName() + "/";
|
317 |
loadCurrentDirectoryFiles(); |
318 |
displayCurrentFiles(); |
319 |
} |
320 |
|
321 |
else{
|
322 |
viewIntent = new Intent(this, ContainerObjectDetails.class); |
323 |
viewIntent.putExtra("container", curDirFiles[position]);
|
324 |
viewIntent.putExtra("cdnUrl", container.getCdnUrl());
|
325 |
viewIntent.putExtra("containerNames", container.getName());
|
326 |
viewIntent.putExtra("isCdnEnabled", cdnEnabledIs);
|
327 |
startActivityForResult(viewIntent, 55); // arbitrary number; never |
328 |
// used again
|
329 |
} |
330 |
} |
331 |
} |
332 |
|
333 |
/*
|
334 |
* Create the Menu options
|
335 |
*/
|
336 |
@Override
|
337 |
public boolean onCreateOptionsMenu(Menu menu) { |
338 |
super.onCreateOptionsMenu(menu);
|
339 |
MenuInflater inflater = getMenuInflater(); |
340 |
inflater.inflate(R.menu.view_container_object_list_menu, menu); |
341 |
return true; |
342 |
} |
343 |
|
344 |
@Override
|
345 |
/*
|
346 |
* option performed for delete depends on if you
|
347 |
* are at the top of a container or in a folder
|
348 |
*/
|
349 |
public boolean onOptionsItemSelected(MenuItem item) { |
350 |
switch (item.getItemId()) {
|
351 |
case R.id.delete_container:
|
352 |
if(currentPath.equals("")){ |
353 |
showDialog(deleteContainer); |
354 |
} |
355 |
else{
|
356 |
showDialog(deleteFolder); |
357 |
} |
358 |
return true; |
359 |
case R.id.enable_cdn:
|
360 |
Intent viewIntent1 = new Intent(this, EnableCDNActivity.class); |
361 |
viewIntent1.putExtra("Cname", container.getName());
|
362 |
startActivityForResult(viewIntent1, 56);
|
363 |
return true; |
364 |
case R.id.refresh:
|
365 |
loadFiles(); |
366 |
return true; |
367 |
case R.id.add_folder:
|
368 |
showDialog(R.id.add_folder); |
369 |
return true; |
370 |
case R.id.add_file:
|
371 |
Intent viewIntent2 = new Intent(this, AddFileActivity.class); |
372 |
viewIntent2.putExtra("Cname", container.getName());
|
373 |
viewIntent2.putExtra("curPath", currentPath);
|
374 |
startActivityForResult(viewIntent2, 56);
|
375 |
return true; |
376 |
} |
377 |
return false; |
378 |
} |
379 |
|
380 |
@Override
|
381 |
protected Dialog onCreateDialog(int id) { |
382 |
switch (id) {
|
383 |
case deleteContainer:
|
384 |
if(curDirFiles.length == 0){ |
385 |
return new AlertDialog.Builder(ContainerObjectsActivity.this) |
386 |
.setIcon(R.drawable.alert_dialog_icon) |
387 |
.setTitle("Delete Container")
|
388 |
.setMessage( |
389 |
"Are you sure you want to delete this Container?")
|
390 |
.setPositiveButton("Delete Container",
|
391 |
new DialogInterface.OnClickListener() {
|
392 |
public void onClick(DialogInterface dialog, |
393 |
int whichButton) {
|
394 |
// User clicked OK so do some stuff
|
395 |
new DeleteContainerTask()
|
396 |
.execute(currentPath); |
397 |
} |
398 |
}) |
399 |
.setNegativeButton("Cancel",
|
400 |
new DialogInterface.OnClickListener() {
|
401 |
public void onClick(DialogInterface dialog, |
402 |
int whichButton) {
|
403 |
// User clicked Cancel so do some stuff
|
404 |
} |
405 |
}).create(); |
406 |
} |
407 |
else{
|
408 |
return new AlertDialog.Builder(ContainerObjectsActivity.this) |
409 |
.setIcon(R.drawable.alert_dialog_icon) |
410 |
.setTitle("Delete Container")
|
411 |
.setMessage("Container must be empty to delete")
|
412 |
.setNegativeButton("OK",
|
413 |
new DialogInterface.OnClickListener() {
|
414 |
public void onClick(DialogInterface dialog, |
415 |
int whichButton) {
|
416 |
// User clicked Cancel so do some stuff
|
417 |
} |
418 |
}).create(); |
419 |
} |
420 |
case deleteFolder:
|
421 |
if(curDirFiles.length == 0){ |
422 |
return new AlertDialog.Builder(ContainerObjectsActivity.this) |
423 |
.setIcon(R.drawable.alert_dialog_icon) |
424 |
.setTitle("Delete Folder")
|
425 |
.setMessage( |
426 |
"Are you sure you want to delete this Folder?")
|
427 |
.setPositiveButton("Delete Folder",
|
428 |
new DialogInterface.OnClickListener() {
|
429 |
public void onClick(DialogInterface dialog, |
430 |
int whichButton) {
|
431 |
// User clicked OK so do some stuff
|
432 |
new DeleteObjectTask()
|
433 |
.execute(); |
434 |
} |
435 |
}) |
436 |
.setNegativeButton("Cancel",
|
437 |
new DialogInterface.OnClickListener() {
|
438 |
public void onClick(DialogInterface dialog, |
439 |
int whichButton) {
|
440 |
// User clicked Cancel so do some stuff
|
441 |
} |
442 |
}).create(); |
443 |
} |
444 |
else{
|
445 |
return new AlertDialog.Builder(ContainerObjectsActivity.this) |
446 |
.setIcon(R.drawable.alert_dialog_icon) |
447 |
.setTitle("Delete Folder")
|
448 |
.setMessage( |
449 |
"Folder must be empty to delete")
|
450 |
.setNegativeButton("OK",
|
451 |
new DialogInterface.OnClickListener() {
|
452 |
public void onClick(DialogInterface dialog, |
453 |
int whichButton) {
|
454 |
// User clicked Cancel so do some stuff
|
455 |
} |
456 |
}).create(); |
457 |
} |
458 |
case R.id.add_folder:
|
459 |
final EditText input = new EditText(this); |
460 |
return new AlertDialog.Builder(ContainerObjectsActivity.this) |
461 |
.setIcon(R.drawable.alert_dialog_icon) |
462 |
.setView(input) |
463 |
.setTitle("Add Folder")
|
464 |
.setMessage("Enter new name for folder: ")
|
465 |
.setPositiveButton("Add", new DialogInterface.OnClickListener() { |
466 |
public void onClick(DialogInterface dialog, int whichButton) { |
467 |
//User clicked OK so do some stuff
|
468 |
String[] info = {input.getText().toString(), "application/directory"}; |
469 |
new AddFolderTask().execute(info);
|
470 |
} |
471 |
}) |
472 |
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { |
473 |
public void onClick(DialogInterface dialog, int whichButton) { |
474 |
// User clicked Cancel so do some stuff
|
475 |
} |
476 |
}) |
477 |
.create(); |
478 |
} |
479 |
return null; |
480 |
} |
481 |
|
482 |
@Override
|
483 |
public void onActivityResult(int requestCode, int resultCode, Intent data) { |
484 |
super.onActivityResult(requestCode, resultCode, data);
|
485 |
|
486 |
if (resultCode == RESULT_OK) {
|
487 |
// a sub-activity kicked back, so we want to refresh the server list
|
488 |
loadFiles(); |
489 |
} |
490 |
if (requestCode == 56) { |
491 |
if (resultCode == RESULT_OK) {
|
492 |
Intent viewIntent1 = new Intent(this, |
493 |
ListContainerActivity.class); |
494 |
startActivityForResult(viewIntent1, 56);
|
495 |
} |
496 |
} |
497 |
} |
498 |
|
499 |
private CloudServersException parseCloudServersException(
|
500 |
HttpResponse response) { |
501 |
CloudServersException cse = new CloudServersException();
|
502 |
try {
|
503 |
BasicResponseHandler responseHandler = new BasicResponseHandler();
|
504 |
String body = responseHandler.handleResponse(response);
|
505 |
CloudServersFaultXMLParser parser = new CloudServersFaultXMLParser();
|
506 |
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); |
507 |
XMLReader xmlReader = saxParser.getXMLReader(); |
508 |
xmlReader.setContentHandler(parser); |
509 |
xmlReader.parse(new InputSource(new StringReader(body))); |
510 |
cse = parser.getException(); |
511 |
} catch (ClientProtocolException e) {
|
512 |
cse = new CloudServersException();
|
513 |
cse.setMessage(e.getLocalizedMessage()); |
514 |
} catch (IOException e) { |
515 |
cse = new CloudServersException();
|
516 |
cse.setMessage(e.getLocalizedMessage()); |
517 |
} catch (ParserConfigurationException e) { |
518 |
cse = new CloudServersException();
|
519 |
cse.setMessage(e.getLocalizedMessage()); |
520 |
} catch (SAXException e) {
|
521 |
cse = new CloudServersException();
|
522 |
cse.setMessage(e.getLocalizedMessage()); |
523 |
} catch (FactoryConfigurationError e) { |
524 |
cse = new CloudServersException();
|
525 |
cse.setMessage(e.getLocalizedMessage()); |
526 |
} |
527 |
return cse;
|
528 |
} |
529 |
|
530 |
class FileAdapter extends ArrayAdapter<ContainerObjects> { |
531 |
FileAdapter() { |
532 |
super(ContainerObjectsActivity.this,
|
533 |
R.layout.listcontainerobjectcell, curDirFiles); |
534 |
} |
535 |
|
536 |
public View getView(int position, View convertView, ViewGroup parent) { |
537 |
|
538 |
ContainerObjects file = curDirFiles[position]; |
539 |
LayoutInflater inflater = getLayoutInflater(); |
540 |
View row = inflater.inflate(R.layout.listcontainerobjectcell,
|
541 |
parent, false);
|
542 |
|
543 |
TextView label = (TextView) row.findViewById(R.id.label); |
544 |
//label.setText(file.getCName());
|
545 |
label.setText(getShortName(file.getCName())); |
546 |
|
547 |
if (file.getBytes() >= bConver) {
|
548 |
megaBytes = Math.abs(file.getBytes() / bConver + 0.2); |
549 |
TextView sublabel = (TextView) row.findViewById(R.id.sublabel); |
550 |
sublabel.setText(megaBytes + " MB");
|
551 |
} else if (file.getBytes() >= kbConver) { |
552 |
kiloBytes = Math.abs(file.getBytes() / kbConver + 0.2); |
553 |
TextView sublabel = (TextView) row.findViewById(R.id.sublabel); |
554 |
sublabel.setText(kiloBytes + " KB");
|
555 |
} else {
|
556 |
TextView sublabel = (TextView) row.findViewById(R.id.sublabel); |
557 |
sublabel.setText(file.getBytes() + " B");
|
558 |
} |
559 |
|
560 |
return (row);
|
561 |
} |
562 |
} |
563 |
|
564 |
private class LoadFilesTask extends |
565 |
AsyncTask<String, Void, ArrayList<ContainerObjects>> { |
566 |
|
567 |
private CloudServersException exception;
|
568 |
/*
|
569 |
protected void onPreExecute(){
|
570 |
dialog = ProgressDialog.show(ContainerObjectsActivity.this, "", "Loading Files...", true);
|
571 |
}
|
572 |
*/
|
573 |
@Override
|
574 |
protected ArrayList<ContainerObjects> doInBackground(String... path) { |
575 |
ArrayList<ContainerObjects> files = null; |
576 |
try {
|
577 |
files = (new ContainerObjectManager(context)).createList(true, |
578 |
container.getName()); |
579 |
} catch (CloudServersException e) {
|
580 |
exception = e; |
581 |
e.printStackTrace(); |
582 |
} |
583 |
return files;
|
584 |
} |
585 |
|
586 |
@Override
|
587 |
protected void onPostExecute(ArrayList<ContainerObjects> result) { |
588 |
//dialog.dismiss();
|
589 |
if (exception != null) { |
590 |
showAlert("Error", exception.getMessage());
|
591 |
} |
592 |
setFileList(result); |
593 |
} |
594 |
} |
595 |
|
596 |
private class DeleteObjectTask extends |
597 |
AsyncTask<Void, Void, HttpResponse> { |
598 |
|
599 |
private CloudServersException exception;
|
600 |
|
601 |
protected void onPreExecute(){ |
602 |
dialog = ProgressDialog.show(ContainerObjectsActivity.this, "", "Deleting...", true); |
603 |
} |
604 |
|
605 |
@Override
|
606 |
protected HttpResponse doInBackground(Void... arg0) { |
607 |
HttpResponse resp = null;
|
608 |
try {
|
609 |
//subtring because the current directory contains a "/" at the end of the string
|
610 |
resp = (new ContainerObjectManager(context)).deleteObject(container.getName(), currentPath.substring(0, currentPath.length()-1)); |
611 |
} catch (CloudServersException e) {
|
612 |
exception = e; |
613 |
} |
614 |
return resp;
|
615 |
} |
616 |
|
617 |
@Override
|
618 |
protected void onPostExecute(HttpResponse response) { |
619 |
dialog.dismiss(); |
620 |
if (response != null) { |
621 |
int statusCode = response.getStatusLine().getStatusCode();
|
622 |
if (statusCode == 409) { |
623 |
showAlert("Error",
|
624 |
"Folder must be empty in order to delete");
|
625 |
} |
626 |
if (statusCode == 204) { |
627 |
setResult(Activity.RESULT_OK); |
628 |
removeFromList(currentPath); |
629 |
goUpDirectory(); |
630 |
|
631 |
} else {
|
632 |
CloudServersException cse = parseCloudServersException(response); |
633 |
if ("".equals(cse.getMessage())) { |
634 |
showAlert("Error",
|
635 |
"There was a problem deleting your folder.");
|
636 |
} else {
|
637 |
showAlert("Error",
|
638 |
"There was a problem deleting your folder: "
|
639 |
+ cse.getMessage()); |
640 |
} |
641 |
} |
642 |
} else if (exception != null) { |
643 |
showAlert("Error", "There was a problem deleting your folder: " |
644 |
+ exception.getMessage()); |
645 |
} |
646 |
} |
647 |
} |
648 |
|
649 |
private class AddFolderTask extends |
650 |
AsyncTask<String, Void, HttpResponse> { |
651 |
|
652 |
private CloudServersException exception;
|
653 |
|
654 |
@Override
|
655 |
protected HttpResponse doInBackground(String... data) { |
656 |
HttpResponse resp = null;
|
657 |
try {
|
658 |
resp = (new ContainerObjectManager(context)).addObject(container.getName(), currentPath, data[0], data[1]); |
659 |
} catch (CloudServersException e) {
|
660 |
exception = e; |
661 |
} |
662 |
return resp;
|
663 |
} |
664 |
|
665 |
@Override
|
666 |
protected void onPostExecute(HttpResponse response) { |
667 |
//dialog.dismiss();
|
668 |
if (response != null) { |
669 |
int statusCode = response.getStatusLine().getStatusCode();
|
670 |
if (statusCode == 201) { |
671 |
setResult(Activity.RESULT_OK); |
672 |
loadFiles(); |
673 |
} else {
|
674 |
CloudServersException cse = parseCloudServersException(response); |
675 |
if ("".equals(cse.getMessage())) { |
676 |
showAlert("Error",
|
677 |
"There was a problem deleting your folder.");
|
678 |
} else {
|
679 |
showAlert("Error",
|
680 |
"There was a problem deleting your folder: "
|
681 |
+ cse.getMessage()); |
682 |
} |
683 |
} |
684 |
} else if (exception != null) { |
685 |
showAlert("Error", "There was a problem deleting your folder: " |
686 |
+ exception.getMessage()); |
687 |
} |
688 |
} |
689 |
} |
690 |
|
691 |
private class DeleteContainerTask extends |
692 |
AsyncTask<String, Void, HttpResponse> { |
693 |
|
694 |
private CloudServersException exception;
|
695 |
|
696 |
@Override
|
697 |
protected HttpResponse doInBackground(String... object) { |
698 |
HttpResponse resp = null;
|
699 |
try {
|
700 |
resp = (new ContainerManager(context)).delete(container.getName());
|
701 |
Log.v(LOG, "container's name " + container.getName());
|
702 |
} catch (CloudServersException e) {
|
703 |
exception = e; |
704 |
} |
705 |
return resp;
|
706 |
} |
707 |
|
708 |
@Override
|
709 |
protected void onPostExecute(HttpResponse response) { |
710 |
if (response != null) { |
711 |
int statusCode = response.getStatusLine().getStatusCode();
|
712 |
if (statusCode == 409) { |
713 |
showAlert("Error",
|
714 |
"Container must be empty in order to delete");
|
715 |
} |
716 |
if (statusCode == 204) { |
717 |
setResult(Activity.RESULT_OK); |
718 |
loadFiles(); |
719 |
finish(); |
720 |
|
721 |
} else {
|
722 |
CloudServersException cse = parseCloudServersException(response); |
723 |
if ("".equals(cse.getMessage())) { |
724 |
showAlert("Error",
|
725 |
"There was a problem deleting your container.");
|
726 |
} else {
|
727 |
showAlert("Error",
|
728 |
"There was a problem deleting your container: "
|
729 |
+ cse.getMessage()); |
730 |
} |
731 |
} |
732 |
} else if (exception != null) { |
733 |
showAlert("Error", "There was a problem deleting your server: " |
734 |
+ exception.getMessage()); |
735 |
} |
736 |
} |
737 |
} |
738 |
|
739 |
} |