示例#1
0
  /** Synchronize with server when data changes */
  public void pushUpdateOnSave(Update update, ContentValues values) {
    if (!values.containsKey(Update.MESSAGE.name)) return;

    ArrayList<Object> params = new ArrayList<Object>();
    params.add("message");
    params.add(update.getValue(Update.MESSAGE));

    if (update.getValue(Update.TAG) > 0) {
      TagData tagData = tagDataService.fetchById(update.getValue(Update.TAG), TagData.REMOTE_ID);
      if (tagData == null || tagData.getValue(TagData.REMOTE_ID) == 0) return;
      params.add("tag_id");
      params.add(tagData.getValue(TagData.REMOTE_ID));
    }

    if (update.getValue(Update.TASK) > 0) {
      params.add("task_id");
      params.add(update.getValue(Update.TASK));
    }
    if (!checkForToken()) return;

    try {
      params.add("token");
      params.add(token);
      JSONObject result =
          actFmInvoker.invoke("comment_add", params.toArray(new Object[params.size()]));
      update.setValue(Update.REMOTE_ID, result.optLong("id"));
      updateDao.saveExisting(update);
    } catch (IOException e) {
      handleException("task-save", e);
    }
  }
示例#2
0
  private void addComment() {
    Update update = new Update();
    update.setValue(Update.MESSAGE, addCommentField.getText().toString());
    update.setValue(Update.ACTION_CODE, "tag_comment"); // $NON-NLS-1$
    update.setValue(Update.USER_ID, 0L);
    update.setValue(Update.TAG, tagData.getId());
    update.setValue(Update.CREATION_DATE, DateUtilities.now());
    Flags.checkAndClear(Flags.SUPPRESS_SYNC);
    updateDao.createNew(update);

    addCommentField.setText(""); // $NON-NLS-1$
    refreshUpdatesList();
  }
示例#3
0
  public void initialize() {
    taskDao.addListener(
        new ModelUpdateListener<Task>() {
          @Override
          public void onModelUpdated(final Task model) {
            if (Flags.checkAndClear(Flags.SUPPRESS_SYNC)) return;
            final ContentValues setValues = model.getSetValues();
            if (setValues == null
                || !checkForToken()
                || setValues.containsKey(RemoteModel.REMOTE_ID_PROPERTY_NAME)) return;

            new Thread(
                    new Runnable() {
                      @Override
                      public void run() {
                        // sleep so metadata associated with task is saved
                        AndroidUtilities.sleepDeep(1000L);
                        pushTaskOnSave(model, setValues);
                      }
                    })
                .start();
          }
        });

    updateDao.addListener(
        new ModelUpdateListener<Update>() {
          @Override
          public void onModelUpdated(final Update model) {
            if (Flags.checkAndClear(Flags.SUPPRESS_SYNC)) return;
            final ContentValues setValues = model.getSetValues();
            if (setValues == null || !checkForToken() || model.getValue(Update.REMOTE_ID) > 0)
              return;

            new Thread(
                    new Runnable() {
                      @Override
                      public void run() {
                        pushUpdateOnSave(model, setValues);
                      }
                    })
                .start();
          }
        });

    tagDataDao.addListener(
        new ModelUpdateListener<TagData>() {
          @Override
          public void onModelUpdated(final TagData model) {
            if (Flags.checkAndClear(Flags.SUPPRESS_SYNC)) return;
            final ContentValues setValues = model.getSetValues();
            if (setValues == null
                || !checkForToken()
                || setValues.containsKey(RemoteModel.REMOTE_ID_PROPERTY_NAME)) return;

            new Thread(
                    new Runnable() {
                      @Override
                      public void run() {
                        pushTagDataOnSave(model, setValues);
                      }
                    })
                .start();
          }
        });
  }