Revision 98604824 src/com/rackspace/cloud/android/PithosGroupsActivity.java

b/src/com/rackspace/cloud/android/PithosGroupsActivity.java
6 6

  
7 7
import android.app.Activity;
8 8
import android.app.AlertDialog;
9
import android.app.ExpandableListActivity;
9 10
import android.content.Context;
10 11
import android.content.DialogInterface;
11 12
import android.graphics.Color;
......
20 21
import android.view.View;
21 22
import android.widget.AutoCompleteTextView;
22 23
import android.widget.EditText;
24
import android.widget.ExpandableListView;
23 25
import android.widget.ExpandableListView.ExpandableListContextMenuInfo;
24 26

  
25 27
import com.google.android.apps.analytics.GoogleAnalyticsTracker;
......
81 83
		return false;
82 84
	}
83 85
	
86
	
87
	
84 88
	@Override
85 89
	public void onCreateContextMenu(ContextMenu menu, View v,
86 90
			ContextMenuInfo menuInfo) {
87 91
		super.onCreateContextMenu(menu, v, menuInfo);
88
		GroupsListView groupsList = ((GroupsListView) findViewById(R.id.groupsListView));
89
		int position = (int) ((ExpandableListContextMenuInfo)menuInfo).id;
90
		final Object entry = groupsList.getAdapter().getItem(position);
91
		Log.i("Groups", position + " entry class:"+entry.getClass());
92
		if(entry instanceof GroupResource){
93
			menu.add(1, 1, 2, "Add User");
92
		ExpandableListView.ExpandableListContextMenuInfo info =
93
				(ExpandableListView.ExpandableListContextMenuInfo) menuInfo;
94
		int type = ExpandableListView.getPackedPositionType(info.packedPosition);
95
		if(type==1)
94 96
			menu.add(1, 2, 3, "Delete");
95
		}
96
		else if(entry instanceof String){
97
		else{
98
			menu.add(1, 1, 2, "Add User");
97 99
			menu.add(1, 2, 3, "Delete");
98 100
		}
99
		
100
		/*
101
		 * AdapterView.AdapterContextMenuInfo info =
102
		 * (AdapterView.AdapterContextMenuInfo) menuInfo; GssFileListAdapter
103
		 * adapt = (GssFileListAdapter) ((GssFileListView)
104
		 * findViewById(R.id.fileListView)) .getAdapter(); final
105
		 * GssFileListAdapterEntry entry = adapt.getItem(info.position); //
106
		 * if(entry.file instanceof FolderResource)
107
		 */
108

  
109 101
	}
110 102
	
111 103
	@Override
112 104
	public boolean onContextItemSelected(MenuItem item) {
113 105
		final ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) item
114 106
				.getMenuInfo();
107
		int groupPos = 0, childPos = 0;
108
		int type = ExpandableListView.getPackedPositionType(info.packedPosition);
109
		final GroupResource group;
110
		final String user;
111
		final GroupsListView groupsList = ((GroupsListView) findViewById(R.id.groupsListView));
112
		if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
113
			groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition);
114
			childPos = ExpandableListView.getPackedPositionChild(info.packedPosition);
115
			group = (GroupResource) groupsList.getGroupsAdapter().getGroup(groupPos);
116
			user = (String) groupsList.getGroupsAdapter().getChild(groupPos, childPos);
117
			
118
		}
119
		else if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
120
			groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition);
121
			group = (GroupResource) groupsList.getGroupsAdapter().getGroup(groupPos);
122
			user=null;
123
		}
124
		else{
125
			group = null;
126
			user = null;
127
		}
128
		Log.i("GROUPS","****************************");
129
		Log.i("GROUPS","group:"+groupPos+" child:"+childPos);
130
		Log.i("GROUPS","****************************");
131
		
115 132
		AlertDialog alertDialog = null;
116
		GroupsListView groupsList = ((GroupsListView) findViewById(R.id.groupsListView));
117
		int position = (int) ((ExpandableListContextMenuInfo)info).id;
118
		final Object entry = groupsList.getAdapter().getItem(position);
119 133
		switch (item.getItemId()) {
120 134
		// case R.id.new_folder:
121 135
		// new
122 136
		// NewFolderDialog(GssClient.this,GssClient.this,(FolderResource)currentResource).show();
123 137
		// return true;
124 138
		case 2:
139
			final boolean isUser = user !=null;
125 140
			alertDialog = new AlertDialog.Builder(this).create();
126
			alertDialog.setTitle("Delete Group");
127
			alertDialog
128
					.setMessage("R u sure you want to delete this group and all its users?");
141
			if(isUser){
142
				alertDialog.setTitle("Delete User");
143
				alertDialog
144
						.setMessage("R u sure you want to delete this user?"+user);
145
			}
146
			else{
147
				alertDialog.setTitle("Delete Group");
148
				alertDialog
149
						.setMessage("R u sure you want to delete this group and all its users?"+group.getName());
150
			}
129 151
			alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
130 152
				public void onClick(DialogInterface dialog, int which) {
131 153
					HttpBundle bundel;
132 154
					try {
133 155
						Map<String,String> headers = new HashMap<String,String>();
134
	    				headers.put("X-Account-Group-"+((GroupResource)entry).getName(), "~");
156
						if(isUser){
157
							//groupsList.get
158
							//int gp = (int) groupsList.getGroupsAdapter().getCombinedGroupId(combinedpos);
159
							//Log.i("Groups","Position "+gp+" "+groupsList.getAdapter().getItem(gp));
160
							group.getUsers().remove(user);
161
							headers.put("X-Account-Group-"+group.getName(), group.getUserString());
162
						}
163
						else{
164
							headers.put("X-Account-Group-"+group.getName(), "~");
165
						}
135 166
						bundel = new ContainerObjectManager(getApplicationContext()).updateObject(null, null, null, "application/json", headers);
136
						Log.d("papala",bundel.getResponse().getStatusLine().getStatusCode()+" status");
167
						//Log.d("papala",bundel.getResponse().getStatusLine().getStatusCode()+" status");
168
						if(false)
169
							throw new CloudServersException();
137 170
						refresh();
138 171
					} catch (CloudServersException e) {
139 172
						// TODO Auto-generated catch block
......
161 194
    			public void onClick(DialogInterface dialog, int whichButton) {
162 195
    				String value = input.getText().toString().trim();
163 196
    				Map<String,String> headers = new HashMap<String,String>();
164
    				GroupResource gres  = (GroupResource)entry;
165
    				headers.put("X-Account-Group-"+gres.getName(), gres.getUserString()+value);
197
    				
198
    				headers.put("X-Account-Group-"+group.getName(), group.getUserString()+value);
166 199
    				HttpBundle bundel;
167 200
					try {
168 201
						bundel = new ContainerObjectManager(getApplicationContext()).updateObject(null, null, null, "application/json", headers);

Also available in: Unified diff