Ejemplo n.º 1
0
  @Override
  public void onCommentMarkAsFavoriteClicked(Comment comment, boolean markAsFavorite) {
    Observable<Void> result;
    if (markAsFavorite) {
      result =
          favedCommentService.save(
              ImmutableFavedComment.builder()
                  .id(comment.getId())
                  .name(comment.getName())
                  .content(comment.getContent())
                  .created(comment.getCreated())
                  .up(comment.getUp())
                  .down(comment.getDown())
                  .mark(comment.getMark())
                  .thumb(feedItem.getThumb())
                  .itemId(feedItem.getId())
                  .flags(feedItem.getFlags())
                  .build());
    } else {
      result = favedCommentService.delete(comment.getId());
    }

    result
        .compose(bindUntilEvent(FragmentEvent.DESTROY_VIEW))
        .subscribe(Actions.empty(), defaultOnError());

    if (singleShotService.isFirstTime("kfav-userscript-hint")) {
      DialogBuilder.start(getContext())
          .content(R.string.hint_kfav_userscript)
          .positive(
              R.string.open_website,
              di -> {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://goo.gl/py7xNW"));
                getContext().startActivity(intent);
              })
          .negative(R.string.ignore)
          .show();
    }
  }
Ejemplo n.º 2
0
  private void appendChildComments(
      List<Comment> target, ListMultimap<Long, Comment> byParent, long id, String op) {

    Ordering<Comment> ordering = COMMENT_BY_CONFIDENCE;
    if (op != null && prioritizeOpComments) {
      ordering =
          Ordering.natural()
              .reverse()
              .onResultOf((Comment c) -> op.equalsIgnoreCase(c.getName()))
              .compound(ordering);
    }

    List<Comment> children = ordering.sortedCopy(byParent.get(id));
    for (Comment child : children) {
      target.add(child);
      appendChildComments(target, byParent, (int) child.getId(), op);
    }
  }
Ejemplo n.º 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);
      }
    }
  }