示例#1
0
  public EditNoteActivity(Fragment fragment, View parent, long t) {
    super(fragment.getActivity());
    DependencyInjectionService.getInstance().inject(this);

    imageCache = AsyncImageView.getImageCache();
    this.fragment = fragment;

    this.activity = (AstridActivity) fragment.getActivity();

    this.resources = fragment.getResources();
    TypedValue tv = new TypedValue();
    fragment.getActivity().getTheme().resolveAttribute(R.attr.asTextColor, tv, false);
    color = tv.data;

    fragment.getActivity().getTheme().resolveAttribute(R.attr.asDueDateColor, tv, false);
    grayColor = tv.data;

    linkColor = UpdateAdapter.getLinkColor(fragment);

    cameraButton = getDefaultCameraButton();

    setOrientation(VERTICAL);

    commentsBar = parent.findViewById(R.id.updatesFooter);

    loadViewForTaskID(t);
  }
示例#2
0
    public static NoteOrUpdate fromUpdateOrHistory(
        AstridActivity context, UserActivity u, History history, User user, String linkColor) {
      String userImage = ""; // $NON-NLS-1$
      String pictureThumb = ""; // $NON-NLS-1$
      String pictureFull = ""; // $NON-NLS-1$
      Spanned title;
      Bitmap commentBitmap = null;
      long createdAt = 0;
      String type = null;

      if (u != null) {
        pictureThumb = u.getPictureUrl(UserActivity.PICTURE, RemoteModel.PICTURE_MEDIUM);
        pictureFull = u.getPictureUrl(UserActivity.PICTURE, RemoteModel.PICTURE_LARGE);
        if (TextUtils.isEmpty(pictureThumb))
          commentBitmap = u.getPictureBitmap(UserActivity.PICTURE);
        title =
            UpdateAdapter.getUpdateComment(
                context, u, user, linkColor, UpdateAdapter.FROM_TASK_VIEW);
        userImage = ""; // $NON-NLS-1$
        if (user.containsNonNullValue(UpdateAdapter.USER_PICTURE))
          userImage = user.getPictureUrl(UpdateAdapter.USER_PICTURE, RemoteModel.PICTURE_THUMB);
        createdAt = u.getValue(UserActivity.CREATED_AT);
        type = NameMaps.TABLE_ID_USER_ACTIVITY;
      } else {
        if (user.containsNonNullValue(UpdateAdapter.USER_PICTURE))
          userImage = user.getPictureUrl(UpdateAdapter.USER_PICTURE, RemoteModel.PICTURE_THUMB);
        title =
            new SpannableString(
                UpdateAdapter.getHistoryComment(
                    context, history, user, linkColor, UpdateAdapter.FROM_TASK_VIEW));
        createdAt = history.getValue(History.CREATED_AT);
        type = NameMaps.TABLE_ID_HISTORY;
      }

      return new NoteOrUpdate(
          userImage, title, pictureThumb, pictureFull, commentBitmap, createdAt, type);
    }
示例#3
0
  /** Helper method to set the contents and visibility of each field */
  public synchronized void bindView(View view, NoteOrUpdate item) {
    // picture
    final AsyncImageView pictureView = (AsyncImageView) view.findViewById(R.id.picture);
    {
      pictureView.setDefaultImageDrawable(
          ResourceDrawableCache.getImageDrawableFromId(
              resources, R.drawable.icn_default_person_image));
      pictureView.setUrl(item.picture);
    }

    // name
    final TextView nameView = (TextView) view.findViewById(R.id.title);
    {
      nameView.setText(item.title);
      if (NameMaps.TABLE_ID_HISTORY.equals(item.type)) nameView.setTextColor(grayColor);
      else nameView.setTextColor(color);
      Linkify.addLinks(nameView, Linkify.ALL);
    }

    // date
    final TextView date = (TextView) view.findViewById(R.id.date);
    {
      CharSequence dateString =
          DateUtils.getRelativeTimeSpanString(
              item.createdAt,
              DateUtilities.now(),
              DateUtils.MINUTE_IN_MILLIS,
              DateUtils.FORMAT_ABBREV_RELATIVE);
      date.setText(dateString);
    }

    // picture
    final AsyncImageView commentPictureView =
        (AsyncImageView) view.findViewById(R.id.comment_picture);
    {
      UpdateAdapter.setupImagePopupForCommentView(
          view,
          commentPictureView,
          item.pictureThumb,
          item.pictureFull,
          item.commentBitmap,
          item.title.toString(),
          fragment,
          imageCache);
    }
  }
示例#4
0
 private void refreshUpdatesList() {
   Cursor cursor = updateAdapter.getCursor();
   cursor.requery();
   startManagingCursor(cursor);
 }
示例#5
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();
    }
  }