Statistics
| Branch: | Revision:

root / src / com / rackspacecloud / android / ContainerObjectsActivity.java @ 006434d8

History | View | Annotate | Download (22 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.content.Context;
25
import android.content.DialogInterface;
26
import android.content.Intent;
27
import android.os.AsyncTask;
28
import android.os.Bundle;
29
import android.util.Log;
30
import android.view.LayoutInflater;
31
import android.view.Menu;
32
import android.view.MenuInflater;
33
import android.view.MenuItem;
34
import android.view.View;
35
import android.view.ViewGroup;
36
import android.widget.ArrayAdapter;
37
import android.widget.EditText;
38
import android.widget.ListView;
39
import android.widget.TextView;
40

    
41
import com.rackspace.cloud.files.api.client.Container;
42
import com.rackspace.cloud.files.api.client.ContainerManager;
43
import com.rackspace.cloud.files.api.client.ContainerObjectManager;
44
import com.rackspace.cloud.files.api.client.ContainerObjects;
45
import com.rackspace.cloud.servers.api.client.CloudServersException;
46
import com.rackspace.cloud.servers.api.client.http.HttpBundle;
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
        //private ProgressDialog dialog;
71
        private boolean loadingFiles;
72
        private FileAdapter adapter;
73

    
74

    
75
        @Override
76
        public void onCreate(Bundle savedInstanceState) {
77
                super.onCreate(savedInstanceState);
78
                container = (Container) this.getIntent().getExtras().get("container");
79
                Log.v(LOG, "CDNEnabled:" + container.isCdnEnabled());
80
        context = getApplicationContext();
81
                if (container.isCdnEnabled() == true) {
82
                        cdnEnabledIs = "true";
83
                } else {
84
                        cdnEnabledIs = "false";
85
                }
86
                restoreState(savedInstanceState);
87
        }
88
        
89
        @Override
90
        protected void onSaveInstanceState(Bundle outState) {
91
                super.onSaveInstanceState(outState);
92
                outState.putSerializable("container", files);
93
                outState.putString("path", currentPath);
94
                outState.putSerializable("curFiles", curDirFiles);
95
                outState.putBoolean("loadingFiles", loadingFiles);
96
        }
97
        
98
        
99

    
100
        private void restoreState(Bundle state) {
101
                
102
                adapter = (FileAdapter)getLastNonConfigurationInstance();
103
                
104
                if(state != null){
105
                        if(state.containsKey("path")){
106
                                currentPath = state.getString("path");
107
                        }
108
                        else{
109
                                currentPath = "";
110
                        }
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
                                        }
128
                                }
129
                        }
130
                }
131
                else {
132
                        currentPath = "";
133
                        loadFiles();
134
                }        
135
        }
136
        
137
        public Object onRetainNonConfigurationInstance(){
138
                return adapter;
139
        }
140

    
141
        /*
142
         * overriding back button press, because we are not actually changing
143
         * activities when we navigate the file structure
144
         */
145
        public void onBackPressed() {
146
                if(currentPath.equals("")){
147
                        finish();
148
                }
149
                else{
150
                        goUpDirectory();
151
                }
152
        }
153
        
154
        /*
155
         * go to the current directory's parent and display that data
156
         */
157
        private void goUpDirectory(){
158
                currentPath = currentPath.substring(0, currentPath.substring(0, currentPath.length()-2).lastIndexOf("/")+1);
159
                loadCurrentDirectoryFiles();
160
                displayCurrentFiles();
161
        }
162

    
163
        /*
164
         * load all file that are in the container
165
         */
166
        private void loadFiles() {
167
                displayLoadingCell();
168
                new LoadFilesTask().execute();
169
        }
170
        
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);
180
        }
181
        
182
        /* load only the files that should display for the 
183
         * current directory in the curDirFiles[]
184
         */
185
        private void loadCurrentDirectoryFiles(){
186
                ArrayList<ContainerObjects> curFiles = new ArrayList<ContainerObjects>();
187

    
188
                if(files != null){
189
                        for(int i = 0 ; i < files.length; i ++){
190
                                if(fileBelongsInDir(files[i])){
191
                                        curFiles.add(files[i]);
192
                                }
193
                        }
194

    
195
                        curDirFiles = new ContainerObjects[curFiles.size()];
196
                        for(int i = 0; i < curFiles.size(); i++){
197
                                curDirFiles[i] = curFiles.get(i);
198
                        }
199
                }
200
        }
201
        
202
        /*
203
         * determines if a file should be displayed in current 
204
         * directory
205
         */
206
        private Boolean fileBelongsInDir(ContainerObjects obj){
207
                String objPath = obj.getCName();
208
                if(!objPath.startsWith(currentPath)){
209
                        return false;
210
                }
211
                else{
212
                        objPath = objPath.substring(currentPath.length());
213
                        return !objPath.contains("/");
214
                }
215
        }
216

    
217
        
218
        /*
219
         * loads all the files that are in the container
220
         * into one array
221
         */
222
        private void setFileList(ArrayList<ContainerObjects> files) {
223
                if (files == null) {
224
                        files = new ArrayList<ContainerObjects>();
225
                }
226
                String[] fileNames = new String[files.size()];
227
                this.files = new ContainerObjects[files.size()];
228

    
229
                
230
                
231
                if (files != null) {
232
                        for (int i = 0; i < files.size(); i++) {
233
                                ContainerObjects file = files.get(i);
234
                                this.files[i] = file;
235
                                fileNames[i] = file.getName();
236
                        }
237
                }
238
                                
239
                displayCurrentFiles();
240
        }
241
        
242
        private void displayCurrentFiles(){
243
                loadCurrentDirectoryFiles();
244
                if (curDirFiles.length == 0) {
245
                        displayNoServersCell();
246
                } else {
247
                        getListView().setDividerHeight(1); // restore divider lines
248
                        adapter = new FileAdapter();
249
                        setListAdapter(adapter);
250
                }
251
        }
252

    
253
        /*
254
         * display a different empty page depending
255
         * of if you are at top of container or
256
         * in a folder
257
         */
258
        private void displayNoServersCell() {
259
                String a[] = new String[1];
260
                if(currentPath.equals("")){
261
                        a[0] = "Empty Container";
262
                        setListAdapter(new ArrayAdapter<String>(this, R.layout.noobjectscell,
263
                                R.id.no_files_label, a));
264
                }
265
                else{
266
                        a[0] = "No Files";
267
                        setListAdapter(new ArrayAdapter<String>(this, R.layout.nofilescell,
268
                                                R.id.no_files_label, a));
269
                }
270
                getListView().setTextFilterEnabled(true);
271
                getListView().setDividerHeight(0); // hide the dividers so it won't look
272
                                                                                        // like a list row
273
                getListView().setItemsCanFocus(false);
274
        }
275

    
276
        private void showAlert(String title, String message) {
277
                // Can't create handler inside thread that has not called
278
                // Looper.prepare()
279
                // Looper.prepare();
280
                try {
281
                        AlertDialog alert = new AlertDialog.Builder(this).create();
282
                        alert.setTitle(title);
283
                        alert.setMessage(message);
284
                        alert.setButton("OK", new DialogInterface.OnClickListener() {
285
                                public void onClick(DialogInterface dialog, int which) {
286
                                        return;
287
                                }
288
                        });
289
                        alert.show();
290
                } catch (Exception e) {
291
                        e.printStackTrace();
292
                }
293
        }
294

    
295
        /* just get the last part of the filename
296
         * so the entire file path does not show
297
        */
298
        private String getShortName(String longName){
299
                String s = longName;
300
                if(!s.contains("/")){
301
                        return s;
302
                }
303
                else {
304
                        return s.substring(s.lastIndexOf('/')+1);
305
                }
306
        }
307
        
308
        /*
309
         * removed a specified object from the array of 
310
         * all the files in the container
311
         */
312
        private void removeFromList(String path){
313
                ArrayList<ContainerObjects> temp = new ArrayList<ContainerObjects>(Arrays.asList(files));
314
                for(int i = 0; i < files.length; i++){
315
                        if(files[i].getCName().equals(path.substring(0, path.length()-1))){
316
                                temp.remove(i);
317
                        }
318
                }
319
                files = new ContainerObjects[temp.size()];
320
                for(int i = 0; i < temp.size(); i++){
321
                        files[i] = temp.get(i);
322
                }
323
        }
324

    
325
        protected void onListItemClick(ListView l, View v, int position, long id) {
326
                if (curDirFiles != null && curDirFiles.length > 0) {
327
                        Intent viewIntent;
328
                        if(curDirFiles[position].getContentType().equals("application/directory")){                        
329
                                currentPath = curDirFiles[position].getCName() + "/";
330
                                loadCurrentDirectoryFiles();
331
                                displayCurrentFiles();
332
                        }
333
        
334
                        else{
335
                                viewIntent = new Intent(this, ContainerObjectDetails.class);
336
                                viewIntent.putExtra("container", curDirFiles[position]);
337
                                viewIntent.putExtra("cdnUrl", container.getCdnUrl());
338
                                viewIntent.putExtra("containerNames", container.getName());
339
                                viewIntent.putExtra("isCdnEnabled", cdnEnabledIs);
340
                                startActivityForResult(viewIntent, 55); // arbitrary number; never
341
                                // used again
342
                        }
343
                }
344
        }
345

    
346
        /* 
347
         * Create the Menu options
348
         */
349
        @Override
350
        public boolean onCreateOptionsMenu(Menu menu) {
351
                super.onCreateOptionsMenu(menu);
352
                MenuInflater inflater = getMenuInflater();
353
                inflater.inflate(R.menu.view_container_object_list_menu, menu);
354
                return true;
355
        }
356

    
357
        @Override
358
        /*
359
         * option performed for delete depends on if you
360
         * are at the top of a container or in a folder
361
         */
362
        public boolean onOptionsItemSelected(MenuItem item) {
363
                switch (item.getItemId()) {
364
                case R.id.delete_container:
365
                        if(currentPath.equals("")){
366
                                showDialog(deleteContainer);
367
                        }
368
                        else{
369
                                showDialog(deleteFolder);
370
                        }
371
                        return true;
372
                case R.id.enable_cdn:
373
                        Intent viewIntent1 = new Intent(this, EnableCDNActivity.class);
374
                        viewIntent1.putExtra("Cname", container.getName());
375
                        startActivityForResult(viewIntent1, 56);
376
                        return true;
377
                case R.id.refresh:
378
                        loadFiles();
379
                        return true;
380
                case R.id.add_folder:
381
                        showDialog(R.id.add_folder);
382
                        return true;
383
                case R.id.add_file:
384
                        Intent viewIntent2 = new Intent(this, AddFileActivity.class);
385
                        viewIntent2.putExtra("Cname", container.getName());
386
                        viewIntent2.putExtra("curPath", currentPath);
387
                        startActivityForResult(viewIntent2, 56);
388
                        return true;        
389
                }
390
                return false;
391
        }
392

    
393
        @Override
394
        protected Dialog onCreateDialog(int id) {
395
                switch (id) {
396
                case deleteContainer:
397
                        if(curDirFiles.length == 0){
398
                                return new AlertDialog.Builder(ContainerObjectsActivity.this)
399
                                .setIcon(R.drawable.alert_dialog_icon)
400
                                .setTitle("Delete Container")
401
                                .setMessage(
402
                                "Are you sure you want to delete this Container?")
403
                                .setPositiveButton("Delete Container",
404
                                                new DialogInterface.OnClickListener() {
405
                                        public void onClick(DialogInterface dialog,
406
                                                        int whichButton) {
407
                                                // User clicked OK so do some stuff
408
                                                new DeleteContainerTask()
409
                                                .execute(currentPath);
410
                                        }
411
                                })
412
                                .setNegativeButton("Cancel",
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
                        else{
421
                                return new AlertDialog.Builder(ContainerObjectsActivity.this)
422
                                .setIcon(R.drawable.alert_dialog_icon)
423
                                .setTitle("Delete Container")
424
                                .setMessage("Container must be empty to delete")
425
                                .setNegativeButton("OK",
426
                                                new DialogInterface.OnClickListener() {
427
                                        public void onClick(DialogInterface dialog,
428
                                                        int whichButton) {
429
                                                // User clicked Cancel so do some stuff
430
                                        }
431
                                }).create();
432
                        }
433
                case deleteFolder:
434
                        if(curDirFiles.length == 0){
435
                                return new AlertDialog.Builder(ContainerObjectsActivity.this)
436
                                .setIcon(R.drawable.alert_dialog_icon)
437
                                .setTitle("Delete Folder")
438
                                .setMessage(
439
                                "Are you sure you want to delete this Folder?")
440
                                .setPositiveButton("Delete Folder",
441
                                                new DialogInterface.OnClickListener() {
442
                                        public void onClick(DialogInterface dialog,
443
                                                        int whichButton) {
444
                                                // User clicked OK so do some stuff
445
                                                new DeleteObjectTask().execute();
446
                                        }
447
                                })
448
                                .setNegativeButton("Cancel",
449
                                                new DialogInterface.OnClickListener() {
450
                                        public void onClick(DialogInterface dialog,
451
                                                        int whichButton) {
452
                                                // User clicked Cancel so do some stuff
453
                                        }
454
                                }).create();
455
                        }
456
                        else{
457
                                return new AlertDialog.Builder(ContainerObjectsActivity.this)
458
                                .setIcon(R.drawable.alert_dialog_icon)
459
                                .setTitle("Delete Folder")
460
                                .setMessage(
461
                                "Folder must be empty to delete")
462
                                .setNegativeButton("OK",
463
                                                new DialogInterface.OnClickListener() {
464
                                        public void onClick(DialogInterface dialog,
465
                                                        int whichButton) {
466
                                                // User clicked Cancel so do some stuff
467
                                        }
468
                                }).create();
469
                        }
470
                case R.id.add_folder:
471
                        final EditText input = new EditText(this);
472
            return new AlertDialog.Builder(ContainerObjectsActivity.this)
473
                .setIcon(R.drawable.alert_dialog_icon)
474
            .setView(input)
475
                .setTitle("Add Folder")
476
                .setMessage("Enter new name for folder: ")                         
477
                .setPositiveButton("Add", new DialogInterface.OnClickListener() {
478
                        public void onClick(DialogInterface dialog, int whichButton) {
479
                                //User clicked OK so do some stuff
480
                                String[] info = {input.getText().toString(), "application/directory"};
481
                                new AddFolderTask().execute(info);
482
                        }
483
                })
484
                .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
485
                        public void onClick(DialogInterface dialog, int whichButton) {
486
                                // User clicked Cancel so do some stuff
487
                        }
488
                })
489
                .create();     
490
                }
491
                return null;
492
        }
493

    
494
        @Override
495
        public void onActivityResult(int requestCode, int resultCode, Intent data) {
496
                super.onActivityResult(requestCode, resultCode, data);
497

    
498
                if (resultCode == RESULT_OK) {
499
                        // a sub-activity kicked back, so we want to refresh the server list
500
                        loadFiles();
501
                }
502
                /*
503
                if (requestCode == 56) {
504
                        if (resultCode == RESULT_OK) {
505
                                Intent viewIntent1 = new Intent(this,
506
                                                ListContainerActivity.class);
507
                                startActivityForResult(viewIntent1, 56);
508
                        }
509
                }
510
                */
511
        }
512

    
513
        private CloudServersException parseCloudServersException(
514
                        HttpResponse response) {
515
                CloudServersException cse = new CloudServersException();
516
                try {
517
                        BasicResponseHandler responseHandler = new BasicResponseHandler();
518
                        String body = responseHandler.handleResponse(response);
519
                        CloudServersFaultXMLParser parser = new CloudServersFaultXMLParser();
520
                        SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
521
                        XMLReader xmlReader = saxParser.getXMLReader();
522
                        xmlReader.setContentHandler(parser);
523
                        xmlReader.parse(new InputSource(new StringReader(body)));
524
                        cse = parser.getException();
525
                } catch (ClientProtocolException e) {
526
                        cse = new CloudServersException();
527
                        cse.setMessage(e.getLocalizedMessage());
528
                } catch (IOException e) {
529
                        cse = new CloudServersException();
530
                        cse.setMessage(e.getLocalizedMessage());
531
                } catch (ParserConfigurationException e) {
532
                        cse = new CloudServersException();
533
                        cse.setMessage(e.getLocalizedMessage());
534
                } catch (SAXException e) {
535
                        cse = new CloudServersException();
536
                        cse.setMessage(e.getLocalizedMessage());
537
                } catch (FactoryConfigurationError e) {
538
                        cse = new CloudServersException();
539
                        cse.setMessage(e.getLocalizedMessage());
540
                }
541
                return cse;
542
        }
543
        
544
        private void startFileError(String message, HttpBundle bundle){
545
                Intent viewIntent = new Intent(getApplicationContext(), ServerErrorActivity.class);
546
                viewIntent.putExtra("errorMessage", message);
547
                viewIntent.putExtra("response", bundle.getResponseText());
548
                viewIntent.putExtra("request", bundle.getCurlRequest());
549
                startActivity(viewIntent);
550
        }
551
        
552
        class FileAdapter extends ArrayAdapter<ContainerObjects> {
553
                FileAdapter() {
554
                        super(ContainerObjectsActivity.this,
555
                                        R.layout.listcontainerobjectcell, curDirFiles);                
556
                }
557
        
558
                public View getView(int position, View convertView, ViewGroup parent) {
559
        
560
                        Log.d("info", "captin updating position " + position);
561
                        
562
                        ContainerObjects file = curDirFiles[position];
563
                        LayoutInflater inflater = getLayoutInflater();
564
                        View row = inflater.inflate(R.layout.listcontainerobjectcell,
565
                                        parent, false);
566
        
567
                        TextView label = (TextView) row.findViewById(R.id.label);
568
                        //label.setText(file.getCName());
569
                        label.setText(getShortName(file.getCName()));
570
        
571
                        if (file.getBytes() >= bConver) {
572
                                megaBytes = Math.abs(file.getBytes() / bConver + 0.2);
573
                                TextView sublabel = (TextView) row.findViewById(R.id.sublabel);
574
                                sublabel.setText(megaBytes + " MB");
575
                        } else if (file.getBytes() >= kbConver) {
576
                                kiloBytes = Math.abs(file.getBytes() / kbConver + 0.2);
577
                                TextView sublabel = (TextView) row.findViewById(R.id.sublabel);
578
                                sublabel.setText(kiloBytes + " KB");
579
                        } else {
580
                                TextView sublabel = (TextView) row.findViewById(R.id.sublabel);
581
                                sublabel.setText(file.getBytes() + " B");
582
                        }
583
        
584
                        return (row);
585
                }
586
        }
587

    
588
        private class LoadFilesTask extends
589
                        AsyncTask<String, Void, ArrayList<ContainerObjects>> {
590

    
591
                private CloudServersException exception;
592
                protected void onPreExecute(){
593
                        loadingFiles = true;
594
                }
595
                
596
                @Override
597
                protected ArrayList<ContainerObjects> doInBackground(String... path) {
598
                        ArrayList<ContainerObjects> files = null;
599
                        try {
600
                                files = (new ContainerObjectManager(context)).createList(true,
601
                                                container.getName());
602
                        } catch (CloudServersException e) {
603
                                exception = e;
604
                                e.printStackTrace();
605
                        }
606
                        return files;
607
                }
608
        
609
                @Override
610
                protected void onPostExecute(ArrayList<ContainerObjects> result) {
611
                        //dialog.dismiss();
612
                        if (exception != null) {
613
                                showAlert("Error", exception.getMessage());
614
                        }
615
                        Log.d("info", "captin the length of the fiels is " + result.size());
616
                        setFileList(result);
617
                        loadingFiles = false;
618
                }
619

    
620
        }
621

    
622
        private class DeleteObjectTask extends
623
        AsyncTask<Void, Void, HttpBundle> {
624

    
625
                private CloudServersException exception;
626
                
627
                protected void onPreExecute(){
628
                        //dialog = ProgressDialog.show(ContainerObjectsActivity.this, "", "Deleting...", true);
629
                }
630
                
631
                @Override
632
                protected HttpBundle doInBackground(Void... arg0) {
633
                        HttpBundle bundle = null;
634
                        try {
635
                                //subtring because the current directory contains a "/" at the end of the string
636
                                bundle = (new ContainerObjectManager(context)).deleteObject(container.getName(), currentPath.substring(0, currentPath.length()-1));
637
                        } catch (CloudServersException e) {
638
                                exception = e;
639
                        }
640
                        return bundle;
641
                }
642

    
643
                @Override
644
                protected void onPostExecute(HttpBundle bundle) {
645
                        HttpResponse response = bundle.getResponse();
646
                        if (response != null) {
647
                                int statusCode = response.getStatusLine().getStatusCode();
648
                                if (statusCode == 409) {
649
                                        showAlert("Error",
650
                                        "Folder must be empty in order to delete");
651
                                }
652
                                if (statusCode == 204) {
653
                                        setResult(Activity.RESULT_OK);
654
                                        removeFromList(currentPath);
655
                                        goUpDirectory();
656
                                        
657
                                } else {
658
                                        CloudServersException cse = parseCloudServersException(response);
659
                                        if ("".equals(cse.getMessage())) {
660
                                                startFileError("There was a problem deleting your folder.", bundle);
661
                                        } else {
662
                                                startFileError("There was a problem deleting your folder: "
663
                                                                        + cse.getMessage(), bundle);
664
                                        }
665
                                }
666
                        } else if (exception != null) {
667
                                startFileError("There was a problem deleting your folder: "
668
                                                + exception.getMessage(), bundle);
669
                        }
670
                }
671
        }
672
        
673
        private class AddFolderTask extends
674
        AsyncTask<String, Void, HttpBundle> {
675
        
676
                private CloudServersException exception;
677
                
678
                @Override
679
                protected HttpBundle doInBackground(String... data) {
680
                        HttpBundle bundle = null;
681
                        try {
682
                                bundle = (new ContainerObjectManager(context)).addObject(container.getName(), currentPath, data[0], data[1]);
683
                        } catch (CloudServersException e) {
684
                                exception = e;
685
                        }
686
                        return bundle;
687
                }
688
        
689
                @Override
690
                protected void onPostExecute(HttpBundle bundle) {
691
                        HttpResponse response = bundle.getResponse();
692
                        if (response != null) {
693
                                int statusCode = response.getStatusLine().getStatusCode();
694
                                Log.d("info", "captin the status code is " + statusCode);
695
                                if (statusCode == 201) {
696
                                        setResult(Activity.RESULT_OK);
697
                                        loadFiles();
698
                                } else {
699
                                        CloudServersException cse = parseCloudServersException(response);
700
                                        if ("".equals(cse.getMessage())) {
701
                                                startFileError("There was a problem deleting your folder.", bundle);
702
                                        } else {
703
                                                startFileError("There was a problem deleting your folder: "
704
                                                                        + cse.getMessage(), bundle);
705
                                        }
706
                                }
707
                        } else if (exception != null) {
708
                                startFileError("There was a problem deleting your folder: "
709
                                                + exception.getMessage(), bundle);
710
                        }
711
                }
712
        }
713

    
714
        private class DeleteContainerTask extends
715
        AsyncTask<String, Void, HttpBundle> {
716

    
717
                private CloudServersException exception;
718

    
719
                @Override
720
                protected HttpBundle doInBackground(String... object) {
721
                        HttpBundle bundle = null;
722
                        try {
723
                                bundle = (new ContainerManager(context)).delete(container.getName());
724
                        } catch (CloudServersException e) {
725
                                exception = e;
726
                        }
727
                        return bundle;
728
                }
729

    
730
                @Override
731
                protected void onPostExecute(HttpBundle bundle) {
732
                        HttpResponse response = bundle.getResponse();
733
                        if (response != null) {
734
                                int statusCode = response.getStatusLine().getStatusCode();
735
                                if (statusCode == 409) {
736
                                        startFileError("Container must be empty in order to delete", bundle);
737
                                }
738
                                if (statusCode == 204) {
739
                                        setResult(Activity.RESULT_OK);
740
                                        loadFiles();
741
                                        finish();
742

    
743
                                } else {
744
                                        CloudServersException cse = parseCloudServersException(response);
745
                                        if ("".equals(cse.getMessage())) {
746
                                                startFileError("There was a problem deleting your container.", bundle);
747
                                        } else {
748
                                                startFileError("There was a problem deleting your container: "
749
                                                                        + cse.getMessage(), bundle);
750
                                        }
751
                                }
752
                        } else if (exception != null) {
753
                                startFileError("There was a problem deleting your server: "
754
                                                + exception.getMessage(), bundle);
755
                        }
756
                }
757
        }
758

    
759
}