Revision a2b9aced src/com/rackspace/cloud/android/ContainerObjectsActivity.java

b/src/com/rackspace/cloud/android/ContainerObjectsActivity.java
416 416
		inflater.inflate(R.menu.view_container_object_list_context, menu);
417 417
		menu.findItem(R.id.fromtrash_contextmenu).setVisible(false);
418 418
		if(Container.TRASH.equalsIgnoreCase(container.getName())){
419
			menu.findItem(R.id.delete_contextmenu).setVisible(false);
419
			menu.findItem(R.id.delete_contextmenu).setVisible(true);
420 420
			menu.findItem(R.id.totrash_contextmenu).setVisible(false);
421
			menu.findItem(R.id.properties_contextmenu).setVisible(false);
421 422
			menu.findItem(R.id.fromtrash_contextmenu).setVisible(true);
422 423
		}
423 424
		else if(Container.MYSHARED.equalsIgnoreCase(container.getName())){
......
425 426
			menu.findItem(R.id.totrash_contextmenu).setVisible(false);
426 427
		}
427 428
	}
428
	
429
	ContainerObjects currentSelectedObject=null;
429 430
	@Override
430 431
	public boolean onContextItemSelected(final MenuItem item) {
431 432
		final AdapterView.AdapterContextMenuInfo info;
......
438 439
		long id = getListAdapter().getItemId(info.position);
439 440
		final ContainerObjects obj = (ContainerObjects) getListAdapter().getItem(info.position);
440 441
		currentSelectedPath = obj.getCName() + "/";
442
		currentSelectedObject=obj;
441 443
		switch (item.getItemId()) {
442 444
			case R.id.delete_contextmenu:
443 445
				showDialog(deleteContext);
......
460 462
			
461 463
		}
462 464
		currentSelectedPath=null;
465
		currentSelectedObject=null;
463 466
		return false;
464 467
		
465 468
	}
......
602 605
											// User clicked Cancel so do some stuff
603 606
										}
604 607
									}).create();
608
		case toTrashContext:
609
			return new AlertDialog.Builder(ContainerObjectsActivity.this)
610
				.setIcon(R.drawable.alert_dialog_icon)
611
				.setTitle("Move Object To Trash")
612
				.setMessage(
613
						"Are you sure you want to trash this Object?")
614
							.setPositiveButton("Trash Object",
615
									new DialogInterface.OnClickListener() {
616
										public void onClick(DialogInterface dialog,
617
												int whichButton) {
618
											// 	User clicked OK so do some stuff
619
											new TrashObjectTask().execute(container.getName(), currentSelectedPath);
620
										}
621
									})
622
									.setNegativeButton("Cancel",
623
											new DialogInterface.OnClickListener() {
624
										public void onClick(DialogInterface dialog,
625
												int whichButton) {
626
											currentSelectedPath=null;
627
											// User clicked Cancel so do some stuff
628
										}
629
									}).create();
630
		case fromTrashContext:
631
			return new AlertDialog.Builder(ContainerObjectsActivity.this)
632
				.setIcon(R.drawable.alert_dialog_icon)
633
				.setTitle("Restore Object To Pithos")
634
				.setMessage(
635
						"Are you sure you want to restore this Object?")
636
							.setPositiveButton("Restore Object",
637
									new DialogInterface.OnClickListener() {
638
										public void onClick(DialogInterface dialog,
639
												int whichButton) {
640
											// 	User clicked OK so do some stuff
641
											new RestoreTrashObjectTask().execute(container.getName(), currentSelectedPath);
642
										}
643
									})
644
									.setNegativeButton("Cancel",
645
											new DialogInterface.OnClickListener() {
646
										public void onClick(DialogInterface dialog,
647
												int whichButton) {
648
											currentSelectedPath=null;
649
											// User clicked Cancel so do some stuff
650
										}
651
									}).create();
605 652
		case R.id.add_folder:
606 653
			final EditText input = new EditText(this);
607 654
			return new AlertDialog.Builder(ContainerObjectsActivity.this)
......
908 955
			}
909 956
		}
910 957
	}
958
	
959
	private class TrashObjectTask extends AsyncTask<String, Void, HttpBundle> {
960

  
961
		private CloudServersException exception;
962
		public boolean isInFile=false;
963
		String[] arguments;
964
		@Override
965
		protected void onPreExecute() {
966
			showDialog();
967
			
968
		}
969

  
970
		@Override
971
		protected HttpBundle doInBackground(String... args) {
972
			HttpBundle bundle = null;
973
			arguments = args;
974
			try {
975
				// subtring because the current directory contains a "/" at the
976
				// end of the string
977
				String cname = args[0];
978
				String cpath = args[1];
979
				bundle = (new ContainerObjectManager(getContext()))
980
						.trashObject(cname, cpath
981
								.substring(0, cpath.length() - 1));
982
			} catch (CloudServersException e) {
983
				exception = e;
984
			}
985
			return bundle;
986
		}
987

  
988
		@Override
989
		protected void onPostExecute(HttpBundle bundle) {
990
			hideDialog();
991
			HttpResponse response = bundle.getResponse();
992
			if (response != null) {
993
				int statusCode = response.getStatusLine().getStatusCode();
994
				if (statusCode == 409) {
995
					showAlert("Error",
996
							"Folder must be empty in order to delete");
997
				}
998
				if (statusCode == 201) {
999
					new DeleteObjectTask().execute(arguments);
1000
				} else {
1001
					CloudServersException cse = parseCloudServersException(response);
1002
					if ("".equals(cse.getMessage())) {
1003
						showError("There was a problem deleting your folder.",
1004
								bundle);
1005
					} else {
1006
						showError("There was a problem deleting your folder: "
1007
								+ cse.getMessage(), bundle);
1008
					}
1009
				}
1010
			} else if (exception != null) {
1011
				showError("There was a problem deleting your folder: "
1012
						+ exception.getMessage(), bundle);
1013
			}
1014
		}
1015
	}
1016
	
1017
	private class RestoreTrashObjectTask extends AsyncTask<String, Void, HttpBundle> {
1018

  
1019
		private CloudServersException exception;
1020
		public boolean isInFile=false;
1021
		String[] arguments;
1022
		@Override
1023
		protected void onPreExecute() {
1024
			showDialog();
1025
			
1026
		}
1027

  
1028
		@Override
1029
		protected HttpBundle doInBackground(String... args) {
1030
			HttpBundle bundle = null;
1031
			arguments = args;
1032
			try {
1033
				// subtring because the current directory contains a "/" at the
1034
				// end of the string
1035
				String cname = args[0];
1036
				String cpath = args[1];
1037
				bundle = (new ContainerObjectManager(getContext()))
1038
						.restoreObject(cname, cpath
1039
								.substring(0, cpath.length() - 1));
1040
			} catch (CloudServersException e) {
1041
				exception = e;
1042
			}
1043
			return bundle;
1044
		}
1045

  
1046
		@Override
1047
		protected void onPostExecute(HttpBundle bundle) {
1048
			hideDialog();
1049
			HttpResponse response = bundle.getResponse();
1050
			if (response != null) {
1051
				int statusCode = response.getStatusLine().getStatusCode();
1052
				if (statusCode == 409) {
1053
					showAlert("Error",
1054
							"Folder must be empty in order to delete");
1055
				}
1056
				if (statusCode == 201) {
1057
					new DeleteObjectTask().execute(arguments);
1058
				} else {
1059
					CloudServersException cse = parseCloudServersException(response);
1060
					if ("".equals(cse.getMessage())) {
1061
						showError("There was a problem deleting your folder.",
1062
								bundle);
1063
					} else {
1064
						showError("There was a problem deleting your folder: "
1065
								+ cse.getMessage(), bundle);
1066
					}
1067
				}
1068
			} else if (exception != null) {
1069
				showError("There was a problem deleting your folder: "
1070
						+ exception.getMessage(), bundle);
1071
			}
1072
		}
1073
	}
911 1074

  
912 1075
	private class DeleteContainerTask extends
913 1076
			AsyncTask<String, Void, HttpBundle> {

Also available in: Unified diff