예제 #1
0
  private CommentView createCommentView(Comment comment) {

    CommentView commentView = new CommentView(comment);
    CommentController controller = new CommentController(comment, commentView);
    commentView.setController(controller);
    return commentView;
  }
 public View getView(int position, View convertView, ViewGroup parent) {
   // TODO
   CommentView cv = null;
   if (convertView == null) {
     convertView = mInflater.inflate(R.layout.comments_item, null);
     cv = new CommentView();
     cv.txtContent = (TextView) convertView.findViewById(R.id.txtContent);
     cv.txtGenTime = (TextView) convertView.findViewById(R.id.txtGenTime);
     cv.txtUName = (TextView) convertView.findViewById(R.id.txtUName);
     convertView.setTag(cv);
   } else {
     cv = (CommentView) convertView.getTag();
   }
   NewsComment nc = (NewsComment) getItem(position);
   cv.txtContent.setText(nc.getContent());
   cv.txtGenTime.setText(nc.getGen_time().toLocaleString());
   cv.txtUName.setText(nc.getUser_id() + "");
   return convertView;
 }
예제 #3
0
  @Override
  public void onBindViewHolder(CommentView view, int position) {
    CommentEntry entry = comments.get(position);
    Comment comment = entry.comment;

    view.setCommentDepth(entry.depth);
    view.senderInfo.setSenderName(comment.getName(), comment.getMark());
    view.senderInfo.setOnSenderClickedListener(v -> doOnAuthorClicked(comment));

    AndroidUtility.linkify(view.comment, comment.getContent());

    // show the points
    if (equalsIgnoreCase(comment.getName(), selfName)
        || comment.getCreated().isBefore(scoreVisibleThreshold)) {

      view.senderInfo.setPoints(getCommentScore(entry));
    } else {
      view.senderInfo.setPointsUnknown();
    }

    // and the date of the post
    view.senderInfo.setDate(comment.getCreated());

    // enable or disable the badge
    boolean badge = op.transform(op -> op.equalsIgnoreCase(comment.getName())).or(false);
    view.senderInfo.setBadgeOpVisible(badge);

    // and register a vote handler
    view.vote.setVote(entry.vote, true);
    view.vote.setOnVoteListener(
        v -> {
          boolean changed = doVote(entry, v);
          notifyItemChanged(position);
          return changed;
        });

    // set alpha for the sub views. sadly, setting alpha on view.itemView is not working
    view.comment.setAlpha(entry.vote == Vote.DOWN ? 0.5f : 1f);
    view.senderInfo.setAlpha(entry.vote == Vote.DOWN ? 0.5f : 1f);

    view.senderInfo.setOnAnswerClickedListener(v -> doAnswer(comment));

    Context context = view.itemView.getContext();
    view.itemView.setBackgroundColor(
        ContextCompat.getColor(
            context,
            comment.getId() == selectedCommentId
                ? R.color.selected_comment_background
                : R.color.feed_background));

    if (view.kFav != null) {
      if (showFavCommentButton) {
        boolean isFavorite = favedComments.contains(comment.getId());

        view.kFav.setTextColor(
            isFavorite
                ? ContextCompat.getColor(context, R.color.primary)
                : ContextCompat.getColor(context, R.color.grey_700));

        view.kFav.setVisibility(View.VISIBLE);
        view.kFav.setOnClickListener(
            v -> {
              commentActionListener.onCommentMarkAsFavoriteClicked(comment, !isFavorite);
            });
      } else {
        view.kFav.setVisibility(View.GONE);
      }
    }
  }