Example #1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    ThemeService.applyTheme(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tag_updates_activity);

    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayShowTitleEnabled(false);

    actionBar.setDisplayShowCustomEnabled(true);
    actionBar.setCustomView(R.layout.header_title_view);
    ((TextView) actionBar.getCustomView().findViewById(R.id.title))
        .setText(R.string.TAd_contextEditTask);

    Fragment fragment;
    String tag;
    if (getIntent().getExtras().containsKey(TaskCommentsFragment.EXTRA_TASK)) {
      fragment = new TaskCommentsFragment();
      tag = "taskupdates_fragment"; // $NON-NLS-1$
    } else {
      fragment = new TagCommentsFragment();
      tag = "tagupdates_fragment"; // $NON-NLS-1$
    }

    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    transaction.add(R.id.comments_fragment_container, fragment, tag);
    transaction.commit();
  }
Example #2
0
 @Override
 public void runOnSuccess() {
   synchronized (this) {
     if (activity != null) {
       activity.runOnUiThread(
           new Runnable() {
             @Override
             public void run() {
               if (task == null) return;
               fetchTask(task.getId());
               if (task == null) return;
               setUpListAdapter();
               loadingText.setText(R.string.ENA_no_comments);
               loadingText.setVisibility(items.size() == 0 ? View.VISIBLE : View.GONE);
             }
           });
     }
   }
 }
Example #3
0
  @SuppressWarnings("nls")
  private void addComment(
      String message, String actionCode, String uuid, String title, boolean usePicture) {
    // Allow for users to just add picture
    if (TextUtils.isEmpty(message) && usePicture) {
      message = " ";
    }
    UserActivity userActivity = new UserActivity();
    userActivity.setValue(UserActivity.MESSAGE, message);
    userActivity.setValue(UserActivity.ACTION, actionCode);
    userActivity.setValue(UserActivity.USER_UUID, Task.USER_ID_SELF);
    userActivity.setValue(UserActivity.TARGET_ID, uuid);
    userActivity.setValue(UserActivity.TARGET_NAME, title);
    userActivity.setValue(UserActivity.CREATED_AT, DateUtilities.now());
    if (usePicture && pendingCommentPicture != null) {
      JSONObject pictureJson =
          RemoteModel.PictureHelper.savePictureJson(activity, pendingCommentPicture);
      if (pictureJson != null) userActivity.setValue(UserActivity.PICTURE, pictureJson.toString());
    }

    userActivityDao.createNew(userActivity);
    if (commentField != null) commentField.setText(""); // $NON-NLS-1$

    pendingCommentPicture = usePicture ? null : pendingCommentPicture;
    if (usePicture) {
      if (activity != null)
        activity.getIntent().removeExtra(TaskEditFragment.TOKEN_PICTURE_IN_PROGRESS);
    }
    if (pictureButton != null) pictureButton.setImageResource(cameraButton);
    StatisticsService.reportEvent(StatisticsConstants.ACTFM_TASK_COMMENT);

    setUpListAdapter();
    for (UpdatesChangedListener l : listeners) {
      l.commentAdded();
    }
  }
Example #4
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;
  }
Example #5
0
  public static Spanned getUpdateComment(
      final AstridActivity context,
      UserActivity activity,
      User user,
      String linkColor,
      String fromView) {
    String userDisplay;
    if (activity.getValue(UserActivity.USER_UUID).equals(Task.USER_ID_SELF)) {
      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);
    }
    if (TextUtils.isEmpty(userDisplay)) userDisplay = context.getString(R.string.ENA_no_user);
    String targetName = activity.getValue(UserActivity.TARGET_NAME);
    String action = activity.getValue(UserActivity.ACTION);
    String message = activity.getValue(UserActivity.MESSAGE);

    int commentResource = 0;
    if (UserActivity.ACTION_TASK_COMMENT.equals(action)) {
      if (fromView.equals(FROM_TASK_VIEW) || TextUtils.isEmpty(targetName))
        commentResource = R.string.update_string_default_comment;
      else commentResource = R.string.update_string_task_comment;
    } else if (UserActivity.ACTION_TAG_COMMENT.equals(action)) {
      if (fromView.equals(FROM_TAG_VIEW) || TextUtils.isEmpty(targetName))
        commentResource = R.string.update_string_default_comment;
      else commentResource = R.string.update_string_tag_comment;
    }

    if (commentResource == 0)
      return Html.fromHtml(String.format("%s %s", userDisplay, message)); // $NON-NLS-1$

    String original = context.getString(commentResource, userDisplay, targetName, message);
    int taskLinkIndex = original.indexOf(TARGET_LINK_PREFIX);

    if (taskLinkIndex < 0) return Html.fromHtml(original);

    String[] components = original.split(" "); // $NON-NLS-1$
    SpannableStringBuilder builder = new SpannableStringBuilder();
    StringBuilder htmlStringBuilder = new StringBuilder();

    for (String comp : components) {
      Matcher m = TARGET_LINK_PATTERN.matcher(comp);
      if (m.find()) {
        builder.append(Html.fromHtml(htmlStringBuilder.toString()));
        htmlStringBuilder.setLength(0);

        String linkType = m.group(1);
        CharSequence link = getLinkSpan(context, activity, targetName, linkColor, linkType);
        if (link != null) {
          builder.append(link);
          if (!m.hitEnd()) {
            builder.append(comp.substring(m.end()));
          }
          builder.append(' ');
        }
      } else {
        htmlStringBuilder.append(comp);
        htmlStringBuilder.append(' ');
      }
    }

    if (htmlStringBuilder.length() > 0) builder.append(Html.fromHtml(htmlStringBuilder.toString()));

    return builder;
  }
Example #6
0
 @Override
 public void finish() {
   super.finish();
   AndroidUtilities.callOverridePendingTransition(
       this, R.anim.slide_right_in, R.anim.slide_right_out);
 }
Example #7
0
  private void setUpListAdapter() {
    items.clear();
    this.removeAllViews();
    historyCount = 0;
    TodorooCursor<Metadata> notes =
        metadataService.query(
            Query.select(Metadata.PROPERTIES)
                .where(MetadataCriteria.byTaskAndwithKey(task.getId(), NoteMetadata.METADATA_KEY)));
    try {
      Metadata metadata = new Metadata();
      for (notes.moveToFirst(); !notes.isAfterLast(); notes.moveToNext()) {
        metadata.readFromCursor(notes);
        items.add(NoteOrUpdate.fromMetadata(metadata));
      }
    } finally {
      notes.close();
    }

    User self = UpdateAdapter.getSelfUser();

    TodorooCursor<UserActivity> updates = taskService.getActivityAndHistoryForTask(task);
    try {
      UserActivity update = new UserActivity();
      History history = new History();
      User user = new User();
      for (updates.moveToFirst(); !updates.isAfterLast(); updates.moveToNext()) {
        update.clear();
        user.clear();

        String type = updates.getString(UpdateAdapter.TYPE_PROPERTY_INDEX);
        NoteOrUpdate noa;
        boolean isSelf;
        if (NameMaps.TABLE_ID_USER_ACTIVITY.equals(type)) {
          UpdateAdapter.readUserActivityProperties(updates, update);
          isSelf = Task.USER_ID_SELF.equals(update.getValue(UserActivity.USER_UUID));
          UpdateAdapter.readUserProperties(updates, user, self, isSelf);
          noa = NoteOrUpdate.fromUpdateOrHistory(activity, update, null, user, linkColor);
        } else {
          UpdateAdapter.readHistoryProperties(updates, history);
          isSelf = Task.USER_ID_SELF.equals(history.getValue(History.USER_UUID));
          UpdateAdapter.readUserProperties(updates, user, self, isSelf);
          noa = NoteOrUpdate.fromUpdateOrHistory(activity, null, history, user, linkColor);
          historyCount++;
        }
        if (noa != null) items.add(noa);
      }
    } finally {
      updates.close();
    }

    Collections.sort(
        items,
        new Comparator<NoteOrUpdate>() {
          @Override
          public int compare(NoteOrUpdate a, NoteOrUpdate b) {
            if (a.createdAt < b.createdAt) return 1;
            else if (a.createdAt == b.createdAt) return 0;
            else return -1;
          }
        });

    for (int i = 0; i < Math.min(items.size(), commentItems); i++) {
      View notesView = this.getUpdateNotes(items.get(i), this);
      this.addView(notesView);
    }

    if (items.size() > commentItems || task.getValue(Task.HISTORY_HAS_MORE) > 0) {
      Button loadMore = new Button(getContext());
      loadMore.setText(R.string.TEA_load_more);
      loadMore.setTextColor(activity.getResources().getColor(R.color.task_edit_deadline_gray));
      loadMore.setBackgroundColor(Color.alpha(0));
      loadMore.setOnClickListener(
          new View.OnClickListener() {
            public void onClick(View v) {
              // Perform action on click
              commentItems += 10;
              setUpListAdapter();
              if (task.getValue(Task.HISTORY_HAS_MORE) > 0)
                new FetchHistory<Task>(
                        taskDao,
                        Task.HISTORY_FETCH_DATE,
                        Task.HISTORY_HAS_MORE,
                        NameMaps.TABLE_ID_TASKS,
                        task.getUuid(),
                        task.getValue(Task.TITLE),
                        0,
                        historyCount,
                        callback)
                    .execute();
            }
          });
      this.addView(loadMore);
    } else if (items.size() == 0) {
      TextView noUpdates = new TextView(getContext());
      noUpdates.setText(R.string.TEA_no_activity);
      noUpdates.setTextColor(activity.getResources().getColor(R.color.task_edit_deadline_gray));
      noUpdates.setLayoutParams(
          new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
      noUpdates.setPadding(10, 10, 10, 10);
      noUpdates.setGravity(Gravity.CENTER);
      noUpdates.setTextSize(16);
      this.addView(noUpdates);
    }

    for (UpdatesChangedListener l : listeners) {
      l.updatesChanged();
    }
  }
Example #8
0
  private void setUpInterface() {
    timerView = commentsBar.findViewById(R.id.timer_container);
    commentButton = commentsBar.findViewById(R.id.commentButton);
    commentField = (EditText) commentsBar.findViewById(R.id.commentField);

    final boolean showTimerShortcut = Preferences.getBoolean(R.string.p_show_timer_shortcut, false);

    if (showTimerShortcut) {
      commentField.setOnFocusChangeListener(
          new OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
              if (hasFocus) {
                timerView.setVisibility(View.GONE);
                commentButton.setVisibility(View.VISIBLE);
              } else {
                timerView.setVisibility(View.VISIBLE);
                commentButton.setVisibility(View.GONE);
              }
            }
          });
    } else {
      timerView.setVisibility(View.GONE);
    }

    commentField.addTextChangedListener(
        new TextWatcher() {
          @Override
          public void afterTextChanged(Editable s) {
            commentButton.setVisibility(
                (s.length() > 0 || pendingCommentPicture != null) ? View.VISIBLE : View.GONE);
            if (showTimerShortcut)
              timerView.setVisibility(
                  (s.length() > 0 || pendingCommentPicture != null) ? View.GONE : View.VISIBLE);
          }

          @Override
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            //
          }

          @Override
          public void onTextChanged(CharSequence s, int start, int before, int count) {
            //
          }
        });

    commentField.setOnEditorActionListener(
        new OnEditorActionListener() {
          @Override
          public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_NULL && commentField.getText().length() > 0) {
              addComment();
              return true;
            }
            return false;
          }
        });
    commentButton.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            addComment();
          }
        });

    final ClearImageCallback clearImage =
        new ClearImageCallback() {
          @Override
          public void clearImage() {
            pendingCommentPicture = null;
            pictureButton.setImageResource(cameraButton);
          }
        };
    pictureButton = (ImageButton) commentsBar.findViewById(R.id.picture);
    pictureButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            if (pendingCommentPicture != null)
              ActFmCameraModule.showPictureLauncher(fragment, clearImage);
            else ActFmCameraModule.showPictureLauncher(fragment, null);
            respondToPicture = true;
          }
        });
    if (!TextUtils.isEmpty(task.getValue(Task.NOTES))) {
      TextView notes = new TextView(getContext());
      notes.setLinkTextColor(Color.rgb(100, 160, 255));
      notes.setTextSize(18);
      notes.setText(task.getValue(Task.NOTES));
      notes.setPadding(5, 10, 5, 10);
      Linkify.addLinks(notes, Linkify.ALL);
    }

    if (activity != null) {
      Bitmap bitmap =
          activity.getIntent().getParcelableExtra(TaskEditFragment.TOKEN_PICTURE_IN_PROGRESS);
      if (bitmap != null) {
        pendingCommentPicture = bitmap;
        pictureButton.setImageBitmap(pendingCommentPicture);
      }
    }

    // TODO add loading text back in
    //        loadingText = (TextView) findViewById(R.id.loading);
    loadingText = new TextView(getContext());
  }