Exemplo n.º 1
0
  public void completeTodo(long resourceId, int action) {
    try {
      Resource r = Resource.fromDatabase(this, resourceId);
      VCalendar todoCalendarResource = (VCalendar) VComponent.createComponentFromResource(r);
      todoCalendarResource.setEditable();
      VTodo task = (VTodo) todoCalendarResource.getMasterChild();
      task.setCompleted(AcalDateTime.getInstance());
      task.setPercentComplete(100);
      todoCalendarResource.updateTimeZones();

      ResourceManager.getInstance(this)
          .sendRequest(
              new RRResourceEditedRequest(
                  new ResourceResponseListener<Long>() {
                    @Override
                    public void resourceResponse(ResourceResponse<Long> response) {}
                  },
                  r.getCollectionId(),
                  resourceId,
                  todoCalendarResource,
                  RRResourceEditedRequest.ACTION_UPDATE));

    } catch (Exception e) {
      if (e.getMessage() != null) Log.d(TAG, e.getMessage());
      if (Constants.LOG_DEBUG) Log.println(Constants.LOGD, TAG, Log.getStackTraceString(e));
      Toast.makeText(this, getString(R.string.ErrorCompletingTask), Toast.LENGTH_LONG).show();
    }
  }
Exemplo n.º 2
0
  /**
   * ************************************************** Public Methods *
   * **************************************************
   */
  public void deleteTodo(long resourceId, int action) {
    try {
      Resource r = Resource.fromDatabase(this, resourceId);

      ResourceManager.getInstance(this)
          .sendRequest(
              new RRResourceEditedRequest(
                  new ResourceResponseListener<Long>() {
                    @Override
                    public void resourceResponse(ResourceResponse<Long> response) {}
                  },
                  r.getCollectionId(),
                  resourceId,
                  VComponent.createComponentFromResource(r),
                  RRResourceEditedRequest.ACTION_DELETE));
    } catch (Exception e) {
      if (e.getMessage() != null) Log.d(TAG, e.getMessage());
      if (Constants.LOG_DEBUG) Log.println(Constants.LOGD, TAG, Log.getStackTraceString(e));
      Toast.makeText(this, getString(R.string.ErrorDeletingTask), Toast.LENGTH_LONG).show();
    }
  }
Exemplo n.º 3
0
  @Override
  public void process(ReadOnlyResourceTableManager processor) {
    ArrayList<Resource> result = new ArrayList<Resource>();
    // TODO At the moment this algorithm ignores pending resources nor does it handle floating
    // events.
    if (CacheManager.DEBUG) Log.println(Constants.LOGD, TAG, "Process Called...");
    AcalDateRange range = window.getRequestedWindow();
    if (window.getRequestedWindow() == null) {
      if (CacheManager.DEBUG)
        Log.println(Constants.LOGD, TAG, "Resource request cancelled - cache window already full");
      super.postResponse(new RREventsInRangeResponse<ArrayList<Resource>>(result));
      this.setProcessed();
      return;
    }

    // step 1 --> convert window range to long UTC start
    long start = range.start.getMillis();
    long end = range.end.getMillis();

    String whereClause =
        "("
            + ResourceTableManager.EFFECTIVE_TYPE
            + "='"
            + VComponent.VEVENT
            + "' OR "
            + ResourceTableManager.EFFECTIVE_TYPE
            + "='"
            + VComponent.VTODO
            + "' )"
            + " AND ("
            + ResourceTableManager.LATEST_END
            + " IS NULL OR "
            + ResourceTableManager.LATEST_END
            + " >= "
            + start
            + " )"
            + " AND ("
            + ResourceTableManager.EARLIEST_START
            + " IS NULL OR "
            + ResourceTableManager.EARLIEST_START
            + " <= "
            + end
            + " )";

    if (CacheManager.DEBUG)
      Log.println(Constants.LOGD, TAG, "Getting Resource rows where:\n" + whereClause);

    // step 2 query db for resources in range
    ArrayList<ContentValues> rValues = processor.query(null, whereClause, null, null);

    // also need pendings
    ArrayList<ContentValues> pValues = processor.getPendingResources();
    HashMap<Long, ContentValues> pendingMap = new HashMap<Long, ContentValues>();

    if (!pValues.isEmpty()) {
      // we need to remove from rValues, any values that have a corresponding entry in pValues
      for (ContentValues cv : pValues) {
        pendingMap.put(cv.getAsLong(ResourceTableManager.PEND_RESOURCE_ID), cv);
      }
      Iterator<ContentValues> it = rValues.iterator();
      while (it.hasNext()) {
        ContentValues rValue = it.next();
        long rid = rValue.getAsLong(ResourceTableManager.RESOURCE_ID);
        if (pendingMap.containsKey(rid)) {
          ContentValues pValue = pendingMap.get(rid);
          it.remove();
          String data = pValue.getAsString(ResourceTableManager.NEW_DATA);
          if (data == null || data.equals("")) pendingMap.remove(rid);
        }
      }
    }

    // Merge the lists
    if (CacheManager.DEBUG)
      Log.println(
          Constants.LOGD,
          TAG,
          rValues.size()
              + " Resource Rows retreived. and "
              + pValues.size()
              + " pending values. Converting into Resource Objects");
    for (Entry<Long, ContentValues> ent : pendingMap.entrySet()) {
      Resource r = Resource.fromContentValues(ent.getValue());
      r.setPending(true);
      result.add(r);
    }
    for (ContentValues cv : rValues) result.add(Resource.fromContentValues(cv));
    if (CacheManager.DEBUG)
      Log.println(
          Constants.LOGD, TAG, "Conversion complete. Populating VCalendars and appending events.");

    // post response
    super.postResponse(new RREventsInRangeResponse<ArrayList<Resource>>(result));

    this.setProcessed();
  }