Statistics
| Branch: | Revision:

root / src / com / rackspacecloud / android / ContainerObjectsActivity.java @ f506786e

History | View | Annotate | Download (21.7 kB)

1 3d6041e8 Phillip Toohill
package com.rackspacecloud.android;
2 3d6041e8 Phillip Toohill
3 3d6041e8 Phillip Toohill
import java.util.ArrayList;
4 d3ea294b Adam Menz
import java.util.Arrays;
5 3d6041e8 Phillip Toohill
6 3d6041e8 Phillip Toohill
import org.apache.http.HttpResponse;
7 3d6041e8 Phillip Toohill
8 3d6041e8 Phillip Toohill
import android.app.Activity;
9 3d6041e8 Phillip Toohill
import android.app.AlertDialog;
10 3d6041e8 Phillip Toohill
import android.app.Dialog;
11 3d6041e8 Phillip Toohill
import android.content.DialogInterface;
12 3d6041e8 Phillip Toohill
import android.content.Intent;
13 3d6041e8 Phillip Toohill
import android.os.AsyncTask;
14 3d6041e8 Phillip Toohill
import android.os.Bundle;
15 3d6041e8 Phillip Toohill
import android.view.LayoutInflater;
16 3d6041e8 Phillip Toohill
import android.view.Menu;
17 3d6041e8 Phillip Toohill
import android.view.MenuInflater;
18 b2a2d2f1 Adam Menz
import android.view.MenuItem; 
19 3d6041e8 Phillip Toohill
import android.view.View;
20 3d6041e8 Phillip Toohill
import android.view.ViewGroup;
21 3d6041e8 Phillip Toohill
import android.widget.ArrayAdapter;
22 d3ea294b Adam Menz
import android.widget.EditText;
23 f506786e Adam Menz
import android.widget.ImageView;
24 3d6041e8 Phillip Toohill
import android.widget.ListView;
25 3d6041e8 Phillip Toohill
import android.widget.TextView;
26 3d6041e8 Phillip Toohill
27 3d6041e8 Phillip Toohill
import com.rackspace.cloud.files.api.client.Container;
28 3d6041e8 Phillip Toohill
import com.rackspace.cloud.files.api.client.ContainerManager;
29 3d6041e8 Phillip Toohill
import com.rackspace.cloud.files.api.client.ContainerObjectManager;
30 3d6041e8 Phillip Toohill
import com.rackspace.cloud.files.api.client.ContainerObjects;
31 3d6041e8 Phillip Toohill
import com.rackspace.cloud.servers.api.client.CloudServersException;
32 32731215 Adam Menz
import com.rackspace.cloud.servers.api.client.http.HttpBundle;
33 3d6041e8 Phillip Toohill
34 240418be Phillip Toohill
/**
35 3d6041e8 Phillip Toohill
 * 
36 3d6041e8 Phillip Toohill
 * @author Phillip Toohill
37 240418be Phillip Toohill
 * 
38 3d6041e8 Phillip Toohill
 */
39 6b8dad86 Adam Menz
40 b2a2d2f1 Adam Menz
public class ContainerObjectsActivity extends CloudListActivity {
41 3d6041e8 Phillip Toohill
42 3d6041e8 Phillip Toohill
        private static final int deleteContainer = 0;
43 37a14877 Adam Menz
        private static final int deleteFolder = 1;
44 71e52c4a Adam Menz
45 3d6041e8 Phillip Toohill
        private ContainerObjects[] files;
46 3d6041e8 Phillip Toohill
        private static Container container;
47 3d6041e8 Phillip Toohill
        public String LOG = "viewFilesActivity";
48 8b432514 Phillip Toohill
        private String cdnEnabledIs;
49 6864568a Phillip Toohill
        public Object megaBytes;
50 6864568a Phillip Toohill
        public Object kiloBytes;
51 6864568a Phillip Toohill
        public int bConver = 1048576;
52 6864568a Phillip Toohill
        public int kbConver = 1024;
53 51938302 Adam Menz
        private boolean loadingFiles;
54 b2a2d2f1 Adam Menz
        private String currentPath;
55 a7d1fdc2 Adam Menz
        private AndroidCloudApplication app;
56 a7d1fdc2 Adam Menz
        private AddObjectListenerTask task;
57 a7d1fdc2 Adam Menz
        private DeleteObjectListenerTask deleteObjTask;
58 a7d1fdc2 Adam Menz
        private DeleteContainerListenerTask deleteContainerTask;
59 71e52c4a Adam Menz
60 3d6041e8 Phillip Toohill
        @Override
61 240418be Phillip Toohill
        public void onCreate(Bundle savedInstanceState) {
62 240418be Phillip Toohill
                super.onCreate(savedInstanceState);
63 0edf6b39 Adam Menz
                trackPageView(PAGE_FOLDER);
64 240418be Phillip Toohill
                container = (Container) this.getIntent().getExtras().get("container");
65 240418be Phillip Toohill
                if (container.isCdnEnabled() == true) {
66 240418be Phillip Toohill
                        cdnEnabledIs = "true";
67 240418be Phillip Toohill
                } else {
68 240418be Phillip Toohill
                        cdnEnabledIs = "false";
69 240418be Phillip Toohill
                }
70 240418be Phillip Toohill
                restoreState(savedInstanceState);
71 240418be Phillip Toohill
        }
72 a7d1fdc2 Adam Menz
73 3d6041e8 Phillip Toohill
        @Override
74 3d6041e8 Phillip Toohill
        protected void onSaveInstanceState(Bundle outState) {
75 3d6041e8 Phillip Toohill
                super.onSaveInstanceState(outState);
76 71e52c4a Adam Menz
77 a7d1fdc2 Adam Menz
                //files stores all the files in the container
78 3d6041e8 Phillip Toohill
                outState.putSerializable("container", files);
79 71e52c4a Adam Menz
80 a7d1fdc2 Adam Menz
                //current path represents where you have "navigated" to
81 c16dc9e7 Adam Menz
                outState.putString("path", currentPath);
82 71e52c4a Adam Menz
83 51938302 Adam Menz
                outState.putBoolean("loadingFiles", loadingFiles);
84 3d6041e8 Phillip Toohill
        }
85 a7d1fdc2 Adam Menz
86 a7d1fdc2 Adam Menz
87 3d6041e8 Phillip Toohill
88 b2a2d2f1 Adam Menz
        protected void restoreState(Bundle state) {
89 b2a2d2f1 Adam Menz
                super.restoreState(state);
90 71e52c4a Adam Menz
91 a7d1fdc2 Adam Menz
                /*
92 a7d1fdc2 Adam Menz
                 * need reference to the app so you can access curDirFiles
93 a7d1fdc2 Adam Menz
                 * as well as processing status
94 a7d1fdc2 Adam Menz
                 */
95 a7d1fdc2 Adam Menz
                app = (AndroidCloudApplication)this.getApplication();
96 71e52c4a Adam Menz
97 d3ea294b Adam Menz
                if(state != null){
98 d3ea294b Adam Menz
                        if(state.containsKey("path")){
99 d3ea294b Adam Menz
                                currentPath = state.getString("path");
100 240418be Phillip Toohill
                        }
101 c16dc9e7 Adam Menz
                        else{
102 d3ea294b Adam Menz
                                currentPath = "";
103 d3ea294b Adam Menz
                        }
104 a7d1fdc2 Adam Menz
105 51938302 Adam Menz
                        if(state.containsKey("loadingFiles") && state.getBoolean("loadingFiles")){
106 51938302 Adam Menz
                                loadFiles();
107 51938302 Adam Menz
                        }
108 71e52c4a Adam Menz
                        else if(state.containsKey("container")){
109 71e52c4a Adam Menz
                                files = (ContainerObjects[]) state.getSerializable("container");
110 71e52c4a Adam Menz
                                if (app.getCurFiles() == null || app.getCurFiles().size() == 0) {
111 71e52c4a Adam Menz
                                        displayNoFilesCell();
112 71e52c4a Adam Menz
                                } else {
113 71e52c4a Adam Menz
                                        getListView().setDividerHeight(1); // restore divider lines
114 71e52c4a Adam Menz
                                        setListAdapter(new FileAdapter());
115 a7d1fdc2 Adam Menz
116 d3ea294b Adam Menz
                                }
117 71e52c4a Adam Menz
118 240418be Phillip Toohill
                        }
119 240418be Phillip Toohill
                }
120 d3ea294b Adam Menz
                else {
121 d3ea294b Adam Menz
                        currentPath = "";
122 d3ea294b Adam Menz
                        loadFiles();
123 d3ea294b Adam Menz
                }        
124 71e52c4a Adam Menz
125 a7d1fdc2 Adam Menz
                /*
126 a7d1fdc2 Adam Menz
                 * if the app is process when we enter the activity
127 a7d1fdc2 Adam Menz
                 * we must listen for the new curDirFiles list
128 a7d1fdc2 Adam Menz
                 */
129 a7d1fdc2 Adam Menz
                if(app.isAddingObject()){
130 a7d1fdc2 Adam Menz
                        task = new AddObjectListenerTask();
131 a7d1fdc2 Adam Menz
                        task.execute();
132 a7d1fdc2 Adam Menz
                }
133 71e52c4a Adam Menz
134 a7d1fdc2 Adam Menz
                if(app.isDeletingObject()){
135 a7d1fdc2 Adam Menz
                        displayNoFilesCell();
136 a7d1fdc2 Adam Menz
                        deleteObjTask = new DeleteObjectListenerTask();
137 a7d1fdc2 Adam Menz
                        deleteObjTask.execute();
138 a7d1fdc2 Adam Menz
                }
139 71e52c4a Adam Menz
140 877f6f58 Adam Menz
                if(app.isDeletingContainer()){
141 877f6f58 Adam Menz
                        displayNoFilesCell();
142 877f6f58 Adam Menz
                        deleteContainerTask = new DeleteContainerListenerTask();
143 877f6f58 Adam Menz
                        deleteContainerTask.execute();
144 877f6f58 Adam Menz
                }
145 a7d1fdc2 Adam Menz
146 a7d1fdc2 Adam Menz
147 240418be Phillip Toohill
        }
148 71e52c4a Adam Menz
149 a7d1fdc2 Adam Menz
        @Override
150 a7d1fdc2 Adam Menz
        protected void onStop(){
151 a7d1fdc2 Adam Menz
                super.onStop();
152 a7d1fdc2 Adam Menz
153 a7d1fdc2 Adam Menz
                /*
154 a7d1fdc2 Adam Menz
                 * Need to stop running listener task
155 a7d1fdc2 Adam Menz
                 * if we exit
156 a7d1fdc2 Adam Menz
                 */
157 a7d1fdc2 Adam Menz
                if(task != null){
158 a7d1fdc2 Adam Menz
                        task.cancel(true);
159 a7d1fdc2 Adam Menz
                }
160 71e52c4a Adam Menz
161 3e180b04 Adam Menz
                if(deleteObjTask != null){
162 3e180b04 Adam Menz
                        deleteObjTask.cancel(true);
163 3e180b04 Adam Menz
                }
164 71e52c4a Adam Menz
165 3e180b04 Adam Menz
                if(deleteContainerTask != null){
166 3e180b04 Adam Menz
                        deleteContainerTask.cancel(true);
167 3e180b04 Adam Menz
                }
168 3e180b04 Adam Menz
169 240418be Phillip Toohill
        }
170 240418be Phillip Toohill
171 37a14877 Adam Menz
        /*
172 37a14877 Adam Menz
         * overriding back button press, because we are not actually changing
173 d3ea294b Adam Menz
         * activities when we navigate the file structure
174 37a14877 Adam Menz
         */
175 37a14877 Adam Menz
        public void onBackPressed() {
176 37a14877 Adam Menz
                if(currentPath.equals("")){
177 37a14877 Adam Menz
                        finish();
178 37a14877 Adam Menz
                }
179 37a14877 Adam Menz
                else{
180 37a14877 Adam Menz
                        goUpDirectory();
181 240418be Phillip Toohill
                }
182 240418be Phillip Toohill
        }
183 a7d1fdc2 Adam Menz
184 37a14877 Adam Menz
        /*
185 37a14877 Adam Menz
         * go to the current directory's parent and display that data
186 37a14877 Adam Menz
         */
187 37a14877 Adam Menz
        private void goUpDirectory(){
188 37a14877 Adam Menz
                currentPath = currentPath.substring(0, currentPath.substring(0, currentPath.length()-2).lastIndexOf("/")+1);
189 a7d1fdc2 Adam Menz
                loadCurrentDirectoryFiles();
190 37a14877 Adam Menz
                displayCurrentFiles();
191 37a14877 Adam Menz
        }
192 240418be Phillip Toohill
193 cc71758a Adam Menz
        /*
194 51938302 Adam Menz
         * load all file that are in the container
195 51938302 Adam Menz
         */
196 240418be Phillip Toohill
        private void loadFiles() {
197 3ea9d68e Adam Menz
                //displayLoadingCell();
198 37a14877 Adam Menz
                new LoadFilesTask().execute();
199 37a14877 Adam Menz
        }
200 a7d1fdc2 Adam Menz
201 a7d1fdc2 Adam Menz
202 37a14877 Adam Menz
        /* load only the files that should display for the 
203 37a14877 Adam Menz
         * current directory in the curDirFiles[]
204 37a14877 Adam Menz
         */
205 37a14877 Adam Menz
        private void loadCurrentDirectoryFiles(){
206 37a14877 Adam Menz
                ArrayList<ContainerObjects> curFiles = new ArrayList<ContainerObjects>();
207 37a14877 Adam Menz
208 37a14877 Adam Menz
                if(files != null){
209 37a14877 Adam Menz
                        for(int i = 0 ; i < files.length; i ++){
210 37a14877 Adam Menz
                                if(fileBelongsInDir(files[i])){
211 37a14877 Adam Menz
                                        curFiles.add(files[i]);
212 37a14877 Adam Menz
                                }
213 37a14877 Adam Menz
                        }
214 a7d1fdc2 Adam Menz
                        app.setCurFiles(curFiles);
215 37a14877 Adam Menz
                }
216 37a14877 Adam Menz
        }
217 a7d1fdc2 Adam Menz
218 37a14877 Adam Menz
        /*
219 37a14877 Adam Menz
         * determines if a file should be displayed in current 
220 37a14877 Adam Menz
         * directory
221 37a14877 Adam Menz
         */
222 37a14877 Adam Menz
        private Boolean fileBelongsInDir(ContainerObjects obj){
223 37a14877 Adam Menz
                String objPath = obj.getCName();
224 37a14877 Adam Menz
                if(!objPath.startsWith(currentPath)){
225 37a14877 Adam Menz
                        return false;
226 37a14877 Adam Menz
                }
227 37a14877 Adam Menz
                else{
228 37a14877 Adam Menz
                        objPath = objPath.substring(currentPath.length());
229 37a14877 Adam Menz
                        return !objPath.contains("/");
230 37a14877 Adam Menz
                }
231 240418be Phillip Toohill
        }
232 240418be Phillip Toohill
233 a7d1fdc2 Adam Menz
234 37a14877 Adam Menz
        /*
235 37a14877 Adam Menz
         * loads all the files that are in the container
236 37a14877 Adam Menz
         * into one array
237 37a14877 Adam Menz
         */
238 3d6041e8 Phillip Toohill
        private void setFileList(ArrayList<ContainerObjects> files) {
239 240418be Phillip Toohill
                if (files == null) {
240 240418be Phillip Toohill
                        files = new ArrayList<ContainerObjects>();
241 240418be Phillip Toohill
                }
242 240418be Phillip Toohill
                String[] fileNames = new String[files.size()];
243 240418be Phillip Toohill
                this.files = new ContainerObjects[files.size()];
244 240418be Phillip Toohill
245 a7d1fdc2 Adam Menz
246 a7d1fdc2 Adam Menz
247 240418be Phillip Toohill
                if (files != null) {
248 3d6041e8 Phillip Toohill
                        for (int i = 0; i < files.size(); i++) {
249 240418be Phillip Toohill
                                ContainerObjects file = files.get(i);
250 3d6041e8 Phillip Toohill
                                this.files[i] = file;
251 3d6041e8 Phillip Toohill
                                fileNames[i] = file.getName();
252 3d6041e8 Phillip Toohill
                        }
253 3d6041e8 Phillip Toohill
                }
254 37a14877 Adam Menz
        }
255 a7d1fdc2 Adam Menz
256 37a14877 Adam Menz
        private void displayCurrentFiles(){
257 a7d1fdc2 Adam Menz
                if (app.getCurFiles().size() == 0) {
258 a7d1fdc2 Adam Menz
                        displayNoFilesCell();
259 3d6041e8 Phillip Toohill
                } else {
260 3ea9d68e Adam Menz
                        ArrayList<ContainerObjects> tempList = new ArrayList<ContainerObjects>();
261 a7d1fdc2 Adam Menz
                        for(int i = 0; i < app.getCurFiles().size(); i++){
262 a7d1fdc2 Adam Menz
                                tempList.add(app.getCurFiles().get(i));
263 3ea9d68e Adam Menz
                        }
264 a7d1fdc2 Adam Menz
                        getListView().setDividerHeight(1); // restore divider lines
265 a7d1fdc2 Adam Menz
                        setListAdapter(new FileAdapter());
266 3d6041e8 Phillip Toohill
                }
267 240418be Phillip Toohill
        }
268 240418be Phillip Toohill
269 37a14877 Adam Menz
        /*
270 37a14877 Adam Menz
         * display a different empty page depending
271 37a14877 Adam Menz
         * of if you are at top of container or
272 37a14877 Adam Menz
         * in a folder
273 37a14877 Adam Menz
         */
274 a7d1fdc2 Adam Menz
        private void displayNoFilesCell() {
275 240418be Phillip Toohill
                String a[] = new String[1];
276 37a14877 Adam Menz
                if(currentPath.equals("")){
277 37a14877 Adam Menz
                        a[0] = "Empty Container";
278 37a14877 Adam Menz
                        setListAdapter(new ArrayAdapter<String>(this, R.layout.noobjectscell,
279 71e52c4a Adam Menz
                                        R.id.no_files_label, a));
280 37a14877 Adam Menz
                }
281 37a14877 Adam Menz
                else{
282 37a14877 Adam Menz
                        a[0] = "No Files";
283 37a14877 Adam Menz
                        setListAdapter(new ArrayAdapter<String>(this, R.layout.nofilescell,
284 71e52c4a Adam Menz
                                        R.id.no_files_label, a));
285 37a14877 Adam Menz
                }
286 240418be Phillip Toohill
                getListView().setTextFilterEnabled(true);
287 240418be Phillip Toohill
                getListView().setDividerHeight(0); // hide the dividers so it won't look
288 71e52c4a Adam Menz
                // like a list row
289 240418be Phillip Toohill
                getListView().setItemsCanFocus(false);
290 240418be Phillip Toohill
        }
291 a7d1fdc2 Adam Menz
292 c16dc9e7 Adam Menz
        /* just get the last part of the filename
293 c16dc9e7 Adam Menz
         * so the entire file path does not show
294 a7d1fdc2 Adam Menz
         */
295 c16dc9e7 Adam Menz
        private String getShortName(String longName){
296 c16dc9e7 Adam Menz
                String s = longName;
297 c16dc9e7 Adam Menz
                if(!s.contains("/")){
298 c16dc9e7 Adam Menz
                        return s;
299 3d6041e8 Phillip Toohill
                }
300 c16dc9e7 Adam Menz
                else {
301 d3ea294b Adam Menz
                        return s.substring(s.lastIndexOf('/')+1);
302 3d6041e8 Phillip Toohill
                }
303 240418be Phillip Toohill
        }
304 a7d1fdc2 Adam Menz
305 d3ea294b Adam Menz
        /*
306 d3ea294b Adam Menz
         * removed a specified object from the array of 
307 d3ea294b Adam Menz
         * all the files in the container
308 d3ea294b Adam Menz
         */
309 d3ea294b Adam Menz
        private void removeFromList(String path){
310 d3ea294b Adam Menz
                ArrayList<ContainerObjects> temp = new ArrayList<ContainerObjects>(Arrays.asList(files));
311 d3ea294b Adam Menz
                for(int i = 0; i < files.length; i++){
312 d3ea294b Adam Menz
                        if(files[i].getCName().equals(path.substring(0, path.length()-1))){
313 d3ea294b Adam Menz
                                temp.remove(i);
314 d3ea294b Adam Menz
                        }
315 3d6041e8 Phillip Toohill
                }
316 d3ea294b Adam Menz
                files = new ContainerObjects[temp.size()];
317 d3ea294b Adam Menz
                for(int i = 0; i < temp.size(); i++){
318 d3ea294b Adam Menz
                        files[i] = temp.get(i);
319 d3ea294b Adam Menz
                }
320 d3ea294b Adam Menz
        }
321 240418be Phillip Toohill
322 d3ea294b Adam Menz
        protected void onListItemClick(ListView l, View v, int position, long id) {
323 a7d1fdc2 Adam Menz
                if (app.getCurFiles() != null && app.getCurFiles().size() > 0) {
324 d3ea294b Adam Menz
                        Intent viewIntent;
325 a7d1fdc2 Adam Menz
                        if(app.getCurFiles().get(position).getContentType().equals("application/directory")){                        
326 a7d1fdc2 Adam Menz
                                currentPath = app.getCurFiles().get(position).getCName() + "/";
327 a7d1fdc2 Adam Menz
                                loadCurrentDirectoryFiles();
328 d3ea294b Adam Menz
                                displayCurrentFiles();
329 d3ea294b Adam Menz
                        }
330 a7d1fdc2 Adam Menz
331 d3ea294b Adam Menz
                        else{
332 d3ea294b Adam Menz
                                viewIntent = new Intent(this, ContainerObjectDetails.class);
333 a7d1fdc2 Adam Menz
                                viewIntent.putExtra("container", app.getCurFiles().get(position));
334 d3ea294b Adam Menz
                                viewIntent.putExtra("cdnUrl", container.getCdnUrl());
335 d3ea294b Adam Menz
                                viewIntent.putExtra("containerNames", container.getName());
336 d3ea294b Adam Menz
                                viewIntent.putExtra("isCdnEnabled", cdnEnabledIs);
337 d3ea294b Adam Menz
                                startActivityForResult(viewIntent, 55); // arbitrary number; never
338 d3ea294b Adam Menz
                                // used again
339 6864568a Phillip Toohill
                        }
340 3d6041e8 Phillip Toohill
                }
341 240418be Phillip Toohill
        }
342 240418be Phillip Toohill
343 37a14877 Adam Menz
        /* 
344 37a14877 Adam Menz
         * Create the Menu options
345 37a14877 Adam Menz
         */
346 240418be Phillip Toohill
        @Override
347 240418be Phillip Toohill
        public boolean onCreateOptionsMenu(Menu menu) {
348 3d6041e8 Phillip Toohill
                super.onCreateOptionsMenu(menu);
349 3d6041e8 Phillip Toohill
                MenuInflater inflater = getMenuInflater();
350 3d6041e8 Phillip Toohill
                inflater.inflate(R.menu.view_container_object_list_menu, menu);
351 3d6041e8 Phillip Toohill
                return true;
352 240418be Phillip Toohill
        }
353 240418be Phillip Toohill
354 240418be Phillip Toohill
        @Override
355 37a14877 Adam Menz
        /*
356 37a14877 Adam Menz
         * option performed for delete depends on if you
357 37a14877 Adam Menz
         * are at the top of a container or in a folder
358 37a14877 Adam Menz
         */
359 240418be Phillip Toohill
        public boolean onOptionsItemSelected(MenuItem item) {
360 3d6041e8 Phillip Toohill
                switch (item.getItemId()) {
361 3d6041e8 Phillip Toohill
                case R.id.delete_container:
362 37a14877 Adam Menz
                        if(currentPath.equals("")){
363 37a14877 Adam Menz
                                showDialog(deleteContainer);
364 37a14877 Adam Menz
                        }
365 37a14877 Adam Menz
                        else{
366 37a14877 Adam Menz
                                showDialog(deleteFolder);
367 37a14877 Adam Menz
                        }
368 3d6041e8 Phillip Toohill
                        return true;
369 3d6041e8 Phillip Toohill
                case R.id.enable_cdn:
370 3d6041e8 Phillip Toohill
                        Intent viewIntent1 = new Intent(this, EnableCDNActivity.class);
371 240418be Phillip Toohill
                        viewIntent1.putExtra("Cname", container.getName());
372 240418be Phillip Toohill
                        startActivityForResult(viewIntent1, 56);
373 3d6041e8 Phillip Toohill
                        return true;
374 3d6041e8 Phillip Toohill
                case R.id.refresh:
375 3d6041e8 Phillip Toohill
                        loadFiles();
376 240418be Phillip Toohill
                        return true;
377 d3ea294b Adam Menz
                case R.id.add_folder:
378 d3ea294b Adam Menz
                        showDialog(R.id.add_folder);
379 44ac7bea Adam Menz
                        return true;
380 d3ea294b Adam Menz
                case R.id.add_file:
381 d3ea294b Adam Menz
                        Intent viewIntent2 = new Intent(this, AddFileActivity.class);
382 d3ea294b Adam Menz
                        viewIntent2.putExtra("Cname", container.getName());
383 d3ea294b Adam Menz
                        viewIntent2.putExtra("curPath", currentPath);
384 d3ea294b Adam Menz
                        startActivityForResult(viewIntent2, 56);
385 d3ea294b Adam Menz
                        return true;        
386 3d6041e8 Phillip Toohill
                }
387 3d6041e8 Phillip Toohill
                return false;
388 240418be Phillip Toohill
        }
389 240418be Phillip Toohill
390 3d6041e8 Phillip Toohill
        @Override
391 240418be Phillip Toohill
        protected Dialog onCreateDialog(int id) {
392 240418be Phillip Toohill
                switch (id) {
393 240418be Phillip Toohill
                case deleteContainer:
394 a7d1fdc2 Adam Menz
                        if(app.getCurFiles().size() == 0){
395 37a14877 Adam Menz
                                return new AlertDialog.Builder(ContainerObjectsActivity.this)
396 37a14877 Adam Menz
                                .setIcon(R.drawable.alert_dialog_icon)
397 37a14877 Adam Menz
                                .setTitle("Delete Container")
398 37a14877 Adam Menz
                                .setMessage(
399 37a14877 Adam Menz
                                "Are you sure you want to delete this Container?")
400 37a14877 Adam Menz
                                .setPositiveButton("Delete Container",
401 37a14877 Adam Menz
                                                new DialogInterface.OnClickListener() {
402 37a14877 Adam Menz
                                        public void onClick(DialogInterface dialog,
403 37a14877 Adam Menz
                                                        int whichButton) {
404 37a14877 Adam Menz
                                                // User clicked OK so do some stuff
405 0edf6b39 Adam Menz
                                                trackEvent(CATEGORY_CONTAINER, EVENT_DELETE, "", -1);
406 37a14877 Adam Menz
                                                new DeleteContainerTask()
407 37a14877 Adam Menz
                                                .execute(currentPath);
408 37a14877 Adam Menz
                                        }
409 37a14877 Adam Menz
                                })
410 37a14877 Adam Menz
                                .setNegativeButton("Cancel",
411 37a14877 Adam Menz
                                                new DialogInterface.OnClickListener() {
412 37a14877 Adam Menz
                                        public void onClick(DialogInterface dialog,
413 37a14877 Adam Menz
                                                        int whichButton) {
414 37a14877 Adam Menz
                                                // User clicked Cancel so do some stuff
415 37a14877 Adam Menz
                                        }
416 37a14877 Adam Menz
                                }).create();
417 37a14877 Adam Menz
                        }
418 37a14877 Adam Menz
                        else{
419 37a14877 Adam Menz
                                return new AlertDialog.Builder(ContainerObjectsActivity.this)
420 37a14877 Adam Menz
                                .setIcon(R.drawable.alert_dialog_icon)
421 37a14877 Adam Menz
                                .setTitle("Delete Container")
422 37a14877 Adam Menz
                                .setMessage("Container must be empty to delete")
423 37a14877 Adam Menz
                                .setNegativeButton("OK",
424 37a14877 Adam Menz
                                                new DialogInterface.OnClickListener() {
425 37a14877 Adam Menz
                                        public void onClick(DialogInterface dialog,
426 37a14877 Adam Menz
                                                        int whichButton) {
427 37a14877 Adam Menz
                                                // User clicked Cancel so do some stuff
428 37a14877 Adam Menz
                                        }
429 37a14877 Adam Menz
                                }).create();
430 37a14877 Adam Menz
                        }
431 37a14877 Adam Menz
                case deleteFolder:
432 a7d1fdc2 Adam Menz
                        if(app.getCurFiles().size() == 0){
433 37a14877 Adam Menz
                                return new AlertDialog.Builder(ContainerObjectsActivity.this)
434 37a14877 Adam Menz
                                .setIcon(R.drawable.alert_dialog_icon)
435 37a14877 Adam Menz
                                .setTitle("Delete Folder")
436 37a14877 Adam Menz
                                .setMessage(
437 37a14877 Adam Menz
                                "Are you sure you want to delete this Folder?")
438 37a14877 Adam Menz
                                .setPositiveButton("Delete Folder",
439 37a14877 Adam Menz
                                                new DialogInterface.OnClickListener() {
440 37a14877 Adam Menz
                                        public void onClick(DialogInterface dialog,
441 37a14877 Adam Menz
                                                        int whichButton) {
442 37a14877 Adam Menz
                                                // User clicked OK so do some stuff
443 51938302 Adam Menz
                                                new DeleteObjectTask().execute();
444 37a14877 Adam Menz
                                        }
445 37a14877 Adam Menz
                                })
446 37a14877 Adam Menz
                                .setNegativeButton("Cancel",
447 37a14877 Adam Menz
                                                new DialogInterface.OnClickListener() {
448 37a14877 Adam Menz
                                        public void onClick(DialogInterface dialog,
449 37a14877 Adam Menz
                                                        int whichButton) {
450 37a14877 Adam Menz
                                                // User clicked Cancel so do some stuff
451 37a14877 Adam Menz
                                        }
452 37a14877 Adam Menz
                                }).create();
453 37a14877 Adam Menz
                        }
454 37a14877 Adam Menz
                        else{
455 37a14877 Adam Menz
                                return new AlertDialog.Builder(ContainerObjectsActivity.this)
456 37a14877 Adam Menz
                                .setIcon(R.drawable.alert_dialog_icon)
457 37a14877 Adam Menz
                                .setTitle("Delete Folder")
458 37a14877 Adam Menz
                                .setMessage(
459 37a14877 Adam Menz
                                "Folder must be empty to delete")
460 37a14877 Adam Menz
                                .setNegativeButton("OK",
461 37a14877 Adam Menz
                                                new DialogInterface.OnClickListener() {
462 37a14877 Adam Menz
                                        public void onClick(DialogInterface dialog,
463 37a14877 Adam Menz
                                                        int whichButton) {
464 37a14877 Adam Menz
                                                // User clicked Cancel so do some stuff
465 37a14877 Adam Menz
                                        }
466 37a14877 Adam Menz
                                }).create();
467 37a14877 Adam Menz
                        }
468 d3ea294b Adam Menz
                case R.id.add_folder:
469 d3ea294b Adam Menz
                        final EditText input = new EditText(this);
470 a7d1fdc2 Adam Menz
                        return new AlertDialog.Builder(ContainerObjectsActivity.this)
471 a7d1fdc2 Adam Menz
                        .setIcon(R.drawable.alert_dialog_icon)
472 a7d1fdc2 Adam Menz
                        .setView(input)
473 a7d1fdc2 Adam Menz
                        .setTitle("Add Folder")
474 a7d1fdc2 Adam Menz
                        .setMessage("Enter new name for folder: ")                         
475 a7d1fdc2 Adam Menz
                        .setPositiveButton("Add", new DialogInterface.OnClickListener() {
476 a7d1fdc2 Adam Menz
                                public void onClick(DialogInterface dialog, int whichButton) {
477 a7d1fdc2 Adam Menz
                                        //User clicked OK so do some stuff
478 a7d1fdc2 Adam Menz
                                        String[] info = {input.getText().toString(), "application/directory"};
479 a7d1fdc2 Adam Menz
                                        new AddFolderTask().execute(info);
480 a7d1fdc2 Adam Menz
                                }
481 a7d1fdc2 Adam Menz
                        })
482 a7d1fdc2 Adam Menz
                        .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
483 a7d1fdc2 Adam Menz
                                public void onClick(DialogInterface dialog, int whichButton) {
484 a7d1fdc2 Adam Menz
                                        // User clicked Cancel so do some stuff
485 a7d1fdc2 Adam Menz
                                }
486 a7d1fdc2 Adam Menz
                        })
487 a7d1fdc2 Adam Menz
                        .create();     
488 240418be Phillip Toohill
                }
489 240418be Phillip Toohill
                return null;
490 3d6041e8 Phillip Toohill
        }
491 3d6041e8 Phillip Toohill
492 240418be Phillip Toohill
        @Override
493 240418be Phillip Toohill
        public void onActivityResult(int requestCode, int resultCode, Intent data) {
494 240418be Phillip Toohill
                super.onActivityResult(requestCode, resultCode, data);
495 71e52c4a Adam Menz
496 e6c34a0f Adam Menz
                if (resultCode == RESULT_OK && requestCode == 56) {
497 240418be Phillip Toohill
                        // a sub-activity kicked back, so we want to refresh the server list
498 240418be Phillip Toohill
                        loadFiles();
499 240418be Phillip Toohill
                }
500 71e52c4a Adam Menz
501 3e180b04 Adam Menz
                // deleted file so need to update the list
502 3e180b04 Adam Menz
                if (requestCode == 55 && resultCode == 99) {
503 3e180b04 Adam Menz
                        loadFiles();
504 240418be Phillip Toohill
                }
505 71e52c4a Adam Menz
506 240418be Phillip Toohill
        }
507 240418be Phillip Toohill
508 d3ea294b Adam Menz
        class FileAdapter extends ArrayAdapter<ContainerObjects> {
509 d3ea294b Adam Menz
                FileAdapter() {
510 d3ea294b Adam Menz
                        super(ContainerObjectsActivity.this,
511 a7d1fdc2 Adam Menz
                                        R.layout.listcontainerobjectcell, app.getCurFiles());        
512 d3ea294b Adam Menz
                }
513 a7d1fdc2 Adam Menz
514 d3ea294b Adam Menz
                public View getView(int position, View convertView, ViewGroup parent) {
515 a7d1fdc2 Adam Menz
                        ContainerObjects file = app.getCurFiles().get(position);
516 d3ea294b Adam Menz
                        LayoutInflater inflater = getLayoutInflater();
517 d3ea294b Adam Menz
                        View row = inflater.inflate(R.layout.listcontainerobjectcell,
518 d3ea294b Adam Menz
                                        parent, false);
519 a7d1fdc2 Adam Menz
520 d3ea294b Adam Menz
                        TextView label = (TextView) row.findViewById(R.id.label);
521 d3ea294b Adam Menz
                        label.setText(getShortName(file.getCName()));
522 a7d1fdc2 Adam Menz
523 f506786e Adam Menz
                        ImageView objectImage = (ImageView) row.findViewById(R.id.file_type_image);
524 f506786e Adam Menz
                        if(file.getContentType().equals("application/directory")){
525 f506786e Adam Menz
                                objectImage.setImageResource(R.drawable.folder);
526 f506786e Adam Menz
                        } else {
527 f506786e Adam Menz
                                objectImage.setImageResource(R.drawable.file);
528 f506786e Adam Menz
                        }
529 f506786e Adam Menz
                        
530 d3ea294b Adam Menz
                        if (file.getBytes() >= bConver) {
531 d3ea294b Adam Menz
                                megaBytes = Math.abs(file.getBytes() / bConver + 0.2);
532 d3ea294b Adam Menz
                                TextView sublabel = (TextView) row.findViewById(R.id.sublabel);
533 d3ea294b Adam Menz
                                sublabel.setText(megaBytes + " MB");
534 d3ea294b Adam Menz
                        } else if (file.getBytes() >= kbConver) {
535 d3ea294b Adam Menz
                                kiloBytes = Math.abs(file.getBytes() / kbConver + 0.2);
536 d3ea294b Adam Menz
                                TextView sublabel = (TextView) row.findViewById(R.id.sublabel);
537 d3ea294b Adam Menz
                                sublabel.setText(kiloBytes + " KB");
538 d3ea294b Adam Menz
                        } else {
539 d3ea294b Adam Menz
                                TextView sublabel = (TextView) row.findViewById(R.id.sublabel);
540 d3ea294b Adam Menz
                                sublabel.setText(file.getBytes() + " B");
541 d3ea294b Adam Menz
                        }
542 a7d1fdc2 Adam Menz
543 d3ea294b Adam Menz
                        return (row);
544 d3ea294b Adam Menz
                }
545 d3ea294b Adam Menz
        }
546 71e52c4a Adam Menz
547 d3ea294b Adam Menz
        private class LoadFilesTask extends
548 a7d1fdc2 Adam Menz
        AsyncTask<String, Void, ArrayList<ContainerObjects>> {
549 240418be Phillip Toohill
550 3d6041e8 Phillip Toohill
                private CloudServersException exception;
551 71e52c4a Adam Menz
552 d3ea294b Adam Menz
                protected void onPreExecute(){
553 a7d1fdc2 Adam Menz
                        showDialog();
554 b2a2d2f1 Adam Menz
                        loadingFiles = true;
555 d3ea294b Adam Menz
                }
556 a7d1fdc2 Adam Menz
557 d3ea294b Adam Menz
                @Override
558 d3ea294b Adam Menz
                protected ArrayList<ContainerObjects> doInBackground(String... path) {
559 d3ea294b Adam Menz
                        ArrayList<ContainerObjects> files = null;
560 d3ea294b Adam Menz
                        try {
561 b2a2d2f1 Adam Menz
                                files = (new ContainerObjectManager(getContext())).createList(true,
562 d3ea294b Adam Menz
                                                container.getName());
563 d3ea294b Adam Menz
                        } catch (CloudServersException e) {
564 d3ea294b Adam Menz
                                exception = e;
565 d3ea294b Adam Menz
                                e.printStackTrace();
566 d3ea294b Adam Menz
                        }
567 d3ea294b Adam Menz
                        return files;
568 d3ea294b Adam Menz
                }
569 a7d1fdc2 Adam Menz
570 d3ea294b Adam Menz
                @Override
571 d3ea294b Adam Menz
                protected void onPostExecute(ArrayList<ContainerObjects> result) {
572 b2a2d2f1 Adam Menz
                        loadingFiles = false;
573 a7d1fdc2 Adam Menz
                        hideDialog();
574 d3ea294b Adam Menz
                        if (exception != null) {
575 d3ea294b Adam Menz
                                showAlert("Error", exception.getMessage());
576 d3ea294b Adam Menz
                        }
577 d3ea294b Adam Menz
                        setFileList(result);
578 3ea9d68e Adam Menz
                        loadCurrentDirectoryFiles();
579 3ea9d68e Adam Menz
                        displayCurrentFiles();
580 d3ea294b Adam Menz
                }
581 51938302 Adam Menz
582 d3ea294b Adam Menz
        }
583 d3ea294b Adam Menz
584 a7d1fdc2 Adam Menz
        private class AddFolderTask extends
585 a7d1fdc2 Adam Menz
        AsyncTask<String, Void, HttpBundle> {
586 3d6041e8 Phillip Toohill
587 3d6041e8 Phillip Toohill
                private CloudServersException exception;
588 a7d1fdc2 Adam Menz
589 a7d1fdc2 Adam Menz
                @Override
590 d3ea294b Adam Menz
                protected void onPreExecute(){
591 a7d1fdc2 Adam Menz
                        showDialog();
592 a7d1fdc2 Adam Menz
                        app.setAddingObject(true);
593 a7d1fdc2 Adam Menz
                        task = new AddObjectListenerTask();
594 a7d1fdc2 Adam Menz
                        task.execute();
595 d3ea294b Adam Menz
                }
596 a7d1fdc2 Adam Menz
597 3d6041e8 Phillip Toohill
                @Override
598 a7d1fdc2 Adam Menz
                protected HttpBundle doInBackground(String... data) {
599 32731215 Adam Menz
                        HttpBundle bundle = null;
600 3d6041e8 Phillip Toohill
                        try {
601 71e52c4a Adam Menz
602 b2a2d2f1 Adam Menz
                                bundle = (new ContainerObjectManager(getContext())).addObject(container.getName(), currentPath, data[0], data[1]);
603 3d6041e8 Phillip Toohill
                        } catch (CloudServersException e) {
604 3d6041e8 Phillip Toohill
                                exception = e;
605 3d6041e8 Phillip Toohill
                        }
606 32731215 Adam Menz
                        return bundle;
607 3d6041e8 Phillip Toohill
                }
608 240418be Phillip Toohill
609 3d6041e8 Phillip Toohill
                @Override
610 32731215 Adam Menz
                protected void onPostExecute(HttpBundle bundle) {
611 a7d1fdc2 Adam Menz
                        app.setAddingObject(false);
612 b2a2d2f1 Adam Menz
                        hideDialog();
613 32731215 Adam Menz
                        HttpResponse response = bundle.getResponse();
614 3d6041e8 Phillip Toohill
                        if (response != null) {
615 3d6041e8 Phillip Toohill
                                int statusCode = response.getStatusLine().getStatusCode();
616 a7d1fdc2 Adam Menz
                                if (statusCode == 201) {
617 37a14877 Adam Menz
                                        setResult(Activity.RESULT_OK);
618 a7d1fdc2 Adam Menz
                                        //loading the new files is done by ListenerTask
619 37a14877 Adam Menz
                                } else {
620 37a14877 Adam Menz
                                        CloudServersException cse = parseCloudServersException(response);
621 37a14877 Adam Menz
                                        if ("".equals(cse.getMessage())) {
622 b2a2d2f1 Adam Menz
                                                showError("There was a problem deleting your folder.", bundle);
623 37a14877 Adam Menz
                                        } else {
624 b2a2d2f1 Adam Menz
                                                showError("There was a problem deleting your folder: "
625 a7d1fdc2 Adam Menz
                                                                + cse.getMessage(), bundle);
626 37a14877 Adam Menz
                                        }
627 37a14877 Adam Menz
                                }
628 37a14877 Adam Menz
                        } else if (exception != null) {
629 b2a2d2f1 Adam Menz
                                showError("There was a problem deleting your folder: "
630 32731215 Adam Menz
                                                + exception.getMessage(), bundle);
631 37a14877 Adam Menz
                        }
632 37a14877 Adam Menz
                }
633 37a14877 Adam Menz
        }
634 a7d1fdc2 Adam Menz
635 a7d1fdc2 Adam Menz
        private class DeleteObjectTask extends
636 a7d1fdc2 Adam Menz
        AsyncTask<Void, Void, HttpBundle> {
637 71e52c4a Adam Menz
638 d3ea294b Adam Menz
                private CloudServersException exception;
639 71e52c4a Adam Menz
640 d3ea294b Adam Menz
                @Override
641 a7d1fdc2 Adam Menz
                protected void onPreExecute(){
642 a7d1fdc2 Adam Menz
                        showDialog();
643 a7d1fdc2 Adam Menz
                        app.setDeleteingObject(true);
644 a7d1fdc2 Adam Menz
                        deleteObjTask = new DeleteObjectListenerTask();
645 a7d1fdc2 Adam Menz
                        deleteObjTask.execute();
646 a7d1fdc2 Adam Menz
                }
647 71e52c4a Adam Menz
648 a7d1fdc2 Adam Menz
                @Override
649 a7d1fdc2 Adam Menz
                protected HttpBundle doInBackground(Void... arg0) {
650 32731215 Adam Menz
                        HttpBundle bundle = null;
651 d3ea294b Adam Menz
                        try {
652 a7d1fdc2 Adam Menz
                                //subtring because the current directory contains a "/" at the end of the string
653 b2a2d2f1 Adam Menz
                                bundle = (new ContainerObjectManager(getContext())).deleteObject(container.getName(), currentPath.substring(0, currentPath.length()-1));
654 d3ea294b Adam Menz
                        } catch (CloudServersException e) {
655 d3ea294b Adam Menz
                                exception = e;
656 d3ea294b Adam Menz
                        }
657 32731215 Adam Menz
                        return bundle;
658 d3ea294b Adam Menz
                }
659 71e52c4a Adam Menz
660 d3ea294b Adam Menz
                @Override
661 32731215 Adam Menz
                protected void onPostExecute(HttpBundle bundle) {
662 a7d1fdc2 Adam Menz
                        app.setDeleteingObject(false);
663 b2a2d2f1 Adam Menz
                        hideDialog();
664 32731215 Adam Menz
                        HttpResponse response = bundle.getResponse();
665 d3ea294b Adam Menz
                        if (response != null) {
666 d3ea294b Adam Menz
                                int statusCode = response.getStatusLine().getStatusCode();
667 a7d1fdc2 Adam Menz
                                if (statusCode == 409) {
668 a7d1fdc2 Adam Menz
                                        showAlert("Error",
669 a7d1fdc2 Adam Menz
                                        "Folder must be empty in order to delete");
670 a7d1fdc2 Adam Menz
                                }
671 a7d1fdc2 Adam Menz
                                if (statusCode == 204) {
672 d3ea294b Adam Menz
                                        setResult(Activity.RESULT_OK);
673 3e180b04 Adam Menz
                                } else {
674 d3ea294b Adam Menz
                                        CloudServersException cse = parseCloudServersException(response);
675 d3ea294b Adam Menz
                                        if ("".equals(cse.getMessage())) {
676 b2a2d2f1 Adam Menz
                                                showError("There was a problem deleting your folder.", bundle);
677 d3ea294b Adam Menz
                                        } else {
678 b2a2d2f1 Adam Menz
                                                showError("There was a problem deleting your folder: "
679 a7d1fdc2 Adam Menz
                                                                + cse.getMessage(), bundle);
680 d3ea294b Adam Menz
                                        }
681 d3ea294b Adam Menz
                                }
682 d3ea294b Adam Menz
                        } else if (exception != null) {
683 b2a2d2f1 Adam Menz
                                showError("There was a problem deleting your folder: "
684 32731215 Adam Menz
                                                + exception.getMessage(), bundle);
685 d3ea294b Adam Menz
                        }
686 d3ea294b Adam Menz
                }
687 d3ea294b Adam Menz
        }
688 d3ea294b Adam Menz
689 37a14877 Adam Menz
        private class DeleteContainerTask extends
690 32731215 Adam Menz
        AsyncTask<String, Void, HttpBundle> {
691 37a14877 Adam Menz
692 37a14877 Adam Menz
                private CloudServersException exception;
693 37a14877 Adam Menz
694 37a14877 Adam Menz
                @Override
695 b2a2d2f1 Adam Menz
                protected void onPreExecute(){ 
696 a7d1fdc2 Adam Menz
                        showDialog();
697 a7d1fdc2 Adam Menz
                        app.setDeletingContainer(true);
698 a7d1fdc2 Adam Menz
                        deleteContainerTask = new DeleteContainerListenerTask();
699 a7d1fdc2 Adam Menz
                        deleteContainerTask.execute();
700 a7d1fdc2 Adam Menz
                }
701 71e52c4a Adam Menz
702 a7d1fdc2 Adam Menz
                @Override
703 32731215 Adam Menz
                protected HttpBundle doInBackground(String... object) {
704 32731215 Adam Menz
                        HttpBundle bundle = null;
705 37a14877 Adam Menz
                        try {
706 b2a2d2f1 Adam Menz
                                bundle = (new ContainerManager(getContext())).delete(container.getName());
707 3d6041e8 Phillip Toohill
                        } catch (CloudServersException e) {
708 3d6041e8 Phillip Toohill
                                exception = e;
709 3d6041e8 Phillip Toohill
                        }
710 32731215 Adam Menz
                        return bundle;
711 3d6041e8 Phillip Toohill
                }
712 240418be Phillip Toohill
713 3d6041e8 Phillip Toohill
                @Override
714 32731215 Adam Menz
                protected void onPostExecute(HttpBundle bundle) {
715 a7d1fdc2 Adam Menz
                        hideDialog();
716 a7d1fdc2 Adam Menz
                        app.setDeletingContainer(false);
717 32731215 Adam Menz
                        HttpResponse response = bundle.getResponse();
718 3d6041e8 Phillip Toohill
                        if (response != null) {
719 3d6041e8 Phillip Toohill
                                int statusCode = response.getStatusLine().getStatusCode();
720 3d6041e8 Phillip Toohill
                                if (statusCode == 409) {
721 b2a2d2f1 Adam Menz
                                        showError("Container must be empty in order to delete", bundle);
722 3d6041e8 Phillip Toohill
                                }
723 3d6041e8 Phillip Toohill
                                if (statusCode == 204) {
724 3d6041e8 Phillip Toohill
                                        setResult(Activity.RESULT_OK);
725 240418be Phillip Toohill
726 3d6041e8 Phillip Toohill
                                } else {
727 3d6041e8 Phillip Toohill
                                        CloudServersException cse = parseCloudServersException(response);
728 3d6041e8 Phillip Toohill
                                        if ("".equals(cse.getMessage())) {
729 b2a2d2f1 Adam Menz
                                                showError("There was a problem deleting your container.", bundle);
730 3d6041e8 Phillip Toohill
                                        } else {
731 b2a2d2f1 Adam Menz
                                                showError("There was a problem deleting your container: "
732 a7d1fdc2 Adam Menz
                                                                + cse.getMessage(), bundle);
733 3d6041e8 Phillip Toohill
                                        }
734 3d6041e8 Phillip Toohill
                                }
735 3d6041e8 Phillip Toohill
                        } else if (exception != null) {
736 b2a2d2f1 Adam Menz
                                showError("There was a problem deleting your server: "
737 32731215 Adam Menz
                                                + exception.getMessage(), bundle);
738 240418be Phillip Toohill
                        }
739 3d6041e8 Phillip Toohill
                }
740 240418be Phillip Toohill
        }
741 3d6041e8 Phillip Toohill
742 a7d1fdc2 Adam Menz
        /*
743 a7d1fdc2 Adam Menz
         * listens for the application to change isProcessing
744 a7d1fdc2 Adam Menz
         * listens so activity knows when it should display
745 a7d1fdc2 Adam Menz
         * the new curDirFiles
746 a7d1fdc2 Adam Menz
         */
747 a7d1fdc2 Adam Menz
        private class AddObjectListenerTask extends
748 a7d1fdc2 Adam Menz
        AsyncTask<Void, Void, Void> {
749 71e52c4a Adam Menz
750 a7d1fdc2 Adam Menz
                @Override
751 a7d1fdc2 Adam Menz
                protected Void doInBackground(Void... arg1) {
752 a7d1fdc2 Adam Menz
753 a7d1fdc2 Adam Menz
                        while(app.isAddingObject()){
754 a7d1fdc2 Adam Menz
                                // wait for process to finish
755 a7d1fdc2 Adam Menz
                                // or have it be canceled
756 a7d1fdc2 Adam Menz
                                if(task.isCancelled()){
757 a7d1fdc2 Adam Menz
                                        return null;
758 a7d1fdc2 Adam Menz
                                }
759 a7d1fdc2 Adam Menz
                        }
760 a7d1fdc2 Adam Menz
                        return null;
761 a7d1fdc2 Adam Menz
                }
762 a7d1fdc2 Adam Menz
763 a7d1fdc2 Adam Menz
                /*
764 a7d1fdc2 Adam Menz
                 * when no longer processing, time to load
765 a7d1fdc2 Adam Menz
                 * the new files
766 a7d1fdc2 Adam Menz
                 */
767 a7d1fdc2 Adam Menz
                @Override
768 a7d1fdc2 Adam Menz
                protected void onPostExecute(Void arg1) {
769 b2a2d2f1 Adam Menz
                        hideDialog();
770 a7d1fdc2 Adam Menz
                        loadFiles();
771 a7d1fdc2 Adam Menz
                }
772 a7d1fdc2 Adam Menz
        }
773 71e52c4a Adam Menz
774 71e52c4a Adam Menz
775 a7d1fdc2 Adam Menz
        private class DeleteObjectListenerTask extends
776 a7d1fdc2 Adam Menz
        AsyncTask<Void, Void, Void> {
777 71e52c4a Adam Menz
778 a7d1fdc2 Adam Menz
                @Override
779 a7d1fdc2 Adam Menz
                protected Void doInBackground(Void... arg1) {
780 a7d1fdc2 Adam Menz
781 a7d1fdc2 Adam Menz
                        while(app.isDeletingObject()){
782 a7d1fdc2 Adam Menz
                                // wait for process to finish
783 a7d1fdc2 Adam Menz
                                // or have it be canceled
784 a7d1fdc2 Adam Menz
                                if(deleteObjTask.isCancelled()){
785 a7d1fdc2 Adam Menz
                                        return null;
786 a7d1fdc2 Adam Menz
                                }
787 a7d1fdc2 Adam Menz
                        }
788 a7d1fdc2 Adam Menz
                        return null;
789 a7d1fdc2 Adam Menz
                }
790 a7d1fdc2 Adam Menz
791 a7d1fdc2 Adam Menz
                /*
792 a7d1fdc2 Adam Menz
                 * when no longer processing, time to load
793 a7d1fdc2 Adam Menz
                 * the new files
794 a7d1fdc2 Adam Menz
                 */
795 a7d1fdc2 Adam Menz
                @Override
796 a7d1fdc2 Adam Menz
                protected void onPostExecute(Void arg1) {
797 a7d1fdc2 Adam Menz
                        hideDialog();
798 a7d1fdc2 Adam Menz
                        removeFromList(currentPath);
799 a7d1fdc2 Adam Menz
                        goUpDirectory();
800 a7d1fdc2 Adam Menz
                }
801 a7d1fdc2 Adam Menz
        }
802 71e52c4a Adam Menz
803 a7d1fdc2 Adam Menz
        private class DeleteContainerListenerTask extends
804 a7d1fdc2 Adam Menz
        AsyncTask<Void, Void, Void> {
805 71e52c4a Adam Menz
806 a7d1fdc2 Adam Menz
                @Override
807 a7d1fdc2 Adam Menz
                protected Void doInBackground(Void... arg1) {
808 a7d1fdc2 Adam Menz
809 a06c1add Adam Menz
                        while(app.isDeletingContainer()){
810 a7d1fdc2 Adam Menz
                                // wait for process to finish
811 a7d1fdc2 Adam Menz
                                // or have it be canceled
812 a7d1fdc2 Adam Menz
                                if(deleteContainerTask.isCancelled()){
813 a7d1fdc2 Adam Menz
                                        return null;
814 a7d1fdc2 Adam Menz
                                }
815 a7d1fdc2 Adam Menz
                        }
816 a7d1fdc2 Adam Menz
                        return null;
817 a7d1fdc2 Adam Menz
                }
818 a7d1fdc2 Adam Menz
819 a7d1fdc2 Adam Menz
                /*
820 a7d1fdc2 Adam Menz
                 * when no longer processing, time to load
821 a7d1fdc2 Adam Menz
                 * the new files
822 a7d1fdc2 Adam Menz
                 */
823 a7d1fdc2 Adam Menz
                @Override
824 a7d1fdc2 Adam Menz
                protected void onPostExecute(Void arg1) {
825 877f6f58 Adam Menz
826 877f6f58 Adam Menz
                        hideDialog();
827 a06c1add Adam Menz
                        setResult(RESULT_OK);
828 a7d1fdc2 Adam Menz
                        finish();
829 a7d1fdc2 Adam Menz
                }
830 a7d1fdc2 Adam Menz
        }
831 3d6041e8 Phillip Toohill
}