private void createTaskEventIfEnabled(Task t, boolean deleteEventIfExists) { if (preferences.isDefaultCalendarSet()) { ContentResolver cr = context.getContentResolver(); Uri calendarUri = createTaskEvent(t, cr, new ContentValues(), deleteEventIfExists); if (calendarUri != null) { t.setCalendarUri(calendarUri.toString()); } } }
public void rescheduleRepeatingTask(Task task, ContentResolver cr) { String taskUri = getTaskEventUri(task); if (TextUtils.isEmpty(taskUri)) { return; } Uri eventUri = Uri.parse(taskUri); String calendarId = getCalendarId(eventUri, cr); if (calendarId == null) { // Bail out, no calendar id task.setCalendarUri(""); // $NON-NLS-1$ return; } ContentValues cv = new ContentValues(); cv.put(CALENDAR_ID_COLUMN, calendarId); Uri uri = createTaskEvent(task, cr, cv, false); task.setCalendarUri(uri.toString()); }
public boolean deleteTaskEvent(Task task) { boolean eventDeleted = false; String uri; if (task.containsNonNullValue(Task.CALENDAR_URI)) { uri = task.getCalendarURI(); } else { task = taskService.fetchById(task.getId(), Task.CALENDAR_URI); if (task == null) { return false; } uri = task.getCalendarURI(); } if (!TextUtils.isEmpty(uri)) { try { Uri calendarUri = Uri.parse(uri); // try to load calendar ContentResolver cr = context.getContentResolver(); Cursor cursor = cr.query(calendarUri, new String[] {"dtstart"}, null, null, null); // $NON-NLS-1$ try { boolean alreadydeleted = cursor.getCount() == 0; if (!alreadydeleted) { cr.delete(calendarUri, null, null); eventDeleted = true; } } finally { cursor.close(); } task.setCalendarUri(""); } catch (Exception e) { log.error(e.getMessage(), e); } } return eventDeleted; }