コード例 #1
0
ファイル: TagViewActivity.java プロジェクト: ghy/astrid
  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();
  }
コード例 #2
0
ファイル: TaskListFragment.java プロジェクト: kflux/tasks
  @Override
  public void onResume() {
    super.onResume();

    getActivity()
        .registerReceiver(
            refreshReceiver, new IntentFilter(AstridApiConstants.BROADCAST_EVENT_REFRESH));

    if (Flags.checkAndClear(Flags.REFRESH)) {
      refresh();
    }

    setUpBackgroundJobs();

    refreshFilterCount();

    initiateAutomaticSync();
  }
コード例 #3
0
ファイル: TaskListFragment.java プロジェクト: junekai/astrid
  @Override
  public void onResume() {
    super.onResume();

    getActivity()
        .registerReceiver(
            detailReceiver, new IntentFilter(AstridApiConstants.BROADCAST_SEND_DETAILS));
    getActivity()
        .registerReceiver(
            detailReceiver, new IntentFilter(AstridApiConstants.BROADCAST_SEND_DECORATIONS));
    getActivity()
        .registerReceiver(
            refreshReceiver, new IntentFilter(AstridApiConstants.BROADCAST_EVENT_REFRESH));
    syncActionHelper.register();

    if (Flags.checkAndClear(Flags.REFRESH)) {
      refresh();
    }

    setUpBackgroundJobs();

    if (!Preferences.getBoolean(WelcomeWalkthrough.KEY_SHOWED_WELCOME_LOGIN, false)) {
      Preferences.setBoolean(WelcomeWalkthrough.KEY_SHOWED_WELCOME_LOGIN, true);
      Intent showWelcomeLogin = new Intent(getActivity(), WelcomeWalkthrough.class);
      showWelcomeLogin.putExtra(ActFmLoginActivity.SHOW_TOAST, false);
      startActivity(showWelcomeLogin);
      return;
    }

    if (!Preferences.getBoolean(R.string.p_showed_add_task_help, false)) {
      showTaskCreateHelpPopover();
    } else if (!Preferences.getBoolean(R.string.p_showed_tap_task_help, false)) {
      showTaskEditHelpPopover();
    } else if (!Preferences.getBoolean(R.string.p_showed_lists_help, false)) {
      showListsHelp();
    }
    refreshFilterCount();
    initiateAutomaticSync();
  }
コード例 #4
0
ファイル: ActFmSyncService.java プロジェクト: ghy/astrid
  /**
   * Send tagData changes to server
   *
   * @param setValues
   */
  public void pushTagDataOnSave(TagData tagData, ContentValues values) {
    long remoteId;
    if (tagData.containsValue(TagData.REMOTE_ID)) remoteId = tagData.getValue(TagData.REMOTE_ID);
    else {
      TagData forRemote = tagDataService.fetchById(tagData.getId(), TagData.REMOTE_ID);
      if (forRemote == null) return;
      remoteId = forRemote.getValue(TagData.REMOTE_ID);
    }
    boolean newlyCreated = remoteId == 0;

    ArrayList<Object> params = new ArrayList<Object>();

    if (values.containsKey(TagData.NAME.name)) {
      params.add("name");
      params.add(tagData.getValue(TagData.NAME));
    }

    if (values.containsKey(TagData.MEMBERS.name)) {
      params.add("members");
      try {
        JSONArray members = new JSONArray(tagData.getValue(TagData.MEMBERS));
        if (members.length() == 0) params.add("");
        else {
          ArrayList<Object> array = new ArrayList<Object>(members.length());
          for (int i = 0; i < members.length(); i++) {
            JSONObject person = members.getJSONObject(i);
            if (person.has("id")) array.add(person.getLong("id"));
            else {
              if (person.has("name"))
                array.add(person.getString("name") + " <" + person.getString("email") + ">");
              else array.add(person.getString("email"));
            }
          }
          params.add(array);
        }
      } catch (JSONException e) {
        throw new RuntimeException(e);
      }
    }

    if (params.size() == 0 || !checkForToken()) return;

    if (!newlyCreated) {
      params.add("id");
      params.add(remoteId);
    }

    boolean success;
    try {
      params.add("token");
      params.add(token);
      JSONObject result =
          actFmInvoker.invoke("tag_save", params.toArray(new Object[params.size()]));
      if (newlyCreated) {
        tagData.setValue(TagData.REMOTE_ID, result.optLong("id"));
        Flags.set(Flags.SUPPRESS_SYNC);
        tagDataDao.saveExisting(tagData);
      }
      success = true;
    } catch (IOException e) {
      handleException("tag-save", e);
      success = false;
    }
    if (!Flags.checkAndClear(Flags.TOAST_ON_SAVE)) return;

    final boolean finalSuccess = success;
    Handler handler = new Handler(Looper.getMainLooper());
    handler.post(
        new Runnable() {
          @Override
          public void run() {
            if (finalSuccess)
              Toast.makeText(
                      ContextManager.getContext(), R.string.actfm_toast_success, Toast.LENGTH_LONG)
                  .show();
            else
              Toast.makeText(
                      ContextManager.getContext(), R.string.actfm_toast_error, Toast.LENGTH_LONG)
                  .show();
          }
        });
  }
コード例 #5
0
ファイル: ActFmSyncService.java プロジェクト: ghy/astrid
  /** Synchronize with server when data changes */
  public void pushTaskOnSave(Task task, ContentValues values) {
    long remoteId;
    if (task.containsValue(Task.REMOTE_ID)) remoteId = task.getValue(Task.REMOTE_ID);
    else {
      Task taskForRemote = taskService.fetchById(task.getId(), Task.REMOTE_ID);
      if (taskForRemote == null) return;
      remoteId = taskForRemote.getValue(Task.REMOTE_ID);
    }
    boolean newlyCreated = remoteId == 0;

    ArrayList<Object> params = new ArrayList<Object>();

    if (values.containsKey(Task.TITLE.name)) {
      params.add("title");
      params.add(task.getValue(Task.TITLE));
    }
    if (values.containsKey(Task.DUE_DATE.name)) {
      params.add("due");
      params.add(task.getValue(Task.DUE_DATE) / 1000L);
      params.add("has_due_time");
      params.add(task.hasDueTime() ? 1 : 0);
    }
    if (values.containsKey(Task.NOTES.name)) {
      params.add("notes");
      params.add(task.getValue(Task.NOTES));
    }
    if (values.containsKey(Task.DELETION_DATE.name)) {
      params.add("deleted_at");
      params.add(task.getValue(Task.DELETION_DATE) / 1000L);
    }
    if (values.containsKey(Task.COMPLETION_DATE.name)) {
      params.add("completed");
      params.add(task.getValue(Task.COMPLETION_DATE) / 1000L);
    }
    if (values.containsKey(Task.IMPORTANCE.name)) {
      params.add("importance");
      params.add(task.getValue(Task.IMPORTANCE));
    }
    if (values.containsKey(Task.RECURRENCE.name)) {
      params.add("repeat");
      params.add(task.getValue(Task.RECURRENCE));
    }
    if (values.containsKey(Task.USER_ID.name) && task.getValue(Task.USER_ID) >= 0) {
      params.add("user_id");
      if (task.getValue(Task.USER_ID) == 0) params.add(ActFmPreferenceService.userId());
      else params.add(task.getValue(Task.USER_ID));
    }
    if (Flags.checkAndClear(Flags.TAGS_CHANGED) || newlyCreated) {
      TodorooCursor<Metadata> cursor = TagService.getInstance().getTags(task.getId());
      try {
        if (cursor.getCount() == 0) {
          params.add("tags");
          params.add("");
        } else {
          Metadata metadata = new Metadata();
          for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
            metadata.readFromCursor(cursor);
            if (metadata.containsNonNullValue(TagService.REMOTE_ID)
                && metadata.getValue(TagService.REMOTE_ID) > 0) {
              params.add("tag_ids[]");
              params.add(metadata.getValue(TagService.REMOTE_ID));
            } else {
              params.add("tags[]");
              params.add(metadata.getValue(TagService.TAG));
            }
          }
        }
      } finally {
        cursor.close();
      }
    }

    if (params.size() == 0 || !checkForToken()) return;

    System.err.println("PUSHN ON SAVE: " + task.getMergedValues());
    System.err.println("SETVALUES: " + values);

    if (!newlyCreated) {
      params.add("id");
      params.add(remoteId);
    } else if (!params.contains(Task.TITLE.name)) return;

    try {
      params.add("token");
      params.add(token);
      JSONObject result =
          actFmInvoker.invoke("task_save", params.toArray(new Object[params.size()]));
      ArrayList<Metadata> metadata = new ArrayList<Metadata>();
      JsonHelper.taskFromJson(result, task, metadata);
      task.setValue(Task.MODIFICATION_DATE, DateUtilities.now());
      task.setValue(Task.LAST_SYNC, DateUtilities.now());
      Flags.set(Flags.SUPPRESS_SYNC);
      taskDao.saveExisting(task);
    } catch (JSONException e) {
      handleException("task-save-json", e);
    } catch (IOException e) {
      handleException("task-save-io", e);
    }
  }