Exemple #1
0
  public void delete(Task item) {
    if (!item.isSaved()) {
      return;
    }

    if (item.containsValue(Task.TITLE) && item.getTitle().length() == 0) {
      taskDao.delete(item.getId());
      item.setId(Task.NO_ID);
    } else {
      long id = item.getId();
      item.clear();
      item.setId(id);
      gcalHelper.deleteTaskEvent(item);
      item.setDeletionDate(DateUtilities.now());
      taskService.save(item);
    }
  }
  public Uri createTaskEvent(
      Task task, ContentResolver cr, ContentValues values, boolean deleteEventIfExists) {
    String eventuri = getTaskEventUri(task);

    if (!TextUtils.isEmpty(eventuri) && deleteEventIfExists) {
      deleteTaskEvent(task);
    }

    try {
      Uri uri = getCalendarContentUri(Calendars.CALENDAR_CONTENT_EVENTS);
      values.put("title", task.getTitle());
      values.put("description", task.getNotes());
      values.put("hasAlarm", 0);
      if (preIceCreamSandwich()) {
        values.put("transparency", 0);
        values.put("visibility", 0);
      }
      boolean valuesContainCalendarId =
          (values.containsKey(CALENDAR_ID_COLUMN)
              && !TextUtils.isEmpty(values.getAsString(CALENDAR_ID_COLUMN)));
      if (!valuesContainCalendarId) {
        String calendarId = preferences.getDefaultCalendar();
        if (!TextUtils.isEmpty(calendarId)) {
          values.put("calendar_id", calendarId);
        }
      }

      createStartAndEndDate(task, values);

      Uri eventUri = cr.insert(uri, values);
      cr.notifyChange(eventUri, null);

      return eventUri;

    } catch (Exception e) {
      // won't work on emulator
      log.error(e.getMessage(), e);
    }

    return null;
  }