Search in sources :

Example 6 with ReactionsModel

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

the class IssueDetailsViewHolder method addReactionCount.

private void addReactionCount(View v) {
    if (adapter != null) {
        TimelineModel timelineModel = (TimelineModel) adapter.getItem(getAdapterPosition());
        if (timelineModel == null)
            return;
        ReactionsModel reactionsModel = null;
        PullRequest pullRequest = timelineModel.getPullRequest();
        Issue issue = timelineModel.getIssue();
        int number = 0;
        if (pullRequest != null) {
            reactionsModel = pullRequest.getReactions();
            number = pullRequest.getNumber();
        } else if (issue != null) {
            reactionsModel = issue.getReactions();
            number = issue.getNumber();
        }
        if (reactionsModel == null)
            reactionsModel = new ReactionsModel();
        boolean isReacted = reactionsCallback == null || reactionsCallback.isPreviouslyReacted(number, v.getId());
        boolean isCallingApi = reactionsCallback != null && reactionsCallback.isCallingApi(number, v.getId());
        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;
        }
        if (pullRequest != null) {
            pullRequest.setReactions(reactionsModel);
            appendEmojies(reactionsModel);
            timelineModel.setPullRequest(pullRequest);
        } else if (issue != null) {
            issue.setReactions(reactionsModel);
            appendEmojies(reactionsModel);
            timelineModel.setIssue(issue);
        }
    }
}
Also used : Issue(com.fastaccess.data.dao.model.Issue) PullRequest(com.fastaccess.data.dao.model.PullRequest) ReactionsModel(com.fastaccess.data.dao.ReactionsModel) TimelineModel(com.fastaccess.data.dao.TimelineModel)

Example 7 with ReactionsModel

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

the class ReactionsProvider method isCallingApi.

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

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