Search in sources :

Example 1 with ReactionsModel

use of com.fastaccess.data.dao.ReactionsModel in project FastHub by k0shk0sh.

the class ReactionsProvider method isPreviouslyReacted.

public boolean isPreviouslyReacted(long idOrNumber, @IdRes int vId) {
    ReactionsModel reactionsModel = getReactionsMap().get(idOrNumber);
    if (reactionsModel == null || InputHelper.isEmpty(reactionsModel.getContent())) {
        return false;
    }
    ReactionTypes type = ReactionTypes.get(vId);
    return type != null && type.getContent().equals(reactionsModel.getContent());
}
Also used : ReactionTypes(com.fastaccess.data.dao.types.ReactionTypes) ReactionsModel(com.fastaccess.data.dao.ReactionsModel)

Example 2 with ReactionsModel

use of com.fastaccess.data.dao.ReactionsModel in project FastHub by k0shk0sh.

the class ReviewCommentsViewHolder method addReactionCount.

private void addReactionCount(View v) {
    if (adapter != null) {
        ReviewCommentModel comment = (ReviewCommentModel) adapter.getItem(getAdapterPosition());
        if (comment != null) {
            boolean isReacted = reactionsCallback == null || reactionsCallback.isPreviouslyReacted(comment.getId(), v.getId());
            ReactionsModel reactionsModel = comment.getReactions() != null ? comment.getReactions() : new ReactionsModel();
            switch(v.getId()) {
                case R.id.heart:
                case R.id.heartReaction:
                    reactionsModel.setHeart(!isReacted ? reactionsModel.getHeart() + 1 : reactionsModel.getHeart() - 1);
                    break;
                case R.id.sad:
                case R.id.sadReaction:
                    reactionsModel.setConfused(!isReacted ? reactionsModel.getConfused() + 1 : reactionsModel.getConfused() - 1);
                    break;
                case R.id.thumbsDown:
                case R.id.thumbsDownReaction:
                    reactionsModel.setMinusOne(!isReacted ? reactionsModel.getMinusOne() + 1 : reactionsModel.getMinusOne() - 1);
                    break;
                case R.id.thumbsUp:
                case R.id.thumbsUpReaction:
                    reactionsModel.setPlusOne(!isReacted ? reactionsModel.getPlusOne() + 1 : reactionsModel.getPlusOne() - 1);
                    break;
                case R.id.laugh:
                case R.id.laughReaction:
                    reactionsModel.setLaugh(!isReacted ? reactionsModel.getLaugh() + 1 : reactionsModel.getLaugh() - 1);
                    break;
                case R.id.hurray:
                case R.id.hurrayReaction:
                    reactionsModel.setHooray(!isReacted ? reactionsModel.getHooray() + 1 : reactionsModel.getHooray() - 1);
                    break;
            }
            comment.setReactions(reactionsModel);
            appendEmojies(reactionsModel);
        }
    }
}
Also used : ReviewCommentModel(com.fastaccess.data.dao.ReviewCommentModel) ReactionsModel(com.fastaccess.data.dao.ReactionsModel)

Example 3 with ReactionsModel

use of com.fastaccess.data.dao.ReactionsModel in project FastHub by k0shk0sh.

the class ReviewCommentsViewHolder method bind.

@Override
public void bind(@NonNull ReviewCommentModel commentModel) {
    if (commentModel.getUser() != null) {
        avatarView.setUrl(commentModel.getUser().getAvatarUrl(), commentModel.getUser().getLogin(), commentModel.getUser().isOrganizationType(), LinkParserHelper.isEnterprise(commentModel.getHtmlUrl()));
        name.setText(commentModel.getUser().getLogin());
        if (commentModel.getAuthorAssociation() != null && !"none".equalsIgnoreCase(commentModel.getAuthorAssociation())) {
            owner.setText(commentModel.getAuthorAssociation().toLowerCase());
            owner.setVisibility(View.VISIBLE);
        } else {
            boolean isRepoOwner = TextUtils.equals(commentModel.getUser().getLogin(), repoOwner);
            if (isRepoOwner) {
                owner.setVisibility(View.VISIBLE);
                owner.setText(R.string.owner);
            } else {
                boolean isPoster = TextUtils.equals(commentModel.getUser().getLogin(), poster);
                if (isPoster) {
                    owner.setVisibility(View.VISIBLE);
                    owner.setText(R.string.original_poster);
                } else {
                    owner.setText("");
                    owner.setVisibility(View.GONE);
                }
            }
        }
    }
    date.setText(ParseDateFormat.getTimeAgo(commentModel.getCreatedAt()));
    if (!InputHelper.isEmpty(commentModel.getBodyHtml())) {
        int width = adapter != null ? adapter.getRowWidth() : 0;
        HtmlHelper.htmlIntoTextView(comment, commentModel.getBodyHtml(), width > 0 ? width : viewGroup.getWidth());
    } else {
        comment.setText("");
    }
    if (commentModel.getReactions() != null) {
        ReactionsModel reaction = commentModel.getReactions();
        appendEmojies(reaction);
    }
    if (onToggleView != null)
        onToggle(onToggleView.isCollapsed(getId()), false);
}
Also used : ReactionsModel(com.fastaccess.data.dao.ReactionsModel)

Example 4 with ReactionsModel

use of com.fastaccess.data.dao.ReactionsModel in project FastHub by k0shk0sh.

the class TimelineCommentsViewHolder method bind.

@Override
public void bind(@NonNull TimelineModel timelineModel) {
    Comment commentsModel = timelineModel.getComment();
    if (commentsModel.getUser() != null) {
        avatar.setUrl(commentsModel.getUser().getAvatarUrl(), commentsModel.getUser().getLogin(), false, LinkParserHelper.isEnterprise(commentsModel.getHtmlUrl()));
        name.setText(commentsModel.getUser() != null ? commentsModel.getUser().getLogin() : "Anonymous");
        if (commentsModel.getAuthorAssociation() != null && !"none".equalsIgnoreCase(commentsModel.getAuthorAssociation())) {
            owner.setText(commentsModel.getAuthorAssociation().toLowerCase());
            owner.setVisibility(View.VISIBLE);
        } else {
            boolean isRepoOwner = TextUtils.equals(commentsModel.getUser().getLogin(), repoOwner);
            if (isRepoOwner) {
                owner.setVisibility(View.VISIBLE);
                owner.setText(R.string.owner);
            } else {
                boolean isPoster = TextUtils.equals(commentsModel.getUser().getLogin(), poster);
                if (isPoster) {
                    owner.setVisibility(View.VISIBLE);
                    owner.setText(R.string.original_poster);
                } else {
                    owner.setText("");
                    owner.setVisibility(View.GONE);
                }
            }
        }
    } else {
        avatar.setUrl(null, null, false, false);
        name.setText("");
    }
    if (!InputHelper.isEmpty(commentsModel.getPath()) && commentsModel.getPosition() > 0) {
        pathText.setVisibility(View.VISIBLE);
        pathText.setText(String.format("Commented on %s#L%s", commentsModel.getPath(), commentsModel.getLine() > 0 ? commentsModel.getLine() : commentsModel.getPosition()));
    } else {
        pathText.setText("");
        pathText.setVisibility(View.GONE);
    }
    if (!InputHelper.isEmpty(commentsModel.getBodyHtml())) {
        String body = commentsModel.getBodyHtml();
        int width = adapter != null ? adapter.getRowWidth() : 0;
        HtmlHelper.htmlIntoTextView(comment, body, width > 0 ? width : viewGroup.getWidth());
    } else {
        comment.setText("");
    }
    if (commentsModel.getCreatedAt().before(commentsModel.getUpdatedAt())) {
        date.setText(String.format("%s %s", ParseDateFormat.getTimeAgo(commentsModel.getCreatedAt()), itemView.getResources().getString(R.string.edited)));
    } else {
        date.setText(ParseDateFormat.getTimeAgo(commentsModel.getCreatedAt()));
    }
    if (showEmojies) {
        if (commentsModel.getReactions() != null) {
            ReactionsModel reaction = commentsModel.getReactions();
            appendEmojies(reaction);
        }
    }
    emojiesList.setVisibility(showEmojies ? View.VISIBLE : View.GONE);
    if (onToggleView != null)
        onToggle(onToggleView.isCollapsed(getAdapterPosition()), false);
}
Also used : Comment(com.fastaccess.data.dao.model.Comment) ReactionsModel(com.fastaccess.data.dao.ReactionsModel)

Example 5 with ReactionsModel

use of com.fastaccess.data.dao.ReactionsModel in project FastHub by k0shk0sh.

the class TimelineCommentsViewHolder method addReactionCount.

private void addReactionCount(View v) {
    if (adapter != null) {
        TimelineModel timelineModel = (TimelineModel) adapter.getItem(getAdapterPosition());
        if (timelineModel == null)
            return;
        Comment comment = timelineModel.getComment();
        if (comment != null) {
            boolean isReacted = reactionsCallback == null || reactionsCallback.isPreviouslyReacted(comment.getId(), v.getId());
            boolean isCallingApi = reactionsCallback != null && reactionsCallback.isCallingApi(comment.getId(), v.getId());
            // if (isCallingApi) return;
            ReactionsModel reactionsModel = comment.getReactions() != null ? comment.getReactions() : new ReactionsModel();
            switch(v.getId()) {
                case R.id.heart:
                case R.id.heartReaction:
                    reactionsModel.setHeart(!isReacted ? reactionsModel.getHeart() + 1 : reactionsModel.getHeart() - 1);
                    break;
                case R.id.sad:
                case R.id.sadReaction:
                    reactionsModel.setConfused(!isReacted ? reactionsModel.getConfused() + 1 : reactionsModel.getConfused() - 1);
                    break;
                case R.id.thumbsDown:
                case R.id.thumbsDownReaction:
                    reactionsModel.setMinusOne(!isReacted ? reactionsModel.getMinusOne() + 1 : reactionsModel.getMinusOne() - 1);
                    break;
                case R.id.thumbsUp:
                case R.id.thumbsUpReaction:
                    reactionsModel.setPlusOne(!isReacted ? reactionsModel.getPlusOne() + 1 : reactionsModel.getPlusOne() - 1);
                    break;
                case R.id.laugh:
                case R.id.laughReaction:
                    reactionsModel.setLaugh(!isReacted ? reactionsModel.getLaugh() + 1 : reactionsModel.getLaugh() - 1);
                    break;
                case R.id.hurray:
                case R.id.hurrayReaction:
                    reactionsModel.setHooray(!isReacted ? reactionsModel.getHooray() + 1 : reactionsModel.getHooray() - 1);
                    break;
            }
            comment.setReactions(reactionsModel);
            appendEmojies(reactionsModel);
            timelineModel.setComment(comment);
        }
    }
}
Also used : Comment(com.fastaccess.data.dao.model.Comment) ReactionsModel(com.fastaccess.data.dao.ReactionsModel) TimelineModel(com.fastaccess.data.dao.TimelineModel)

Aggregations

ReactionsModel (com.fastaccess.data.dao.ReactionsModel)7 TimelineModel (com.fastaccess.data.dao.TimelineModel)2 Comment (com.fastaccess.data.dao.model.Comment)2 ReactionTypes (com.fastaccess.data.dao.types.ReactionTypes)2 ReviewCommentModel (com.fastaccess.data.dao.ReviewCommentModel)1 Issue (com.fastaccess.data.dao.model.Issue)1 PullRequest (com.fastaccess.data.dao.model.PullRequest)1