Statistics
| Branch: | Revision:

root / src / com / rackspacecloud / android / ContainerObjectsActivity.java @ 0edf6b39

History | View | Annotate | Download (25.3 kB)

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