Statistics
| Branch: | Revision:

root / src / com / rackspacecloud / android / ContainerObjectsActivity.java @ 5018a7f8

History | View | Annotate | Download (21.8 kB)

1
package com.rackspacecloud.android;
2

    
3
import java.util.ArrayList;
4
import java.util.Arrays;
5

    
6
import org.apache.http.HttpResponse;
7

    
8
import android.app.Activity;
9
import android.app.AlertDialog;
10
import android.app.Dialog;
11
import android.content.DialogInterface;
12
import android.content.Intent;
13
import android.os.AsyncTask;
14
import android.os.Bundle;
15
import android.view.LayoutInflater;
16
import android.view.Menu;
17
import android.view.MenuInflater;
18
import android.view.MenuItem; 
19
import android.view.View;
20
import android.view.ViewGroup;
21
import android.widget.ArrayAdapter;
22
import android.widget.EditText;
23
import android.widget.ImageView;
24
import android.widget.ListView;
25
import android.widget.TextView;
26

    
27
import com.rackspace.cloud.files.api.client.Container;
28
import com.rackspace.cloud.files.api.client.ContainerManager;
29
import com.rackspace.cloud.files.api.client.ContainerObjectManager;
30
import com.rackspace.cloud.files.api.client.ContainerObjects;
31
import com.rackspace.cloud.servers.api.client.CloudServersException;
32
import com.rackspace.cloud.servers.api.client.http.HttpBundle;
33

    
34
/**
35
 * 
36
 * @author Phillip Toohill
37
 * 
38
 */
39

    
40
public class ContainerObjectsActivity extends CloudListActivity {
41

    
42
        private static final int deleteContainer = 0;
43
        private static final int deleteFolder = 1;
44

    
45
        private ContainerObjects[] files;
46
        private static Container container;
47
        public String LOG = "viewFilesActivity";
48
        private String cdnEnabledIs;
49
        public Object megaBytes;
50
        public Object kiloBytes;
51
        public int bConver = 1048576;
52
        public int kbConver = 1024;
53
        private boolean loadingFiles;
54
        private String currentPath;
55
        private AndroidCloudApplication app;
56
        private AddObjectListenerTask task;
57
        private DeleteObjectListenerTask deleteObjTask;
58
        private DeleteContainerListenerTask deleteContainerTask;
59

    
60
        @Override
61
        public void onCreate(Bundle savedInstanceState) {
62
                super.onCreate(savedInstanceState);
63
                trackPageView(GoogleAnalytics.PAGE_FOLDER);
64
                container = (Container) this.getIntent().getExtras().get("container");
65
                if (container.isCdnEnabled() == true) {
66
                        cdnEnabledIs = "true";
67
                } else {
68
                        cdnEnabledIs = "false";
69
                }
70
                restoreState(savedInstanceState);
71
        }
72

    
73
        @Override
74
        protected void onSaveInstanceState(Bundle outState) {
75
                super.onSaveInstanceState(outState);
76

    
77
                //files stores all the files in the container
78
                outState.putSerializable("container", files);
79

    
80
                //current path represents where you have "navigated" to
81
                outState.putString("path", currentPath);
82

    
83
                outState.putBoolean("loadingFiles", loadingFiles);
84
        }
85

    
86

    
87

    
88
        protected void restoreState(Bundle state) {
89
                super.restoreState(state);
90

    
91
                /*
92
                 * need reference to the app so you can access curDirFiles
93
                 * as well as processing status
94
                 */
95
                app = (AndroidCloudApplication)this.getApplication();
96

    
97
                if(state != null){
98
                        if(state.containsKey("path")){
99
                                currentPath = state.getString("path");
100
                        }
101
                        else{
102
                                currentPath = "";
103
                        }
104

    
105
                        if(state.containsKey("loadingFiles") && state.getBoolean("loadingFiles")){
106
                                loadFiles();
107
                        }
108
                        else if(state.containsKey("container")){
109
                                files = (ContainerObjects[]) state.getSerializable("container");
110
                                if (app.getCurFiles() == null || app.getCurFiles().size() == 0) {
111
                                        displayNoFilesCell();
112
                                } else {
113
                                        getListView().setDividerHeight(1); // restore divider lines
114
                                        setListAdapter(new FileAdapter());
115

    
116
                                }
117

    
118
                        }
119
                }
120
                else {
121
                        currentPath = "";
122
                        loadFiles();
123
                }        
124

    
125
                /*
126
                 * if the app is process when we enter the activity
127
                 * we must listen for the new curDirFiles list
128
                 */
129
                if(app.isAddingObject()){
130
                        task = new AddObjectListenerTask();
131
                        task.execute();
132
                }
133

    
134
                if(app.isDeletingObject()){
135
                        displayNoFilesCell();
136
                        deleteObjTask = new DeleteObjectListenerTask();
137
                        deleteObjTask.execute();
138
                }
139

    
140
                if(app.isDeletingContainer()){
141
                        displayNoFilesCell();
142
                        deleteContainerTask = new DeleteContainerListenerTask();
143
                        deleteContainerTask.execute();
144
                }
145

    
146

    
147
        }
148

    
149
        @Override
150
        protected void onStop(){
151
                super.onStop();
152

    
153
                /*
154
                 * Need to stop running listener task
155
                 * if we exit
156
                 */
157
                if(task != null){
158
                        task.cancel(true);
159
                }
160

    
161
                if(deleteObjTask != null){
162
                        deleteObjTask.cancel(true);
163
                }
164

    
165
                if(deleteContainerTask != null){
166
                        deleteContainerTask.cancel(true);
167
                }
168

    
169
        }
170

    
171
        /*
172
         * overriding back button press, because we are not actually changing
173
         * activities when we navigate the file structure
174
         */
175
        public void onBackPressed() {
176
                if(currentPath.equals("")){
177
                        finish();
178
                }
179
                else{
180
                        goUpDirectory();
181
                }
182
        }
183

    
184
        /*
185
         * go to the current directory's parent and display that data
186
         */
187
        private void goUpDirectory(){
188
                currentPath = currentPath.substring(0, currentPath.substring(0, currentPath.length()-2).lastIndexOf("/")+1);
189
                loadCurrentDirectoryFiles();
190
                displayCurrentFiles();
191
        }
192

    
193
        /*
194
         * load all file that are in the container
195
         */
196
        private void loadFiles() {
197
                //displayLoadingCell();
198
                new LoadFilesTask().execute();
199
        }
200

    
201

    
202
        /* load only the files that should display for the 
203
         * current directory in the curDirFiles[]
204
         */
205
        private void loadCurrentDirectoryFiles(){
206
                ArrayList<ContainerObjects> curFiles = new ArrayList<ContainerObjects>();
207

    
208
                if(files != null){
209
                        for(int i = 0 ; i < files.length; i ++){
210
                                if(fileBelongsInDir(files[i])){
211
                                        curFiles.add(files[i]);
212
                                }
213
                        }
214
                        app.setCurFiles(curFiles);
215
                }
216
        }
217

    
218
        /*
219
         * determines if a file should be displayed in current 
220
         * directory
221
         */
222
        private Boolean fileBelongsInDir(ContainerObjects obj){
223
                String objPath = obj.getCName();
224
                if(!objPath.startsWith(currentPath)){
225
                        return false;
226
                }
227
                else{
228
                        objPath = objPath.substring(currentPath.length());
229
                        return !objPath.contains("/");
230
                }
231
        }
232

    
233

    
234
        /*
235
         * loads all the files that are in the container
236
         * into one array
237
         */
238
        private void setFileList(ArrayList<ContainerObjects> files) {
239
                if (files == null) {
240
                        files = new ArrayList<ContainerObjects>();
241
                }
242
                String[] fileNames = new String[files.size()];
243
                this.files = new ContainerObjects[files.size()];
244

    
245

    
246

    
247
                if (files != null) {
248
                        for (int i = 0; i < files.size(); i++) {
249
                                ContainerObjects file = files.get(i);
250
                                this.files[i] = file;
251
                                fileNames[i] = file.getName();
252
                        }
253
                }
254
        }
255

    
256
        private void displayCurrentFiles(){
257
                if (app.getCurFiles().size() == 0) {
258
                        displayNoFilesCell();
259
                } else {
260
                        ArrayList<ContainerObjects> tempList = new ArrayList<ContainerObjects>();
261
                        for(int i = 0; i < app.getCurFiles().size(); i++){
262
                                tempList.add(app.getCurFiles().get(i));
263
                        }
264
                        getListView().setDividerHeight(1); // restore divider lines
265
                        setListAdapter(new FileAdapter());
266
                }
267
        }
268

    
269
        /*
270
         * display a different empty page depending
271
         * of if you are at top of container or
272
         * in a folder
273
         */
274
        private void displayNoFilesCell() {
275
                String a[] = new String[1];
276
                if(currentPath.equals("")){
277
                        a[0] = "Empty Container";
278
                        setListAdapter(new ArrayAdapter<String>(this, R.layout.noobjectscell,
279
                                        R.id.no_files_label, a));
280
                }
281
                else{
282
                        a[0] = "No Files";
283
                        setListAdapter(new ArrayAdapter<String>(this, R.layout.nofilescell,
284
                                        R.id.no_files_label, a));
285
                }
286
                getListView().setTextFilterEnabled(true);
287
                getListView().setDividerHeight(0); // hide the dividers so it won't look
288
                // like a list row
289
                getListView().setItemsCanFocus(false);
290
        }
291

    
292
        /* just get the last part of the filename
293
         * so the entire file path does not show
294
         */
295
        private String getShortName(String longName){
296
                String s = longName;
297
                if(!s.contains("/")){
298
                        return s;
299
                }
300
                else {
301
                        return s.substring(s.lastIndexOf('/')+1);
302
                }
303
        }
304

    
305
        /*
306
         * removed a specified object from the array of 
307
         * all the files in the container
308
         */
309
        private void removeFromList(String path){
310
                ArrayList<ContainerObjects> temp = new ArrayList<ContainerObjects>(Arrays.asList(files));
311
                for(int i = 0; i < files.length; i++){
312
                        if(files[i].getCName().equals(path.substring(0, path.length()-1))){
313
                                temp.remove(i);
314
                        }
315
                }
316
                files = new ContainerObjects[temp.size()];
317
                for(int i = 0; i < temp.size(); i++){
318
                        files[i] = temp.get(i);
319
                }
320
        }
321

    
322
        protected void onListItemClick(ListView l, View v, int position, long id) {
323
                if (app.getCurFiles() != null && app.getCurFiles().size() > 0) {
324
                        Intent viewIntent;
325
                        if(app.getCurFiles().get(position).getContentType().equals("application/directory")){                        
326
                                currentPath = app.getCurFiles().get(position).getCName() + "/";
327
                                loadCurrentDirectoryFiles();
328
                                displayCurrentFiles();
329
                        }
330

    
331
                        else{
332
                                viewIntent = new Intent(this, ContainerObjectDetails.class);
333
                                viewIntent.putExtra("container", app.getCurFiles().get(position));
334
                                viewIntent.putExtra("cdnUrl", container.getCdnUrl());
335
                                viewIntent.putExtra("containerNames", container.getName());
336
                                viewIntent.putExtra("isCdnEnabled", cdnEnabledIs);
337
                                startActivityForResult(viewIntent, 55); // arbitrary number; never
338
                                // used again
339
                        }
340
                }
341
        }
342

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

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

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

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

    
496
                if (resultCode == RESULT_OK && requestCode == 56) {
497
                        // a sub-activity kicked back, so we want to refresh the server list
498
                        loadFiles();
499
                }
500

    
501
                // deleted file so need to update the list
502
                if (requestCode == 55 && resultCode == 99) {
503
                        loadFiles();
504
                }
505

    
506
        }
507

    
508
        class FileAdapter extends ArrayAdapter<ContainerObjects> {
509
                FileAdapter() {
510
                        super(ContainerObjectsActivity.this,
511
                                        R.layout.listcontainerobjectcell, app.getCurFiles());        
512
                }
513

    
514
                public View getView(int position, View convertView, ViewGroup parent) {
515
                        ContainerObjects file = app.getCurFiles().get(position);
516
                        LayoutInflater inflater = getLayoutInflater();
517
                        View row = inflater.inflate(R.layout.listcontainerobjectcell,
518
                                        parent, false);
519

    
520
                        TextView label = (TextView) row.findViewById(R.id.label);
521
                        label.setText(getShortName(file.getCName()));
522

    
523
                        ImageView objectImage = (ImageView) row.findViewById(R.id.file_type_image);
524
                        if(file.getContentType().equals("application/directory")){
525
                                objectImage.setImageResource(R.drawable.folder);
526
                        } else {
527
                                objectImage.setImageResource(R.drawable.file);
528
                        }
529
                        
530
                        if (file.getBytes() >= bConver) {
531
                                megaBytes = Math.abs(file.getBytes() / bConver + 0.2);
532
                                TextView sublabel = (TextView) row.findViewById(R.id.sublabel);
533
                                sublabel.setText(megaBytes + " MB");
534
                        } else if (file.getBytes() >= kbConver) {
535
                                kiloBytes = Math.abs(file.getBytes() / kbConver + 0.2);
536
                                TextView sublabel = (TextView) row.findViewById(R.id.sublabel);
537
                                sublabel.setText(kiloBytes + " KB");
538
                        } else {
539
                                TextView sublabel = (TextView) row.findViewById(R.id.sublabel);
540
                                sublabel.setText(file.getBytes() + " B");
541
                        }
542

    
543
                        return (row);
544
                }
545
        }
546

    
547
        private class LoadFilesTask extends
548
        AsyncTask<String, Void, ArrayList<ContainerObjects>> {
549

    
550
                private CloudServersException exception;
551

    
552
                protected void onPreExecute(){
553
                        showDialog();
554
                        loadingFiles = true;
555
                }
556

    
557
                @Override
558
                protected ArrayList<ContainerObjects> doInBackground(String... path) {
559
                        ArrayList<ContainerObjects> files = null;
560
                        try {
561
                                files = (new ContainerObjectManager(getContext())).createList(true,
562
                                                container.getName());
563
                        } catch (CloudServersException e) {
564
                                exception = e;
565
                                e.printStackTrace();
566
                        }
567
                        return files;
568
                }
569

    
570
                @Override
571
                protected void onPostExecute(ArrayList<ContainerObjects> result) {
572
                        loadingFiles = false;
573
                        hideDialog();
574
                        if (exception != null) {
575
                                showAlert("Error", exception.getMessage());
576
                        }
577
                        setFileList(result);
578
                        loadCurrentDirectoryFiles();
579
                        displayCurrentFiles();
580
                }
581

    
582
        }
583

    
584
        private class AddFolderTask extends
585
        AsyncTask<String, Void, HttpBundle> {
586

    
587
                private CloudServersException exception;
588

    
589
                @Override
590
                protected void onPreExecute(){
591
                        showDialog();
592
                        app.setAddingObject(true);
593
                        task = new AddObjectListenerTask();
594
                        task.execute();
595
                }
596

    
597
                @Override
598
                protected HttpBundle doInBackground(String... data) {
599
                        HttpBundle bundle = null;
600
                        try {
601

    
602
                                bundle = (new ContainerObjectManager(getContext())).addObject(container.getName(), currentPath, data[0], data[1]);
603
                        } catch (CloudServersException e) {
604
                                exception = e;
605
                        }
606
                        return bundle;
607
                }
608

    
609
                @Override
610
                protected void onPostExecute(HttpBundle bundle) {
611
                        app.setAddingObject(false);
612
                        hideDialog();
613
                        HttpResponse response = bundle.getResponse();
614
                        if (response != null) {
615
                                int statusCode = response.getStatusLine().getStatusCode();
616
                                if (statusCode == 201) {
617
                                        setResult(Activity.RESULT_OK);
618
                                        //loading the new files is done by ListenerTask
619
                                } else {
620
                                        CloudServersException cse = parseCloudServersException(response);
621
                                        if ("".equals(cse.getMessage())) {
622
                                                showError("There was a problem deleting your folder.", bundle);
623
                                        } else {
624
                                                showError("There was a problem deleting your folder: "
625
                                                                + cse.getMessage(), bundle);
626
                                        }
627
                                }
628
                        } else if (exception != null) {
629
                                showError("There was a problem deleting your folder: "
630
                                                + exception.getMessage(), bundle);
631
                        }
632
                }
633
        }
634

    
635
        private class DeleteObjectTask extends
636
        AsyncTask<Void, Void, HttpBundle> {
637

    
638
                private CloudServersException exception;
639

    
640
                @Override
641
                protected void onPreExecute(){
642
                        showDialog();
643
                        app.setDeleteingObject(true);
644
                        deleteObjTask = new DeleteObjectListenerTask();
645
                        deleteObjTask.execute();
646
                }
647

    
648
                @Override
649
                protected HttpBundle doInBackground(Void... arg0) {
650
                        HttpBundle bundle = null;
651
                        try {
652
                                //subtring because the current directory contains a "/" at the end of the string
653
                                bundle = (new ContainerObjectManager(getContext())).deleteObject(container.getName(), currentPath.substring(0, currentPath.length()-1));
654
                        } catch (CloudServersException e) {
655
                                exception = e;
656
                        }
657
                        return bundle;
658
                }
659

    
660
                @Override
661
                protected void onPostExecute(HttpBundle bundle) {
662
                        app.setDeleteingObject(false);
663
                        hideDialog();
664
                        HttpResponse response = bundle.getResponse();
665
                        if (response != null) {
666
                                int statusCode = response.getStatusLine().getStatusCode();
667
                                if (statusCode == 409) {
668
                                        showAlert("Error",
669
                                        "Folder must be empty in order to delete");
670
                                }
671
                                if (statusCode == 204) {
672
                                        setResult(Activity.RESULT_OK);
673
                                } else {
674
                                        CloudServersException cse = parseCloudServersException(response);
675
                                        if ("".equals(cse.getMessage())) {
676
                                                showError("There was a problem deleting your folder.", bundle);
677
                                        } else {
678
                                                showError("There was a problem deleting your folder: "
679
                                                                + cse.getMessage(), bundle);
680
                                        }
681
                                }
682
                        } else if (exception != null) {
683
                                showError("There was a problem deleting your folder: "
684
                                                + exception.getMessage(), bundle);
685
                        }
686
                }
687
        }
688

    
689
        private class DeleteContainerTask extends
690
        AsyncTask<String, Void, HttpBundle> {
691

    
692
                private CloudServersException exception;
693

    
694
                @Override
695
                protected void onPreExecute(){ 
696
                        showDialog();
697
                        app.setDeletingContainer(true);
698
                        deleteContainerTask = new DeleteContainerListenerTask();
699
                        deleteContainerTask.execute();
700
                }
701

    
702
                @Override
703
                protected HttpBundle doInBackground(String... object) {
704
                        HttpBundle bundle = null;
705
                        try {
706
                                bundle = (new ContainerManager(getContext())).delete(container.getName());
707
                        } catch (CloudServersException e) {
708
                                exception = e;
709
                        }
710
                        return bundle;
711
                }
712

    
713
                @Override
714
                protected void onPostExecute(HttpBundle bundle) {
715
                        hideDialog();
716
                        app.setDeletingContainer(false);
717
                        HttpResponse response = bundle.getResponse();
718
                        if (response != null) {
719
                                int statusCode = response.getStatusLine().getStatusCode();
720
                                if (statusCode == 409) {
721
                                        showError("Container must be empty in order to delete", bundle);
722
                                }
723
                                if (statusCode == 204) {
724
                                        setResult(Activity.RESULT_OK);
725

    
726
                                } else {
727
                                        CloudServersException cse = parseCloudServersException(response);
728
                                        if ("".equals(cse.getMessage())) {
729
                                                showError("There was a problem deleting your container.", bundle);
730
                                        } else {
731
                                                showError("There was a problem deleting your container: "
732
                                                                + cse.getMessage(), bundle);
733
                                        }
734
                                }
735
                        } else if (exception != null) {
736
                                showError("There was a problem deleting your server: "
737
                                                + exception.getMessage(), bundle);
738
                        }
739
                }
740
        }
741

    
742
        /*
743
         * listens for the application to change isProcessing
744
         * listens so activity knows when it should display
745
         * the new curDirFiles
746
         */
747
        private class AddObjectListenerTask extends
748
        AsyncTask<Void, Void, Void> {
749

    
750
                @Override
751
                protected Void doInBackground(Void... arg1) {
752

    
753
                        while(app.isAddingObject()){
754
                                // wait for process to finish
755
                                // or have it be canceled
756
                                if(task.isCancelled()){
757
                                        return null;
758
                                }
759
                        }
760
                        return null;
761
                }
762

    
763
                /*
764
                 * when no longer processing, time to load
765
                 * the new files
766
                 */
767
                @Override
768
                protected void onPostExecute(Void arg1) {
769
                        hideDialog();
770
                        loadFiles();
771
                }
772
        }
773

    
774

    
775
        private class DeleteObjectListenerTask extends
776
        AsyncTask<Void, Void, Void> {
777

    
778
                @Override
779
                protected Void doInBackground(Void... arg1) {
780

    
781
                        while(app.isDeletingObject()){
782
                                // wait for process to finish
783
                                // or have it be canceled
784
                                if(deleteObjTask.isCancelled()){
785
                                        return null;
786
                                }
787
                        }
788
                        return null;
789
                }
790

    
791
                /*
792
                 * when no longer processing, time to load
793
                 * the new files
794
                 */
795
                @Override
796
                protected void onPostExecute(Void arg1) {
797
                        hideDialog();
798
                        removeFromList(currentPath);
799
                        goUpDirectory();
800
                }
801
        }
802

    
803
        private class DeleteContainerListenerTask extends
804
        AsyncTask<Void, Void, Void> {
805

    
806
                @Override
807
                protected Void doInBackground(Void... arg1) {
808

    
809
                        while(app.isDeletingContainer()){
810
                                // wait for process to finish
811
                                // or have it be canceled
812
                                if(deleteContainerTask.isCancelled()){
813
                                        return null;
814
                                }
815
                        }
816
                        return null;
817
                }
818

    
819
                /*
820
                 * when no longer processing, time to load
821
                 * the new files
822
                 */
823
                @Override
824
                protected void onPostExecute(Void arg1) {
825

    
826
                        hideDialog();
827
                        setResult(RESULT_OK);
828
                        finish();
829
                }
830
        }
831
}