Statistics
| Branch: | Revision:

root / src / com / rackspacecloud / android / ContainerObjectsActivity.java @ 71e52c4a

History | View | Annotate | Download (21.5 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.util.Log;
16
import android.view.LayoutInflater;
17
import android.view.Menu;
18
import android.view.MenuInflater;
19
import android.view.MenuItem; 
20
import android.view.View;
21
import android.view.ViewGroup;
22
import android.widget.ArrayAdapter;
23
import android.widget.EditText;
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(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
                                Log.d("info", "up here");
107
                                loadFiles();
108
                        }
109
                        else if(state.containsKey("container")){
110
                                Log.d("info", "down here");
111
                                files = (ContainerObjects[]) state.getSerializable("container");
112
                                if (app.getCurFiles() == null || app.getCurFiles().size() == 0) {
113
                                        displayNoFilesCell();
114
                                } else {
115
                                        getListView().setDividerHeight(1); // restore divider lines
116
                                        setListAdapter(new FileAdapter());
117

    
118
                                }
119

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

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

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

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

    
148

    
149
        }
150

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

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

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

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

    
171
        }
172

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

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

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

    
203

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

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

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

    
235

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

    
247

    
248

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

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

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

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

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

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

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

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

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

    
392
        @Override
393
        protected Dialog onCreateDialog(int id) {
394
                switch (id) {
395
                case deleteContainer:
396
                        if(app.getCurFiles().size() == 0){
397
                                return new AlertDialog.Builder(ContainerObjectsActivity.this)
398
                                .setIcon(R.drawable.alert_dialog_icon)
399
                                .setTitle("Delete Container")
400
                                .setMessage(
401
                                "Are you sure you want to delete this Container?")
402
                                .setPositiveButton("Delete Container",
403
                                                new DialogInterface.OnClickListener() {
404
                                        public void onClick(DialogInterface dialog,
405
                                                        int whichButton) {
406
                                                // User clicked OK so do some stuff
407
                                                trackEvent(CATEGORY_CONTAINER, EVENT_DELETE, "", -1);
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(app.getCurFiles().size() == 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 && requestCode == 56) {
499
                        // a sub-activity kicked back, so we want to refresh the server list
500
                        loadFiles();
501
                }
502

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

    
508
        }
509

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

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

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

    
526
                        if (file.getBytes() >= bConver) {
527
                                megaBytes = Math.abs(file.getBytes() / bConver + 0.2);
528
                                TextView sublabel = (TextView) row.findViewById(R.id.sublabel);
529
                                sublabel.setText(megaBytes + " MB");
530
                        } else if (file.getBytes() >= kbConver) {
531
                                kiloBytes = Math.abs(file.getBytes() / kbConver + 0.2);
532
                                TextView sublabel = (TextView) row.findViewById(R.id.sublabel);
533
                                sublabel.setText(kiloBytes + " KB");
534
                        } else {
535
                                TextView sublabel = (TextView) row.findViewById(R.id.sublabel);
536
                                sublabel.setText(file.getBytes() + " B");
537
                        }
538

    
539
                        return (row);
540
                }
541
        }
542

    
543
        private class LoadFilesTask extends
544
        AsyncTask<String, Void, ArrayList<ContainerObjects>> {
545

    
546
                private CloudServersException exception;
547

    
548
                protected void onPreExecute(){
549
                        showDialog();
550
                        loadingFiles = true;
551
                }
552

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

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

    
578
        }
579

    
580
        private class AddFolderTask extends
581
        AsyncTask<String, Void, HttpBundle> {
582

    
583
                private CloudServersException exception;
584

    
585
                @Override
586
                protected void onPreExecute(){
587
                        showDialog();
588
                        app.setAddingObject(true);
589
                        task = new AddObjectListenerTask();
590
                        task.execute();
591
                }
592

    
593
                @Override
594
                protected HttpBundle doInBackground(String... data) {
595
                        HttpBundle bundle = null;
596
                        try {
597

    
598
                                bundle = (new ContainerObjectManager(getContext())).addObject(container.getName(), currentPath, data[0], data[1]);
599
                        } catch (CloudServersException e) {
600
                                exception = e;
601
                        }
602
                        return bundle;
603
                }
604

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

    
631
        private class DeleteObjectTask extends
632
        AsyncTask<Void, Void, HttpBundle> {
633

    
634
                private CloudServersException exception;
635

    
636
                @Override
637
                protected void onPreExecute(){
638
                        showDialog();
639
                        app.setDeleteingObject(true);
640
                        deleteObjTask = new DeleteObjectListenerTask();
641
                        deleteObjTask.execute();
642
                }
643

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

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

    
685
        private class DeleteContainerTask extends
686
        AsyncTask<String, Void, HttpBundle> {
687

    
688
                private CloudServersException exception;
689

    
690
                @Override
691
                protected void onPreExecute(){ 
692
                        showDialog();
693
                        app.setDeletingContainer(true);
694
                        deleteContainerTask = new DeleteContainerListenerTask();
695
                        deleteContainerTask.execute();
696
                }
697

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

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

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

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

    
746
                @Override
747
                protected Void doInBackground(Void... arg1) {
748

    
749
                        while(app.isAddingObject()){
750
                                // wait for process to finish
751
                                // or have it be canceled
752
                                if(task.isCancelled()){
753
                                        return null;
754
                                }
755
                        }
756
                        return null;
757
                }
758

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

    
770

    
771
        private class DeleteObjectListenerTask extends
772
        AsyncTask<Void, Void, Void> {
773

    
774
                @Override
775
                protected Void doInBackground(Void... arg1) {
776

    
777
                        while(app.isDeletingObject()){
778
                                // wait for process to finish
779
                                // or have it be canceled
780
                                if(deleteObjTask.isCancelled()){
781
                                        return null;
782
                                }
783
                        }
784
                        return null;
785
                }
786

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

    
799
        private class DeleteContainerListenerTask extends
800
        AsyncTask<Void, Void, Void> {
801

    
802
                @Override
803
                protected Void doInBackground(Void... arg1) {
804

    
805
                        while(app.isDeletingContainer()){
806
                                // wait for process to finish
807
                                // or have it be canceled
808
                                if(deleteContainerTask.isCancelled()){
809
                                        return null;
810
                                }
811
                        }
812
                        return null;
813
                }
814

    
815
                /*
816
                 * when no longer processing, time to load
817
                 * the new files
818
                 */
819
                @Override
820
                protected void onPostExecute(Void arg1) {
821

    
822
                        hideDialog();
823
                        setResult(RESULT_OK);
824
                        finish();
825
                }
826
        }
827
}