Search in sources :

Example 6 with PullsIssuesParser

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

the class IssuesViewHolder method bind.

@Override
public void bind(@NonNull Issue issueModel) {
    title.setText(issueModel.getTitle());
    if (issueModel.getState() != null) {
        CharSequence data = ParseDateFormat.getTimeAgo(issueModel.getState() == IssueState.open ? issueModel.getCreatedAt() : issueModel.getClosedAt());
        SpannableBuilder builder = SpannableBuilder.builder();
        if (showRepoName) {
            PullsIssuesParser parser = PullsIssuesParser.getForIssue(issueModel.getHtmlUrl());
            if (parser != null)
                builder.bold(parser.getLogin()).append("/").bold(parser.getRepoId()).bold("#").bold(String.valueOf(issueModel.getNumber())).append(" ").append(" ");
        }
        if (!showRepoName) {
            if (issueModel.getState() == IssueState.closed) {
                if (issueModel.getClosedBy() == null) {
                    builder.bold("#").bold(String.valueOf(issueModel.getNumber())).append(" ").append(" ");
                } else {
                    builder.append("#").append(String.valueOf(issueModel.getNumber())).append(" ").append(issueModel.getClosedBy().getLogin()).append(" ");
                }
            } else {
                builder.bold("#").bold(String.valueOf(issueModel.getNumber())).append(" ").append(issueModel.getUser().getLogin()).append(" ");
            }
        }
        details.setText(builder.append(itemView.getResources().getString(issueModel.getState().getStatus()).toLowerCase()).append(" ").append(data));
        if (issueModel.getComments() > 0) {
            commentsNo.setText(String.valueOf(issueModel.getComments()));
            commentsNo.setVisibility(View.VISIBLE);
        } else {
            commentsNo.setVisibility(View.GONE);
        }
    }
    if (showState) {
        issueState.setVisibility(View.VISIBLE);
        issueState.setImageResource(issueModel.getState() == IssueState.open ? R.drawable.ic_issue_opened_small : R.drawable.ic_issue_closed_small);
    } else {
        issueState.setVisibility(View.GONE);
    }
    if (withAvatar && avatarLayout != null) {
        avatarLayout.setUrl(issueModel.getUser().getAvatarUrl(), issueModel.getUser().getLogin(), false, LinkParserHelper.isEnterprise(issueModel.getUser().getHtmlUrl()));
        avatarLayout.setVisibility(View.VISIBLE);
    }
}
Also used : SpannableBuilder(com.fastaccess.ui.widgets.SpannableBuilder) PullsIssuesParser(com.fastaccess.data.dao.PullsIssuesParser)

Aggregations

PullsIssuesParser (com.fastaccess.data.dao.PullsIssuesParser)6 Login (com.fastaccess.data.dao.model.Login)2 User (com.fastaccess.data.dao.model.User)2 SpannableBuilder (com.fastaccess.ui.widgets.SpannableBuilder)2 NonNull (android.support.annotation.NonNull)1