Revision 378fe36a src/com/rackspace/cloud/android/ContainerObjectsActivity.java

b/src/com/rackspace/cloud/android/ContainerObjectsActivity.java
1 1
package com.rackspace.cloud.android;
2 2

  
3

  
4

  
5 3
import java.io.File;
6 4
import java.net.URLEncoder;
7 5
import java.util.ArrayList;
......
21 19
import android.os.AsyncTask;
22 20
import android.os.Bundle;
23 21
import android.util.Log;
22
import android.util.Pair;
24 23
import android.view.ContextMenu;
25 24
import android.view.ContextMenu.ContextMenuInfo;
26 25
import android.view.LayoutInflater;
......
42 41
import com.rackspace.cloud.files.api.client.ContainerManager;
43 42
import com.rackspace.cloud.files.api.client.ContainerObjectManager;
44 43
import com.rackspace.cloud.files.api.client.ContainerObjects;
45
import com.rackspace.cloud.files.api.client.parsers.OthersXmlParser;
44
import com.rackspace.cloud.servers.api.client.Account;
46 45
import com.rackspace.cloud.servers.api.client.CloudServersException;
47 46
import com.rackspace.cloud.servers.api.client.http.HttpBundle;
47
import com.rackspace.cloud.servers.api.client.http.HttpBundleNoNetwork;
48
import com.rackspace.cloud.utils.Utils;
48 49

  
49 50
/**
50 51
 * 
......
59 60
	private static final int deleteContext = 2;
60 61
	private static final int toTrashContext = 3;
61 62
	private static final int fromTrashContext = 4;
62
	private String currentSelectedPath=null;
63
	private String currentSelectedPath = null;
63 64
	private ContainerObjects[] files;
64 65
	private static Container container;
65 66
	public String LOG = "viewFilesActivity";
......
74 75
	private AddObjectListenerTask task;
75 76
	private DeleteObjectListenerTask deleteObjTask;
76 77
	private DeleteContainerListenerTask deleteContainerTask;
77
	
78 78

  
79 79
	@Override
80 80
	public void onCreate(Bundle savedInstanceState) {
......
86 86
		} else {
87 87
			cdnEnabledIs = "false";
88 88
		}
89
		
89

  
90 90
		restoreState(savedInstanceState);
91 91
	}
92 92

  
......
109 109

  
110 110
	protected void restoreState(Bundle state) {
111 111
		super.restoreState(state);
112
		
112

  
113 113
		/*
114 114
		 * need reference to the app so you can access curDirFiles as well as
115 115
		 * processing status
......
148 148
		 */
149 149
		if (app.isAddingObject()) {
150 150
			task = new AddObjectListenerTask();
151
			task.execute();
151
			Utils.execute(task);
152 152
		}
153 153

  
154 154
		if (app.isDeletingObject()) {
155 155
			displayNoFilesCell();
156 156
			deleteObjTask = new DeleteObjectListenerTask();
157
			deleteObjTask.execute();
157
			Utils.execute(deleteObjTask);
158 158
		}
159 159

  
160 160
		if (app.isDeletingContainer()) {
161 161
			displayNoFilesCell();
162 162
			deleteContainerTask = new DeleteContainerListenerTask();
163
			deleteContainerTask.execute();
163
			Utils.execute(deleteContainerTask);
164 164
		}
165 165

  
166 166
	}
......
191 191
	 * activities when we navigate the file structure
192 192
	 */
193 193
	public void onBackPressed() {
194
		
194

  
195 195
		if (currentPath.equals("")) {
196
			if(container.getName().equals(Container.MYSHARED)){}
197
			else
196
			if (container.getName().equals(Container.MYSHARED)) {
197
			} else
198 198
				finish();
199 199
		} else {
200 200
			goUpDirectory();
201 201
		}
202 202
	}
203

  
203 204
	List<ContainerObjects> previousFiles = new ArrayList<ContainerObjects>();
205

  
204 206
	/*
205 207
	 * go to the current directory's parent and display that data
206 208
	 */
207 209
	private void goUpDirectory() {
208
		if(currentSelectedPath != null){
209
			currentSelectedPath=null;
210
		if (currentSelectedPath != null) {
211
			currentSelectedPath = null;
210 212
			loadFiles();
211 213
			return;
212 214
		}
......
214 216
				0,
215 217
				currentPath.substring(0, currentPath.length() - 2).lastIndexOf(
216 218
						"/") + 1);
217
		if(previousFiles!=null&&previousFiles.size()>0){
218
			files = previousFiles.toArray(new ContainerObjects[]{});
219
			previousFiles=null;
219
		if (previousFiles != null && previousFiles.size() > 0) {
220
			files = previousFiles.toArray(new ContainerObjects[] {});
221
			previousFiles = null;
220 222
			loadCurrentDirectoryFiles();
221 223
			displayCurrentFiles();
222
		}
223
		else
224
		} else
224 225
			loadFiles();
225
		//now executing new call
226
		
226
		// now executing new call
227

  
227 228
	}
228 229

  
229 230
	/*
......
256 257
	 * determines if a file should be displayed in current directory
257 258
	 */
258 259
	protected Boolean fileBelongsInDir(ContainerObjects obj) {
259
		/*String objPath = obj.getCName();
260

  
261
		if (!objPath.startsWith(currentPath)) {
262
			Log.i(LOG, "Path is:" + currentPath + " " + objPath + " " + false);
263
			return false;
264
		} else {
265
			objPath = objPath.substring(currentPath.length());
266
			Log.i(LOG, "Path is:" + currentPath + " " + objPath + " "
267
					+ !objPath.contains("/"));
268
			return !objPath.contains("/");
269
		}*/
260
		/*
261
		 * String objPath = obj.getCName();
262
		 * 
263
		 * if (!objPath.startsWith(currentPath)) { Log.i(LOG, "Path is:" +
264
		 * currentPath + " " + objPath + " " + false); return false; } else {
265
		 * objPath = objPath.substring(currentPath.length()); Log.i(LOG,
266
		 * "Path is:" + currentPath + " " + objPath + " " +
267
		 * !objPath.contains("/")); return !objPath.contains("/"); }
268
		 */
270 269
		return true;
271 270
	}
272 271

  
......
291 290
	}
292 291

  
293 292
	protected void displayCurrentFiles() {
294
		if(container.getOtherUser()==null)
295
			setTitle(container.getName()+": /"+currentPath);
296
		else
297
			setTitle(container.getOtherUser()+":"+container.getName()+"/"+currentPath);
293
		if (container.getOtherUser() == null)
294
			setTitle(container.getName() + ": /" + currentPath);
295
		else {
296
			String displayName = Account.getAccount().getDisplayNameForUUID(
297
					container.getOtherUser(), ContainerObjectsActivity.this);
298
			if (displayName == null) {
299
				displayName = container.getOtherUser();
300
			}
301
			setTitle(displayName + ":" + container.getName() + "/"
302
					+ currentPath);
303
		}
298 304
		if (app.getCurFiles().size() == 0) {
299 305
			displayNoFilesCell();
300 306
		} else {
......
369 375
			Intent viewIntent;
370 376
			if (app.getCurFiles().get(position).isFolder()) {
371 377
				currentPath = app.getCurFiles().get(position).getCName() + "/";
372
				/*if(container.getName().equalsIgnoreCase(Container.MYSHARED)){
373
					loadCurrentDirectoryFiles();
374
					displayCurrentFiles();
375
				}
376
				else{*/
377
					previousFiles = Arrays.asList(files);
378
					loadFiles();
379
				//}
380
				//loadCurrentDirectoryFiles();
381
				//displayCurrentFiles();
378
				/*
379
				 * if(container.getName().equalsIgnoreCase(Container.MYSHARED)){
380
				 * loadCurrentDirectoryFiles(); displayCurrentFiles(); } else{
381
				 */
382
				previousFiles = Arrays.asList(files);
383
				loadFiles();
384
				// }
385
				// loadCurrentDirectoryFiles();
386
				// displayCurrentFiles();
382 387
			}
383 388

  
384 389
			else {
......
386 391
				viewIntent.putExtra("container", app.getCurFiles()
387 392
						.get(position));
388 393
				viewIntent.putExtra("cdnUrl", container.getCdnUrl());
389
				if(container.getOtherUser()!=null)
394
				if (container.getOtherUser() != null)
390 395
					viewIntent.putExtra("otherUser", container.getOtherUser());
391 396
				viewIntent.putExtra("containerNames", container.getName());
392 397
				viewIntent.putExtra("isCdnEnabled", cdnEnabledIs);
......
403 408
		MenuInflater inflater = getMenuInflater();
404 409
		inflater.inflate(R.menu.view_container_object_list_menu, menu);
405 410
		menu.findItem(R.id.enable_cdn).setVisible(false);
406
		if(Container.TRASH.equalsIgnoreCase(container.getName())){
411
		if (Container.TRASH.equalsIgnoreCase(container.getName())) {
407 412
			menu.findItem(R.id.delete_container).setVisible(false);
408 413
			menu.findItem(R.id.add_folder).setVisible(false);
409 414
			menu.findItem(R.id.add_file).setVisible(false);
410
		}
411
		else if(Container.MYSHARED.equalsIgnoreCase(container.getName())){
415
		} else if (Container.MYSHARED.equalsIgnoreCase(container.getName())) {
412 416
			menu.findItem(R.id.delete_container).setVisible(false);
413 417
			menu.findItem(R.id.add_folder).setVisible(false);
414 418
			menu.findItem(R.id.add_file).setVisible(false);
415 419
		}
416 420
		return true;
417 421
	}
422

  
418 423
	@Override
419 424
	public void onCreateContextMenu(ContextMenu menu, View v,
420 425
			ContextMenuInfo menuInfo) {
......
422 427
		MenuInflater inflater = getMenuInflater();
423 428
		inflater.inflate(R.menu.view_container_object_list_context, menu);
424 429
		menu.findItem(R.id.fromtrash_contextmenu).setVisible(false);
425
		if(Container.TRASH.equalsIgnoreCase(container.getName())){
430
		if (Container.TRASH.equalsIgnoreCase(container.getName())) {
426 431
			menu.findItem(R.id.delete_contextmenu).setVisible(true);
427 432
			menu.findItem(R.id.totrash_contextmenu).setVisible(false);
428 433
			menu.findItem(R.id.properties_contextmenu).setVisible(false);
429 434
			menu.findItem(R.id.fromtrash_contextmenu).setVisible(true);
430
		}
431
		else if(Container.MYSHARED.equalsIgnoreCase(container.getName())){
435
		} else if (Container.MYSHARED.equalsIgnoreCase(container.getName())) {
432 436
			menu.findItem(R.id.delete_contextmenu).setVisible(false);
433 437
			menu.findItem(R.id.totrash_contextmenu).setVisible(false);
434 438
		}
435 439
	}
436
	ContainerObjects currentSelectedObject=null;
440

  
441
	ContainerObjects currentSelectedObject = null;
442

  
437 443
	@Override
438 444
	public boolean onContextItemSelected(final MenuItem item) {
439 445
		final AdapterView.AdapterContextMenuInfo info;
440 446
		try {
441
		    info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
447
			info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
442 448
		} catch (ClassCastException e) {
443
		    Log.e(LOG, "bad menuInfo", e);
444
		    return false;
449
			Log.e(LOG, "bad menuInfo", e);
450
			return false;
445 451
		}
446 452
		long id = getListAdapter().getItemId(info.position);
447
		final ContainerObjects obj = (ContainerObjects) getListAdapter().getItem(info.position);
453
		final ContainerObjects obj = (ContainerObjects) getListAdapter()
454
				.getItem(info.position);
448 455
		currentSelectedPath = obj.getCName() + "/";
449
		currentSelectedObject=obj;
456
		currentSelectedObject = obj;
450 457
		switch (item.getItemId()) {
451
			case R.id.delete_contextmenu:
452
				showDialog(deleteContext);
453
				return true;
454
			case R.id.totrash_contextmenu:
455
				showDialog(toTrashContext);
456
				return true;
457
			case R.id.fromtrash_contextmenu:
458
				showDialog(fromTrashContext);
459
				return true;
460
			case R.id.properties_contextmenu:
461
				Intent viewIntent;
462
				viewIntent = new Intent(this, ContainerObjectDetails.class);
463
				viewIntent.putExtra("container", obj);
464
				viewIntent.putExtra("cdnUrl", container.getCdnUrl());
465
				if(container.getOtherUser()!=null)
466
					viewIntent.putExtra("otherUser", container.getOtherUser());
467
				viewIntent.putExtra("containerNames", container.getName());
468
				viewIntent.putExtra("isCdnEnabled", cdnEnabledIs);
469
				startActivityForResult(viewIntent, 55);
470
				return true;
471
			
458
		case R.id.delete_contextmenu:
459
			showDialog(deleteContext);
460
			return true;
461
		case R.id.totrash_contextmenu:
462
			showDialog(toTrashContext);
463
			return true;
464
		case R.id.fromtrash_contextmenu:
465
			showDialog(fromTrashContext);
466
			return true;
467
		case R.id.properties_contextmenu:
468
			Intent viewIntent;
469
			viewIntent = new Intent(this, ContainerObjectDetails.class);
470
			viewIntent.putExtra("container", obj);
471
			viewIntent.putExtra("cdnUrl", container.getCdnUrl());
472
			if (container.getOtherUser() != null)
473
				viewIntent.putExtra("otherUser", container.getOtherUser());
474
			viewIntent.putExtra("containerNames", container.getName());
475
			viewIntent.putExtra("isCdnEnabled", cdnEnabledIs);
476
			startActivityForResult(viewIntent, 55);
477
			return true;
478

  
472 479
		}
473
		currentSelectedPath=null;
474
		currentSelectedObject=null;
480
		currentSelectedPath = null;
481
		currentSelectedObject = null;
475 482
		return false;
476
		
483

  
477 484
	}
485

  
478 486
	@Override
479 487
	/*
480 488
	 * option performed for delete depends on if you are at the top of a
......
581 589
									public void onClick(DialogInterface dialog,
582 590
											int whichButton) {
583 591
										// User clicked OK so do some stuff
584
										new DeleteObjectTask().execute(container.getName(), currentPath);
592
										new DeleteObjectTask().execute(
593
												container.getName(),
594
												currentPath);
585 595
									}
586 596
								})
587 597
						.setNegativeButton("Cancel",
......
594 604
			}
595 605
		case deleteContext:
596 606
			return new AlertDialog.Builder(ContainerObjectsActivity.this)
597
				.setIcon(R.drawable.alert_dialog_icon)
598
				.setTitle("Delete Object")
599
				.setMessage(
600
						"Are you sure you want to delete this Object?")
601
							.setPositiveButton("Delete Object",
602
									new DialogInterface.OnClickListener() {
603
										public void onClick(DialogInterface dialog,
604
												int whichButton) {
605
											// 	User clicked OK so do some stuff
606
											new DeleteObjectTask().execute(container.getName(), currentSelectedPath);
607
										}
608
									})
609
									.setNegativeButton("Cancel",
610
											new DialogInterface.OnClickListener() {
611
										public void onClick(DialogInterface dialog,
612
												int whichButton) {
613
											currentSelectedPath=null;
614
											// User clicked Cancel so do some stuff
615
										}
616
									}).create();
607
					.setIcon(R.drawable.alert_dialog_icon)
608
					.setTitle("Delete Object")
609
					.setMessage("Are you sure you want to delete this Object?")
610
					.setPositiveButton("Delete Object",
611
							new DialogInterface.OnClickListener() {
612
								public void onClick(DialogInterface dialog,
613
										int whichButton) {
614
									// User clicked OK so do some stuff
615
									new DeleteObjectTask().execute(
616
											container.getName(),
617
											currentSelectedPath);
618
								}
619
							})
620
					.setNegativeButton("Cancel",
621
							new DialogInterface.OnClickListener() {
622
								public void onClick(DialogInterface dialog,
623
										int whichButton) {
624
									currentSelectedPath = null;
625
									// User clicked Cancel so do some stuff
626
								}
627
							}).create();
617 628
		case toTrashContext:
618 629
			return new AlertDialog.Builder(ContainerObjectsActivity.this)
619
				.setIcon(R.drawable.alert_dialog_icon)
620
				.setTitle("Move Object To Trash")
621
				.setMessage(
622
						"Are you sure you want to trash this Object?")
623
							.setPositiveButton("Trash Object",
624
									new DialogInterface.OnClickListener() {
625
										public void onClick(DialogInterface dialog,
626
												int whichButton) {
627
											// 	User clicked OK so do some stuff
628
											new TrashObjectTask().execute(container.getName(), currentSelectedPath);
629
										}
630
									})
631
									.setNegativeButton("Cancel",
632
											new DialogInterface.OnClickListener() {
633
										public void onClick(DialogInterface dialog,
634
												int whichButton) {
635
											currentSelectedPath=null;
636
											// User clicked Cancel so do some stuff
637
										}
638
									}).create();
630
					.setIcon(R.drawable.alert_dialog_icon)
631
					.setTitle("Move Object To Trash")
632
					.setMessage("Are you sure you want to trash this Object?")
633
					.setPositiveButton("Trash Object",
634
							new DialogInterface.OnClickListener() {
635
								public void onClick(DialogInterface dialog,
636
										int whichButton) {
637
									// User clicked OK so do some stuff
638
									new TrashObjectTask().execute(
639
											container.getName(),
640
											currentSelectedPath);
641
								}
642
							})
643
					.setNegativeButton("Cancel",
644
							new DialogInterface.OnClickListener() {
645
								public void onClick(DialogInterface dialog,
646
										int whichButton) {
647
									currentSelectedPath = null;
648
									// User clicked Cancel so do some stuff
649
								}
650
							}).create();
639 651
		case fromTrashContext:
640 652
			return new AlertDialog.Builder(ContainerObjectsActivity.this)
641
				.setIcon(R.drawable.alert_dialog_icon)
642
				.setTitle("Restore Object To Pithos")
643
				.setMessage(
644
						"Are you sure you want to restore this Object?")
645
							.setPositiveButton("Restore Object",
646
									new DialogInterface.OnClickListener() {
647
										public void onClick(DialogInterface dialog,
648
												int whichButton) {
649
											// 	User clicked OK so do some stuff
650
											new RestoreTrashObjectTask().execute(container.getName(), currentSelectedPath);
651
										}
652
									})
653
									.setNegativeButton("Cancel",
654
											new DialogInterface.OnClickListener() {
655
										public void onClick(DialogInterface dialog,
656
												int whichButton) {
657
											currentSelectedPath=null;
658
											// User clicked Cancel so do some stuff
659
										}
660
									}).create();
653
					.setIcon(R.drawable.alert_dialog_icon)
654
					.setTitle("Restore Object To Pithos")
655
					.setMessage("Are you sure you want to restore this Object?")
656
					.setPositiveButton("Restore Object",
657
							new DialogInterface.OnClickListener() {
658
								public void onClick(DialogInterface dialog,
659
										int whichButton) {
660
									// User clicked OK so do some stuff
661
									new RestoreTrashObjectTask().execute(
662
											container.getName(),
663
											currentSelectedPath);
664
								}
665
							})
666
					.setNegativeButton("Cancel",
667
							new DialogInterface.OnClickListener() {
668
								public void onClick(DialogInterface dialog,
669
										int whichButton) {
670
									currentSelectedPath = null;
671
									// User clicked Cancel so do some stuff
672
								}
673
							}).create();
661 674
		case R.id.add_folder:
662 675
			final EditText input = new EditText(this);
663 676
			return new AlertDialog.Builder(ContainerObjectsActivity.this)
......
696 709
			previousFiles = null;
697 710
			loadFiles();
698 711
		}
699
		
712

  
700 713
		if (resultCode == RESULT_OK && requestCode == 1) {
701 714
			String filename = data.getDataString();
702 715
			uploadFile(filename, data);
703
			
716

  
704 717
		}
705 718

  
706 719
		// deleted file so need to update the list
707 720
		if (requestCode == 55 && resultCode == 99) {
708
			Log.d(LOG,"LOADING FROM DDELETE");
721
			Log.d(LOG, "LOADING FROM DDELETE");
709 722
			previousFiles = null;
710 723
			loadFiles();
711 724
		}
......
745 758
				sublabel.setText(kiloBytes + " KB");
746 759
			} else {
747 760
				TextView sublabel = (TextView) row.findViewById(R.id.sublabel);
748
				sublabel.setText(file.getBytes() + " B");
761
				if(file.getBytes()>0)
762
					sublabel.setText(file.getBytes() + " B");
763
				else{
764
					sublabel.setText(" ");
765
				}
749 766
			}
750 767

  
751 768
			return (row);
......
768 785
			try {
769 786
				if (container.getName().equals(Container.MYSHARED)) {
770 787
					files = (new ContainerObjectManager(getContext()))
771
							.createListMyShared( container.getName(),
788
							.createListMyShared(container.getName(),
772 789
									new ContainerManager(getContext())
773
											.createList(true),path[0]);
790
											.createList(true), path[0]);
774 791
				} else if (container.getName().equals(Container.OTHERS)) {
775 792

  
776 793
				} else {
......
779 796
								.createList(container.getName(), path[0]);
780 797
					else
781 798
						files = (new ContainerObjectManager(getContext()))
782
								.createOtherList(container.getName(), container.getOtherUser(),path[0]);
799
								.createOtherList(container.getName(),
800
										container.getOtherUser(), path[0]);
783 801
				}
784 802
			} catch (CloudServersException e) {
785 803
				exception = e;
......
811 829
			showDialog();
812 830
			app.setAddingObject(true);
813 831
			task = new AddObjectListenerTask();
814
			task.execute();
832
			Utils.execute(task);
815 833
		}
816 834

  
817 835
		@Override
......
820 838
			try {
821 839

  
822 840
				bundle = (new ContainerObjectManager(getContext())).addObject(
823
						container.getName(), currentPath, data[0], data[1],container.getOtherUser());
841
						container.getName(), currentPath, data[0], data[1],
842
						container.getOtherUser());
824 843
			} catch (CloudServersException e) {
825 844
				exception = e;
826 845
			}
......
853 872
			}
854 873
		}
855 874
	}
856
	
875

  
857 876
	private class AddFileTask extends AsyncTask<String, Void, HttpBundle> {
858 877

  
859 878
		private CloudServersException exception;
......
863 882
			showDialog();
864 883
			app.setAddingObject(true);
865 884
			task = new AddObjectListenerTask();
866
			task.execute();
885
			Utils.execute(task);
867 886
		}
868 887

  
869 888
		@Override
......
871 890
			HttpBundle bundle = null;
872 891
			try {
873 892

  
874
				bundle = (new ContainerObjectManager(getContext())).addFileObject(
875
						container.getName(), currentPath, data[0], data[1], data[2], container.getOtherUser());
893
				bundle = (new ContainerObjectManager(getContext()))
894
						.addFileObject(container.getName(), currentPath,
895
								data[0], data[1], data[2],
896
								container.getOtherUser());
876 897
			} catch (CloudServersException e) {
877 898
				exception = e;
878 899
			}
......
892 913
				} else {
893 914
					CloudServersException cse = parseCloudServersException(response);
894 915
					if ("".equals(cse.getMessage())) {
895
						showError("There was a problem deleting your folder.",
916
						showError("There was a problem adding your file.",
896 917
								bundle);
897 918
					} else {
898
						showError("There was a problem deleting your folder: "
919
						showError("There was a problem adding your file: "
899 920
								+ cse.getMessage(), bundle);
900 921
					}
901 922
				}
902 923
			} else if (exception != null) {
903
				showError("There was a problem deleting your folder: "
904
						+ exception.getMessage(), bundle);
924
				showError(
925
						"There was a problem adding your file: "
926
								+ exception.getMessage(), bundle);
905 927
			}
906 928
		}
907 929
	}
......
909 931
	private class DeleteObjectTask extends AsyncTask<String, Void, HttpBundle> {
910 932

  
911 933
		private CloudServersException exception;
912
		public boolean isInFile=false;
934
		public boolean isInFile = false;
935

  
913 936
		@Override
914 937
		protected void onPreExecute() {
915 938
			showDialog();
916 939
			app.setDeleteingObject(true);
917 940
			deleteObjTask = new DeleteObjectListenerTask();
918
			deleteObjTask.execute();
941
			Utils.execute(deleteObjTask);
919 942
		}
920 943

  
921 944
		@Override
......
927 950
				String cname = args[0];
928 951
				String cpath = args[1];
929 952
				bundle = (new ContainerObjectManager(getContext()))
930
						.deleteObject(cname, cpath
931
								.substring(0, cpath.length() - 1),container.getOtherUser());
953
						.deleteObject(cname,
954
								cpath.substring(0, cpath.length() - 1),
955
								container.getOtherUser());
932 956
			} catch (CloudServersException e) {
933 957
				exception = e;
934 958
			}
......
964 988
			}
965 989
		}
966 990
	}
967
	
991

  
968 992
	private class TrashObjectTask extends AsyncTask<String, Void, HttpBundle> {
969 993

  
970 994
		private CloudServersException exception;
971
		public boolean isInFile=false;
995
		public boolean isInFile = false;
972 996
		String[] arguments;
997

  
973 998
		@Override
974 999
		protected void onPreExecute() {
975 1000
			showDialog();
976
			
1001

  
977 1002
		}
978 1003

  
979 1004
		@Override
......
986 1011
				String cname = args[0];
987 1012
				String cpath = args[1];
988 1013
				bundle = (new ContainerObjectManager(getContext()))
989
						.trashObject(cname, cpath
990
								.substring(0, cpath.length() - 1));
1014
						.trashObject(cname,
1015
								cpath.substring(0, cpath.length() - 1));
991 1016
			} catch (CloudServersException e) {
992 1017
				exception = e;
993 1018
			}
......
1009 1034
				} else {
1010 1035
					CloudServersException cse = parseCloudServersException(response);
1011 1036
					if ("".equals(cse.getMessage())) {
1012
						showError("There was a problem deleting your folder.",
1037
						showError("There was a problem trashing your folder.",
1013 1038
								bundle);
1014 1039
					} else {
1015
						showError("There was a problem deleting your folder: "
1040
						showError("There was a problem trashing your folder: "
1016 1041
								+ cse.getMessage(), bundle);
1017 1042
					}
1018 1043
				}
1019 1044
			} else if (exception != null) {
1020
				showError("There was a problem deleting your folder: "
1045
				showError("There was a problem trashing your folder: "
1021 1046
						+ exception.getMessage(), bundle);
1022 1047
			}
1023 1048
		}
1024 1049
	}
1025
	
1026
	private class RestoreTrashObjectTask extends AsyncTask<String, Void, HttpBundle> {
1050

  
1051
	private class RestoreTrashObjectTask extends
1052
			AsyncTask<String, Void, HttpBundle> {
1027 1053

  
1028 1054
		private CloudServersException exception;
1029
		public boolean isInFile=false;
1055
		public boolean isInFile = false;
1030 1056
		String[] arguments;
1057

  
1031 1058
		@Override
1032 1059
		protected void onPreExecute() {
1033 1060
			showDialog();
1034
			
1061

  
1035 1062
		}
1036 1063

  
1037 1064
		@Override
......
1044 1071
				String cname = args[0];
1045 1072
				String cpath = args[1];
1046 1073
				bundle = (new ContainerObjectManager(getContext()))
1047
						.restoreObject(cname, cpath
1048
								.substring(0, cpath.length() - 1));
1074
						.restoreObject(cname,
1075
								cpath.substring(0, cpath.length() - 1));
1049 1076
			} catch (CloudServersException e) {
1050 1077
				exception = e;
1051 1078
			}
......
1067 1094
				} else {
1068 1095
					CloudServersException cse = parseCloudServersException(response);
1069 1096
					if ("".equals(cse.getMessage())) {
1070
						showError("There was a problem deleting your folder.",
1097
						showError("There was a problem restoring your folder.",
1071 1098
								bundle);
1072 1099
					} else {
1073
						showError("There was a problem deleting your folder: "
1100
						showError("There was a problem restoring your folder: "
1074 1101
								+ cse.getMessage(), bundle);
1075 1102
					}
1076 1103
				}
1077 1104
			} else if (exception != null) {
1078
				showError("There was a problem deleting your folder: "
1105
				showError("There was a problem restoring your folder: "
1079 1106
						+ exception.getMessage(), bundle);
1080 1107
			}
1081 1108
		}
1082 1109
	}
1083 1110

  
1084 1111
	private class DeleteContainerTask extends
1085
			AsyncTask<String, Void, HttpBundle> {
1112
			AsyncTask<String, Void, Pair<Integer, Throwable>> {
1086 1113

  
1087 1114
		private CloudServersException exception;
1088 1115

  
......
1091 1118
			showDialog();
1092 1119
			app.setDeletingContainer(true);
1093 1120
			deleteContainerTask = new DeleteContainerListenerTask();
1094
			deleteContainerTask.execute();
1121
			Utils.execute(task);
1095 1122
		}
1096 1123

  
1097 1124
		@Override
1098
		protected HttpBundle doInBackground(String... object) {
1125
		protected Pair<Integer, Throwable> doInBackground(String... object) {
1099 1126
			HttpBundle bundle = null;
1100 1127
			try {
1101 1128
				bundle = (new ContainerManager(getContext())).delete(container
1102 1129
						.getName());
1130
				HttpResponse response = bundle.getResponse();
1131

  
1132
				if (response != null) {
1133
					int statusCode = response.getStatusLine().getStatusCode();
1134
					if (statusCode == 409 || statusCode == 204) {
1135
						return new Pair<Integer, Throwable>(statusCode, null);
1136
					}
1137
					return new Pair<Integer, Throwable>(-1,
1138
							parseCloudServersException(response));
1139
				}
1140
				return new Pair<Integer, Throwable>(-1, null);
1103 1141
			} catch (CloudServersException e) {
1104 1142
				exception = e;
1143
				return new Pair<Integer, Throwable>(-1, e);
1105 1144
			}
1106
			return bundle;
1145

  
1107 1146
		}
1108 1147

  
1109 1148
		@Override
1110
		protected void onPostExecute(HttpBundle bundle) {
1149
		protected void onPostExecute(Pair<Integer, Throwable> bundle) {
1111 1150
			hideDialog();
1112 1151
			app.setDeletingContainer(false);
1113
			HttpResponse response = bundle.getResponse();
1114
			if (response != null) {
1115
				int statusCode = response.getStatusLine().getStatusCode();
1116
				if (statusCode == 409) {
1117
					showError("Container must be empty in order to delete",
1118
							bundle);
1119
				}
1120
				if (statusCode == 204) {
1121
					setResult(Activity.RESULT_OK);
1122

  
1123
				} else {
1124
					CloudServersException cse = parseCloudServersException(response);
1152
			int statusCode = bundle.first;
1153
			if (statusCode == 409) {
1154
				showError("Container must be empty in order to delete", null);
1155
			} else if (statusCode == 204) {
1156
				setResult(Activity.RESULT_OK);
1157
			} else {
1158
				Throwable e = bundle.second;
1159
				if (e instanceof CloudServersException) {
1160
					CloudServersException cse = (CloudServersException) e;
1125 1161
					if ("".equals(cse.getMessage())) {
1126 1162
						showError(
1127 1163
								"There was a problem deleting your container.",
1128
								bundle);
1164
								null);
1129 1165
					} else {
1130 1166
						showError(
1131 1167
								"There was a problem deleting your container: "
1132
										+ cse.getMessage(), bundle);
1168
										+ cse.getMessage(), null);
1133 1169
					}
1170
				} else if (e != null) {
1171
					showError(
1172
							"There was a problem deleting your server: "
1173
									+ e.getMessage(), null);
1134 1174
				}
1135
			} else if (exception != null) {
1136
				showError("There was a problem deleting your server: "
1137
						+ exception.getMessage(), bundle);
1138 1175
			}
1139 1176
		}
1140 1177
	}
......
1189 1226
		@Override
1190 1227
		protected void onPostExecute(Void arg1) {
1191 1228
			hideDialog();
1192
			if(currentSelectedPath==null)
1229
			if (currentSelectedPath == null)
1193 1230
				removeFromList(currentPath);
1194
			previousFiles=null;
1231
			previousFiles = null;
1195 1232
			goUpDirectory();
1196 1233
		}
1197 1234
	}
......
1231 1268
	public ContainerObjects[] getFiles() {
1232 1269
		return files;
1233 1270
	}
1234
	
1271

  
1235 1272
	/***** UPLOAD FILE ****/
1236
	protected void uploadFile(String filename, Intent data){
1273
	protected void uploadFile(String filename, Intent data) {
1237 1274
		if (filename.startsWith("file://")) {
1238 1275
			filename = filename.substring(7);
1239 1276
		}
......
1245 1282
		String filenameNew = null;
1246 1283
		Long fileSize = null;
1247 1284
		if (!file.exists()) {
1248
			Cursor cursor = getContentResolver().query(data.getData(), null, null, null, null);
1285
			Cursor cursor = getContentResolver().query(data.getData(), null,
1286
					null, null, null);
1249 1287
			if (cursor != null) {
1250 1288
				while (cursor.moveToNext()) {
1251 1289
					for (int i = 0; i < cursor.getColumnCount(); i++) {
......
1261 1299
		}
1262 1300
		if (filenameNew != null) {
1263 1301
			file = new File(filenameNew);
1264
			String ext = MimeTypeMap.getSingleton().getFileExtensionFromUrl(file.getPath());
1265
			String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(ext);
1266
			String[] info = {
1267
					file.getName(),
1268
					mime, filenameNew};
1302
			String ext = MimeTypeMap.getSingleton().getFileExtensionFromUrl(
1303
					file.getPath());
1304
			String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(
1305
					ext);
1306
			String[] info = { file.getName(), mime, filenameNew };
1269 1307
			new AddFileTask().execute(info);
1270
			//getTasks().getUploadTask(GssMyFolders.this).execute(getCurrentResource().getUri() + URLEncoder.encode(file.getName()), filenameNew);
1308
			// getTasks().getUploadTask(GssMyFolders.this).execute(getCurrentResource().getUri()
1309
			// + URLEncoder.encode(file.getName()), filenameNew);
1271 1310
		}
1272 1311
	}
1273
	
1274
	protected void uploadFile(List<Uri> uris){
1312

  
1313
	protected void uploadFile(List<Uri> uris) {
1275 1314
		List<String> strings = new ArrayList<String>();
1276
		String path = "";//getCurrentResource().getUri();
1277
		if(!path.endsWith("/"))
1278
			path = path+"/";
1279
		
1280
		for(Uri data : uris){
1315
		String path = "";// getCurrentResource().getUri();
1316
		if (!path.endsWith("/"))
1317
			path = path + "/";
1318

  
1319
		for (Uri data : uris) {
1281 1320
			String filename = data.getPath();
1282 1321
			if (filename.startsWith("file://")) {
1283 1322
				filename = filename.substring(7);
......
1290 1329
			String filenameNew = null;
1291 1330
			Long fileSize = null;
1292 1331
			if (!file.exists()) {
1293
				Cursor cursor = getContentResolver().query(data, null, null, null, null);
1332
				Cursor cursor = getContentResolver().query(data, null, null,
1333
						null, null);
1294 1334
				if (cursor != null) {
1295 1335
					while (cursor.moveToNext()) {
1296 1336
						for (int i = 0; i < cursor.getColumnCount(); i++) {
......
1306 1346
			}
1307 1347
			if (filenameNew != null) {
1308 1348
				file = new File(filenameNew);
1309
				strings.add(path+URLEncoder.encode(file.getName()));
1349
				strings.add(path + URLEncoder.encode(file.getName()));
1310 1350
				strings.add(filenameNew);
1311 1351
			}
1312 1352
		}
1313
		Log.i("*******",""+strings.size());
1314
		//getTasks().getMultiUploadTask(this).execute(strings.toArray(new String[strings.size()]));
1315
			
1316
		
1353
		Log.i("*******", "" + strings.size());
1354
		// getTasks().getMultiUploadTask(this).execute(strings.toArray(new
1355
		// String[strings.size()]));
1356

  
1317 1357
	}
1318
	protected void uploadFile(Uri data){
1358

  
1359
	protected void uploadFile(Uri data) {
1319 1360
		String filename = data.getPath();
1320 1361
		if (filename.startsWith("file://")) {
1321 1362
			filename = filename.substring(7);
......
1328 1369
		String filenameNew = null;
1329 1370
		Long fileSize = null;
1330 1371
		if (!file.exists()) {
1331
			Cursor cursor = getContentResolver().query(data, null, null, null, null);
1372
			Cursor cursor = getContentResolver().query(data, null, null, null,
1373
					null);
1332 1374
			if (cursor != null) {
1333 1375
				while (cursor.moveToNext()) {
1334 1376
					for (int i = 0; i < cursor.getColumnCount(); i++) {
......
1344 1386
		}
1345 1387
		if (filenameNew != null) {
1346 1388
			file = new File(filenameNew);
1347
			//String path = getCurrentResource().getUri();
1348
			//if(!path.endsWith("/"))
1349
				//path = path+"/";
1350
			//getTasks().getUploadTask(GssMyFolders.this).execute(path + URLEncoder.encode(file.getName()), filenameNew);
1389
			// String path = getCurrentResource().getUri();
1390
			// if(!path.endsWith("/"))
1391
			// path = path+"/";
1392
			// getTasks().getUploadTask(GssMyFolders.this).execute(path +
1393
			// URLEncoder.encode(file.getName()), filenameNew);
1351 1394
		}
1352
		
1395

  
1353 1396
	}
1354 1397
}

Also available in: Unified diff