Beispiel #1
0
  @SuppressWarnings("nls")
  private static String userDisplay(Context context, String historyUserId, JSONObject userJson) {
    try {
      String id = userJson.getString("id");
      String name = userJson.getString("name");

      if (historyUserId.equals(id) && ActFmPreferenceService.userId().equals(id))
        return context.getString(R.string.history_yourself);
      else if (ActFmPreferenceService.userId().equals(id))
        return context.getString(R.string.history_you);
      else if (RemoteModel.isValidUuid(id)) return name;
      else return context.getString(R.string.history_a_deleted_user);
    } catch (JSONException e) {
      return context.getString(R.string.ENA_no_user).toLowerCase();
    }
  }
 public static Filter getAssignedByMeFilter(Resources r) {
   int themeFlags = ThemeService.getFilterThemeFlags();
   Filter f =
       new Filter(
           r.getString(R.string.BFE_Assigned),
           r.getString(R.string.BFE_Assigned),
           new QueryTemplate()
               .join(
                   Join.left(
                       Metadata.TABLE,
                       Criterion.and(
                           Metadata.KEY.eq(TaskRabbitMetadata.METADATA_KEY),
                           Task.ID.eq(Metadata.TASK))))
               .where(
                   Criterion.and(
                       TaskCriteria.isActive(),
                       Criterion.or(
                           Task.CREATOR_ID.eq(0),
                           Task.CREATOR_ID.eq(ActFmPreferenceService.userId())),
                       Criterion.or(Task.USER_ID.neq(0), TaskRabbitMetadata.ID.gt(0)))),
           null);
   f.listingIcon =
       ((BitmapDrawable)
               r.getDrawable(ThemeService.getDrawable(R.drawable.filter_assigned, themeFlags)))
           .getBitmap();
   return f;
 }
Beispiel #3
0
 public static void readUser(
     JSONObject user, AbstractModel model, LongProperty idProperty, StringProperty userProperty)
     throws JSONException {
   long id = user.getLong("id");
   if (id == ActFmPreferenceService.userId()) {
     model.setValue(idProperty, 0L);
     if (userProperty != null) model.setValue(userProperty, "");
   } else {
     model.setValue(idProperty, id);
     if (userProperty != null) model.setValue(userProperty, user.toString());
   }
 }
 private static void populateUser() {
   try {
     user.put("name", Preferences.getStringValue(PREF_NAME));
     user.put("first_name", Preferences.getStringValue(PREF_FIRST_NAME));
     user.put("last_name", Preferences.getStringValue(PREF_LAST_NAME));
     user.put("premium", isPremiumUser());
     user.put("email", Preferences.getStringValue(PREF_EMAIL));
     user.put("picture", Preferences.getStringValue(PREF_PICTURE));
     user.put("id", ActFmPreferenceService.userId());
   } catch (JSONException e) {
     throw new RuntimeException(e);
   }
 }
Beispiel #5
0
  @SuppressWarnings("nls")
  private void refreshMembersPage() {
    tagName.setText(tagData.getValue(TagData.NAME));
    picture.setUrl(tagData.getValue(TagData.PICTURE));

    TextView ownerLabel = (TextView) findViewById(R.id.tag_owner);
    try {
      if (tagData.getFlag(TagData.FLAGS, TagData.FLAG_EMERGENT)) {
        ownerLabel.setText(String.format("<%s>", getString(R.string.actfm_TVA_tag_owner_none)));
      } else if (tagData.getValue(TagData.USER_ID) == 0) {
        ownerLabel.setText(Preferences.getStringValue(ActFmPreferenceService.PREF_NAME));
      } else {
        JSONObject owner = new JSONObject(tagData.getValue(TagData.USER));
        ownerLabel.setText(owner.getString("name"));
      }
    } catch (JSONException e) {
      Log.e("tag-view-activity", "json error refresh owner", e);
      ownerLabel.setText("<error>");
      System.err.println(tagData.getValue(TagData.USER));
    }

    tagMembers.removeAllViews();
    String peopleJson = tagData.getValue(TagData.MEMBERS);
    if (!TextUtils.isEmpty(peopleJson)) {
      try {
        JSONArray people = new JSONArray(peopleJson);
        for (int i = 0; i < people.length(); i++) {
          JSONObject person = people.getJSONObject(i);
          TextView textView = null;

          if (person.has("id") && person.getLong("id") == ActFmPreferenceService.userId())
            textView =
                tagMembers.addPerson(Preferences.getStringValue(ActFmPreferenceService.PREF_NAME));
          else if (!TextUtils.isEmpty(person.optString("name")))
            textView = tagMembers.addPerson(person.getString("name"));
          else if (!TextUtils.isEmpty(person.optString("email")))
            textView = tagMembers.addPerson(person.getString("email"));

          if (textView != null) {
            textView.setTag(person);
            textView.setEnabled(false);
          }
        }
      } catch (JSONException e) {
        System.err.println(peopleJson);
        Log.e("tag-view-activity", "json error refresh members", e);
      }
    }

    tagMembers.addPerson(""); // $NON-NLS-1$
  }
Beispiel #6
0
  @SuppressWarnings("nls")
  public static String getHistoryComment(
      final AstridActivity context, History history, User user, String linkColor, String fromView) {
    boolean hasTask = false;
    JSONArray taskAttrs = null;
    if (!TextUtils.isEmpty(history.getValue(History.TASK))) {
      try {
        taskAttrs = new JSONArray(history.getValue(History.TASK));
        hasTask = true;
      } catch (JSONException e) {
        //
      }
    }

    String item;
    String itemPosessive;
    if (FROM_TASK_VIEW.equals(fromView)) {
      item = context.getString(R.string.history_this_task);
    } else if (hasTask && taskAttrs != null) {
      item = taskAttrs.optString(1);
    } else {
      item = context.getString(R.string.history_this_list);
    }
    itemPosessive = item + "'s";

    String oldValue = history.getValue(History.OLD_VALUE);
    String newValue = history.getValue(History.NEW_VALUE);

    String result = "";
    String column = history.getValue(History.COLUMN);
    try {
      if (History.COL_TAG_ADDED.equals(column) || History.COL_TAG_REMOVED.equals(column)) {
        JSONArray tagObj = new JSONArray(newValue);
        String tagName = tagObj.getString(1);
        if (History.COL_TAG_ADDED.equals(column))
          result = context.getString(R.string.history_tag_added, item, tagName);
        else result = context.getString(R.string.history_tag_removed, item, tagName);

      } else if (History.COL_ATTACHMENT_ADDED.equals(column)
          || History.COL_ATTACHMENT_REMOVED.equals(column)) {
        JSONArray attachmentArray = new JSONArray(newValue);
        String attachmentName = attachmentArray.getString(0);
        if (History.COL_ATTACHMENT_ADDED.equals(column))
          result = context.getString(R.string.history_attach_added, attachmentName, item);
        else result = context.getString(R.string.history_attach_removed, attachmentName, item);
      } else if (History.COL_ACKNOWLEDGED.equals(column)) {
        result = context.getString(R.string.history_acknowledged, item);
      } else if (History.COL_SHARED_WITH.equals(column)
          || History.COL_UNSHARED_WITH.equals(column)) {
        JSONArray members = new JSONArray(newValue);
        String userId = history.getValue(History.USER_UUID);
        StringBuilder memberList = new StringBuilder();
        for (int i = 0; i < members.length(); i++) {
          JSONObject m = members.getJSONObject(i);
          memberList.append(userDisplay(context, userId, m));
          if (i != members.length() - 1) memberList.append(", ");
        }

        if (History.COL_SHARED_WITH.equals(column))
          result = context.getString(R.string.history_shared_with, item, memberList);
        else result = context.getString(R.string.history_unshared_with, item, memberList);
      } else if (History.COL_MEMBER_ADDED.equals(column)
          || History.COL_MEMBER_REMOVED.equals(column)) {
        JSONObject userValue = new JSONObject(newValue);
        if (history.getValue(History.USER_UUID).equals(userValue.optString("id"))
            && History.COL_MEMBER_REMOVED.equals(column))
          result = context.getString(R.string.history_left_list, item);
        else {
          String userDisplay = userDisplay(context, history.getValue(History.USER_UUID), userValue);
          if (History.COL_MEMBER_ADDED.equals(column))
            result = context.getString(R.string.history_added_user, userDisplay, item);
          else result = context.getString(R.string.history_removed_user, userDisplay, item);
        }
      } else if (History.COL_COMPLETED_AT.equals(column)) {
        if (!TextUtils.isEmpty(newValue) && !"null".equals(newValue)) {
          result = context.getString(R.string.history_completed, item);
        } else {
          result = context.getString(R.string.history_uncompleted, item);
        }
      } else if (History.COL_DELETED_AT.equals(column)) {
        if (!TextUtils.isEmpty(newValue) && !"null".equals(newValue)) {
          result = context.getString(R.string.history_deleted, item);
        } else {
          result = context.getString(R.string.history_undeleted, item);
        }
      } else if (History.COL_IMPORTANCE.equals(column)) {
        int oldPriority = AndroidUtilities.tryParseInt(oldValue, 0);
        int newPriority = AndroidUtilities.tryParseInt(newValue, 0);

        result =
            context.getString(
                R.string.history_importance_changed,
                itemPosessive,
                priorityString(oldPriority),
                priorityString(newPriority));
      } else if (History.COL_NOTES_LENGTH.equals(column)) {
        int oldLength = AndroidUtilities.tryParseInt(oldValue, 0);
        int newLength = AndroidUtilities.tryParseInt(newValue, 0);

        if (oldLength > 0 && newLength > oldLength)
          result =
              context.getString(
                  R.string.history_added_description_characters,
                  (newLength - oldLength),
                  itemPosessive);
        else if (newLength == 0)
          result = context.getString(R.string.history_removed_description, itemPosessive);
        else if (oldLength > 0 && newLength < oldLength)
          result =
              context.getString(
                  R.string.history_removed_description_characters,
                  (oldLength - newLength),
                  itemPosessive);
        else if (oldLength > 0 && oldLength == newLength)
          result = context.getString(R.string.history_updated_description, itemPosessive);
      } else if (History.COL_PUBLIC.equals(column)) {
        int value = AndroidUtilities.tryParseInt(newValue, 0);
        if (value > 0) result = context.getString(R.string.history_made_public, item);
        else result = context.getString(R.string.history_made_private, item);
      } else if (History.COL_DUE.equals(column)) {
        if (!TextUtils.isEmpty(oldValue)
            && !TextUtils.isEmpty(newValue)
            && !"null".equals(oldValue)
            && !"null".equals(newValue))
          result =
              context.getString(
                  R.string.history_changed_due_date,
                  itemPosessive,
                  dateString(context, oldValue, newValue),
                  dateString(context, newValue, oldValue));
        else if (!TextUtils.isEmpty(newValue) && !"null".equals(newValue))
          result =
              context.getString(
                  R.string.history_set_due_date,
                  itemPosessive,
                  dateString(
                      context, newValue, DateUtilities.timeToIso8601(DateUtilities.now(), true)));
        else result = context.getString(R.string.history_removed_due_date, itemPosessive);
      } else if (History.COL_REPEAT.equals(column)) {
        String repeatString = getRepeatString(context, newValue);
        if (!TextUtils.isEmpty(repeatString))
          result = context.getString(R.string.history_changed_repeat, itemPosessive, repeatString);
        else result = context.getString(R.string.history_removed_repeat, itemPosessive);
      } else if (History.COL_TASK_REPEATED.equals(column)) {
        result =
            context.getString(
                R.string.history_completed_repeating_task,
                item,
                dateString(context, newValue, oldValue));
      } else if (History.COL_TITLE.equals(column)) {
        if (!TextUtils.isEmpty(oldValue) && !"null".equals(oldValue))
          result =
              context.getString(R.string.history_title_changed, itemPosessive, oldValue, newValue);
        else result = context.getString(R.string.history_title_set, itemPosessive, newValue);
      } else if (History.COL_NAME.equals(column)) {
        if (!TextUtils.isEmpty(oldValue) && !"null".equals(oldValue))
          result = context.getString(R.string.history_name_changed, oldValue, newValue);
        else result = context.getString(R.string.history_name_set, newValue);
      } else if (History.COL_DESCRIPTION.equals(column)) {
        if (!TextUtils.isEmpty(oldValue) && !"null".equals(oldValue))
          result = context.getString(R.string.history_description_changed, oldValue, newValue);
        else result = context.getString(R.string.history_description_set, newValue);
      } else if (History.COL_PICTURE_ID.equals(column)
          || History.COL_DEFAULT_LIST_IMAGE_ID.equals(column)) {
        result = context.getString(R.string.history_changed_list_picture);
      } else if (History.COL_IS_SILENT.equals(column)) {
        int value = AndroidUtilities.tryParseInt(newValue, 0);
        if (value > 0) result = context.getString(R.string.history_silenced, item);
        else result = context.getString(R.string.history_unsilenced, item);
      } else if (History.COL_IS_FAVORITE.equals(column)) {
        int value = AndroidUtilities.tryParseInt(newValue, 0);
        if (value > 0) result = context.getString(R.string.history_favorited, item);
        else result = context.getString(R.string.history_unfavorited, item);
      } else if (History.COL_USER_ID.equals(column)) {
        String userId = history.getValue(History.USER_UUID);
        JSONObject userValue = new JSONObject(newValue);
        if (FROM_TAG_VIEW.equals(fromView) && !hasTask) {
          if (!TextUtils.isEmpty(oldValue) && !"null".equals(oldValue))
            result =
                context.getString(
                    R.string.history_changed_list_owner, userDisplay(context, userId, userValue));
          else result = context.getString(R.string.history_created_this_list);
        } else if (!TextUtils.isEmpty(oldValue)
            && !"null".equals(oldValue)
            && Task.USER_ID_UNASSIGNED.equals(userValue))
          result = context.getString(R.string.history_unassigned, item);
        else if (Task.USER_ID_UNASSIGNED.equals(oldValue)
            && userValue.optString("id").equals(ActFmPreferenceService.userId()))
          result = context.getString(R.string.history_claimed, item);
        else if (!TextUtils.isEmpty(oldValue) && !"null".equals(oldValue))
          result =
              context.getString(
                  R.string.history_assigned_to, item, userDisplay(context, userId, userValue));
        else if (!userValue.optString("id").equals(ActFmPreferenceService.userId())
            && !Task.USER_ID_UNASSIGNED.equals(userValue.optString("id")))
          result =
              context.getString(
                  R.string.history_created_for, item, userDisplay(context, userId, userValue));
        else result = context.getString(R.string.history_created, item);
      } else {
        result = context.getString(R.string.history_default, column, newValue);
      }
    } catch (Exception e) {
      e.printStackTrace();
      result = context.getString(R.string.history_default, column, newValue);
    }

    if (TextUtils.isEmpty(result))
      result = context.getString(R.string.history_default, column, newValue);

    String userDisplay;
    if (history.getValue(History.USER_UUID).equals(Task.USER_ID_SELF)
        || history.getValue(History.USER_UUID).equals(ActFmPreferenceService.userId())) {
      userDisplay = context.getString(R.string.update_string_user_self);
    } else if (user == null) {
      userDisplay = context.getString(R.string.ENA_no_user);
    } else {
      userDisplay = user.getDisplayName(USER_NAME, USER_FIRST_NAME, USER_LAST_NAME);
    }

    return userDisplay + " " + result;
  }
  @SuppressWarnings("nls")
  private void buildAssignedToSpinner(ArrayList<JSONObject> sharedPeople) throws JSONException {
    HashSet<Long> userIds = new HashSet<Long>();
    HashSet<String> emails = new HashSet<String>();
    HashMap<String, AssignedToUser> names = new HashMap<String, AssignedToUser>();

    if (task.getValue(Task.USER_ID) != 0) {
      JSONObject user = new JSONObject(task.getValue(Task.USER));
      sharedPeople.add(0, user);
    }

    JSONObject myself = new JSONObject();
    myself.put("id", 0L);
    sharedPeople.add(0, myself);

    // de-duplicate by user id and/or email
    spinnerValues.clear();
    for (int i = 0; i < sharedPeople.size(); i++) {
      JSONObject person = sharedPeople.get(i);
      if (person == null) continue;
      long id = person.optLong("id", -1);
      if (id == ActFmPreferenceService.userId() || (id > -1 && userIds.contains(id))) continue;
      userIds.add(id);

      String email = person.optString("email");
      if (!TextUtils.isEmpty(email) && emails.contains(email)) continue;
      emails.add(email);

      String name = person.optString("name");
      if (id == 0) name = activity.getString(R.string.actfm_EPA_assign_me);
      AssignedToUser atu = new AssignedToUser(name, person);
      spinnerValues.add(atu);
      if (names.containsKey(name)) {
        AssignedToUser user = names.get(name);
        if (user != null && user.user.has("email")) {
          user.label += " (" + user.user.optString("email") + ")";
          names.put(name, null);
        }
        if (!TextUtils.isEmpty("email")) atu.label += " (" + email + ")";
      } else if (TextUtils.isEmpty(name)) {
        if (!TextUtils.isEmpty("email")) atu.label = email;
        else spinnerValues.remove(atu);
      } else names.put(name, atu);
    }

    spinnerValues.add(
        new AssignedToUser(activity.getString(R.string.actfm_EPA_assign_custom), null));

    String assignedStr = task.getValue(Task.USER);
    int assignedIndex = 0;
    if (!TextUtils.isEmpty(assignedStr)) {
      JSONObject assigned = new JSONObject(assignedStr);
      long assignedId = assigned.optLong("id", -1);
      String assignedEmail = assigned.optString("email");
      for (int i = 0; i < spinnerValues.size(); i++) {
        JSONObject user = spinnerValues.get(i).user;
        if (user != null) {
          if (user.optLong("id") == assignedId
              || (user.optString("email").equals(assignedEmail)
                  && !(TextUtils.isEmpty(assignedEmail)))) assignedIndex = i;
        }
      }
    }

    final int selected = assignedIndex;
    final ArrayAdapter<AssignedToUser> usersAdapter =
        new ArrayAdapter<AssignedToUser>(
            activity, android.R.layout.simple_spinner_item, spinnerValues);
    usersAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    activity.runOnUiThread(
        new Runnable() {
          @Override
          public void run() {
            assignedSpinner.setAdapter(usersAdapter);
            assignedSpinner.setSelection(selected);
          }
        });
  }
Beispiel #8
0
  /** 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);
    }
  }