Statistics
| Branch: | Revision:

root / src / com / rackspace / cloud / android / ContainerObjectsActivity.java @ 66ea047a

History | View | Annotate | Download (21.9 kB)

1
package com.rackspace.cloud.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.android.R;
28
import com.rackspace.cloud.files.api.client.Container;
29
import com.rackspace.cloud.files.api.client.ContainerManager;
30
import com.rackspace.cloud.files.api.client.ContainerObjectManager;
31
import com.rackspace.cloud.files.api.client.ContainerObjects;
32
import com.rackspace.cloud.servers.api.client.CloudServersException;
33
import com.rackspace.cloud.servers.api.client.http.HttpBundle;
34

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

    
41
public class ContainerObjectsActivity extends CloudListActivity {
42

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

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

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

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

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

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

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

    
87

    
88

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

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

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

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

    
117
                                }
118

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

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

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

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

    
147

    
148
        }
149

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

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

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

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

    
170
        }
171

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

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

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

    
202

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

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

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

    
234

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

    
246

    
247

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

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

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

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

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

    
327
        protected void onListItemClick(ListView l, View v, int position, long id) {
328
                if (app.getCurFiles() != null && app.getCurFiles().size() > 0) {
329
                        Intent viewIntent;
330
                        if(app.getCurFiles().get(position).getContentType().startsWith("application/directory")){                        
331
                                currentPath = app.getCurFiles().get(position).getCName() + "/";
332
                                loadCurrentDirectoryFiles();
333
                                displayCurrentFiles();
334
                        }
335

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

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

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

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

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

    
500
                if (resultCode == RESULT_OK && requestCode == 56) {
501
                        // a sub-activity kicked back, so we want to refresh the server list
502
                        loadFiles();
503
                }
504

    
505
                // deleted file so need to update the list
506
                if (requestCode == 55 && resultCode == 99) {
507
                        loadFiles();
508
                }
509

    
510
        }
511

    
512
        class FileAdapter extends ArrayAdapter<ContainerObjects> {
513
                FileAdapter() {
514
                        super(ContainerObjectsActivity.this,
515
                                        R.layout.listcontainerobjectcell, app.getCurFiles());        
516
                }
517

    
518
                public View getView(int position, View convertView, ViewGroup parent) {
519
                        ContainerObjects file = app.getCurFiles().get(position);
520
                        LayoutInflater inflater = getLayoutInflater();
521
                        View row = inflater.inflate(R.layout.listcontainerobjectcell,
522
                                        parent, false);
523

    
524
                        TextView label = (TextView) row.findViewById(R.id.label);
525
                        label.setText(getShortName(file.getCName()));
526

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

    
547
                        return (row);
548
                }
549
        }
550

    
551
        private class LoadFilesTask extends
552
        AsyncTask<String, Void, ArrayList<ContainerObjects>> {
553

    
554
                private CloudServersException exception;
555

    
556
                protected void onPreExecute(){
557
                        showDialog();
558
                        loadingFiles = true;
559
                }
560

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

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

    
586
        }
587

    
588
        private class AddFolderTask extends
589
        AsyncTask<String, Void, HttpBundle> {
590

    
591
                private CloudServersException exception;
592

    
593
                @Override
594
                protected void onPreExecute(){
595
                        showDialog();
596
                        app.setAddingObject(true);
597
                        task = new AddObjectListenerTask();
598
                        task.execute();
599
                }
600

    
601
                @Override
602
                protected HttpBundle doInBackground(String... data) {
603
                        HttpBundle bundle = null;
604
                        try {
605

    
606
                                bundle = (new ContainerObjectManager(getContext())).addObject(container.getName(), currentPath, data[0], data[1]);
607
                        } catch (CloudServersException e) {
608
                                exception = e;
609
                        }
610
                        return bundle;
611
                }
612

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

    
639
        private class DeleteObjectTask extends
640
        AsyncTask<Void, Void, HttpBundle> {
641

    
642
                private CloudServersException exception;
643

    
644
                @Override
645
                protected void onPreExecute(){
646
                        showDialog();
647
                        app.setDeleteingObject(true);
648
                        deleteObjTask = new DeleteObjectListenerTask();
649
                        deleteObjTask.execute();
650
                }
651

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

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

    
693
        private class DeleteContainerTask extends
694
        AsyncTask<String, Void, HttpBundle> {
695

    
696
                private CloudServersException exception;
697

    
698
                @Override
699
                protected void onPreExecute(){ 
700
                        showDialog();
701
                        app.setDeletingContainer(true);
702
                        deleteContainerTask = new DeleteContainerListenerTask();
703
                        deleteContainerTask.execute();
704
                }
705

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

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

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

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

    
754
                @Override
755
                protected Void doInBackground(Void... arg1) {
756

    
757
                        while(app.isAddingObject()){
758
                                // wait for process to finish
759
                                // or have it be canceled
760
                                if(task.isCancelled()){
761
                                        return null;
762
                                }
763
                        }
764
                        return null;
765
                }
766

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

    
778

    
779
        private class DeleteObjectListenerTask extends
780
        AsyncTask<Void, Void, Void> {
781

    
782
                @Override
783
                protected Void doInBackground(Void... arg1) {
784

    
785
                        while(app.isDeletingObject()){
786
                                // wait for process to finish
787
                                // or have it be canceled
788
                                if(deleteObjTask.isCancelled()){
789
                                        return null;
790
                                }
791
                        }
792
                        return null;
793
                }
794

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

    
807
        private class DeleteContainerListenerTask extends
808
        AsyncTask<Void, Void, Void> {
809

    
810
                @Override
811
                protected Void doInBackground(Void... arg1) {
812

    
813
                        while(app.isDeletingContainer()){
814
                                // wait for process to finish
815
                                // or have it be canceled
816
                                if(deleteContainerTask.isCancelled()){
817
                                        return null;
818
                                }
819
                        }
820
                        return null;
821
                }
822

    
823
                /*
824
                 * when no longer processing, time to load
825
                 * the new files
826
                 */
827
                @Override
828
                protected void onPostExecute(Void arg1) {
829

    
830
                        hideDialog();
831
                        setResult(RESULT_OK);
832
                        finish();
833
                }
834
        }
835
}