+
+ Builder b;
+
+ // New event/instance - Set Organizer's response as yes
+ if (eventIdIndex != -1) {
+ values.clear();
+ int calendarCursorPosition = mCalendarsSpinner.getSelectedItemPosition();
+ if (mCalendarsCursor.moveToPosition(calendarCursorPosition)) {
+ String ownerEmail = mCalendarsCursor.getString(CALENDARS_INDEX_OWNER_ACCOUNT);
+ if (ownerEmail != null) {
+ String displayName = mCalendarsCursor.getString(CALENDARS_INDEX_DISPLAY_NAME);
+ if (displayName != null) {
+ values.put(Attendees.ATTENDEE_NAME, displayName);
+ }
+ values.put(Attendees.ATTENDEE_EMAIL, ownerEmail);
+ values.put(Attendees.ATTENDEE_RELATIONSHIP, Attendees.RELATIONSHIP_ORGANIZER);
+ values.put(Attendees.ATTENDEE_TYPE, Attendees.TYPE_NONE);
+ values.put(Attendees.ATTENDEE_STATUS, Attendees.ATTENDEE_STATUS_ACCEPTED);
+
+ b = ContentProviderOperation.newInsert(Attendees.CONTENT_URI)
+ .withValues(values);
+ b.withValueBackReference(Reminders.EVENT_ID, eventIdIndex);
+ ops.add(b.build());
+ }
+ }
+ }
+
+ if (eventIdIndex != -1 || uri != null) {
+ Editable attendeesText = mAttendeesList.getText();
+ // Hit the content provider only if the user has changed it
+ if (!mOriginalAttendees.equals(attendeesText.toString())) {
+ // TODO we could do a diff and modify the rows only as needed
+ // Delete all the existing attendees for this event
+ b = ContentProviderOperation.newDelete(Attendees.CONTENT_URI);
+
+ long eventId = -1;
+ if (eventIdIndex == -1) {
+ eventId = ContentUris.parseId(uri);
+ String[] args = new String[] {
+ Long.toString(eventId)
+ };
+ b.withSelection(ATTENDEES_WHERE, args);
+ } else {
+ // Delete all the existing reminders for this event
+ b.withSelection(ATTENDEES_WHERE, new String[1]);
+ b.withSelectionBackReference(0, eventIdIndex);
+ }
+ ops.add(b.build());
+
+ if (attendeesText.length() > 0) {
+ Rfc822Token[] attendees = getAddressesFromList(mAttendeesList);
+ // Insert the attendees
+ for (Rfc822Token attendee : attendees) {
+ values.clear();
+ values.put(Attendees.ATTENDEE_NAME, attendee.getName());
+ values.put(Attendees.ATTENDEE_EMAIL, attendee.getAddress());
+ values.put(Attendees.ATTENDEE_RELATIONSHIP, Attendees.RELATIONSHIP_ATTENDEE);
+ values.put(Attendees.ATTENDEE_TYPE, Attendees.TYPE_NONE);
+ values.put(Attendees.ATTENDEE_STATUS, Attendees.ATTENDEE_STATUS_NONE);
+
+ if (eventIdIndex != -1) {
+ b = ContentProviderOperation.newInsert(Attendees.CONTENT_URI)
+ .withValues(values);
+ b.withValueBackReference(Reminders.EVENT_ID, eventIdIndex);
+ } else {
+ values.put(Attendees.EVENT_ID, eventId);
+ b = ContentProviderOperation.newInsert(Attendees.CONTENT_URI)
+ .withValues(values);
+ }
+ ops.add(b.build());
+ }
+ }
+ }
+ }
+
+ try {
+ // TODO Move this to background thread
+ ContentProviderResult[] results =
+ getContentResolver().applyBatch(android.provider.Calendar.AUTHORITY, ops);
+ if (DEBUG) {
+ for (int i = 0; i < results.length; i++) {
+ Log.v(TAG, "results = " + results[i].toString());
+ }
+ }
+ } catch (RemoteException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (OperationApplicationException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+