Search in sources :

Example 6 with StyledText

use of com.github.pockethub.android.ui.StyledText in project PocketHub by pockethub.

the class CommitDiffListFragment method addCommitParents.

private void addCommitParents(Commit commit, LayoutInflater inflater) {
    List<Commit> parents = commit.parents();
    if (parents == null || parents.isEmpty()) {
        return;
    }
    for (Commit parent : parents) {
        View parentView = inflater.inflate(R.layout.commit_parent_item, null);
        TextView parentIdText = (TextView) parentView.findViewById(R.id.tv_commit_id);
        parentIdText.setPaintFlags(parentIdText.getPaintFlags() | UNDERLINE_TEXT_FLAG);
        StyledText parentText = new StyledText();
        parentText.append(getString(R.string.parent_prefix));
        parentText.monospace(CommitUtils.abbreviate(parent.sha()));
        parentIdText.setText(parentText);
        adapter.addHeader(parentView, parent, true);
    }
}
Also used : GitCommit(com.meisolsson.githubsdk.model.git.GitCommit) Commit(com.meisolsson.githubsdk.model.Commit) FullCommit(com.github.pockethub.android.core.commit.FullCommit) StyledText(com.github.pockethub.android.ui.StyledText) TextView(android.widget.TextView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView)

Example 7 with StyledText

use of com.github.pockethub.android.ui.StyledText in project PocketHub by pockethub.

the class CommitListAdapter method update.

@Override
protected void update(int position, Commit item) {
    setText(0, CommitUtils.abbreviate(item.sha()));
    StyledText authorText = new StyledText();
    authorText.bold(CommitUtils.getAuthor(item));
    authorText.append(' ');
    authorText.append(CommitUtils.getAuthorDate(item));
    setText(1, authorText);
    CommitUtils.bindAuthor(item, avatars, imageView(2));
    setText(3, item.commit().message());
    setText(4, CommitUtils.getCommentCount(item));
}
Also used : StyledText(com.github.pockethub.android.ui.StyledText)

Example 8 with StyledText

use of com.github.pockethub.android.ui.StyledText in project PocketHub by pockethub.

the class IssueListAdapter method updateReporter.

/**
     * Update reporter details in given text view
     *
     *
     * @param reporter
     * @param date
     * @param viewIndex
     */
protected void updateReporter(String reporter, Date date, int viewIndex) {
    StyledText reporterText = new StyledText();
    reporterText.bold(reporter);
    reporterText.append(' ');
    reporterText.append(date);
    setText(viewIndex, reporterText);
}
Also used : StyledText(com.github.pockethub.android.ui.StyledText)

Example 9 with StyledText

use of com.github.pockethub.android.ui.StyledText in project PocketHub by pockethub.

the class IssueFragment method updateHeader.

private void updateHeader(final Issue issue) {
    if (!isUsable()) {
        return;
    }
    titleText.setText(issue.title());
    String body = issue.bodyHtml();
    if (!TextUtils.isEmpty(body)) {
        bodyImageGetter.bind(bodyText, body, issue.id());
    } else {
        bodyText.setText(R.string.no_description_given);
    }
    authorText.setText(issue.user().login());
    createdDateText.setText(new StyledText().append(getString(R.string.prefix_opened)).append(issue.createdAt()));
    avatars.bind(creatorAvatar, issue.user());
    if (IssueUtils.isPullRequest(issue) && issue.pullRequest().commits() != null && issue.pullRequest().commits() > 0) {
        ViewUtils.setGone(commitsView, false);
        TextView icon = (TextView) headerView.findViewById(R.id.tv_commit_icon);
        TypefaceUtils.setOcticons(icon);
        icon.setText(ICON_COMMIT);
        String commits = getString(R.string.pull_request_commits, issue.pullRequest().commits());
        ((TextView) headerView.findViewById(R.id.tv_pull_request_commits)).setText(commits);
    } else {
        ViewUtils.setGone(commitsView, true);
    }
    boolean open = IssueState.open.equals(issue.state());
    if (!open) {
        StyledText text = new StyledText();
        text.bold(getString(R.string.closed));
        Date closedAt = issue.closedAt();
        if (closedAt != null) {
            text.append(' ').append(closedAt);
        }
        stateText.setText(text);
    }
    ViewUtils.setGone(stateText, open);
    User assignee = issue.assignee();
    if (assignee != null) {
        StyledText name = new StyledText();
        name.bold(assignee.login());
        name.append(' ').append(getString(R.string.assigned));
        assigneeText.setText(name);
        assigneeAvatar.setVisibility(VISIBLE);
        avatars.bind(assigneeAvatar, assignee);
    } else {
        assigneeAvatar.setVisibility(GONE);
        assigneeText.setText(R.string.unassigned);
    }
    List<Label> labels = issue.labels();
    if (labels != null && !labels.isEmpty()) {
        LabelDrawableSpan.setText(labelsArea, labels);
        labelsArea.setVisibility(VISIBLE);
    } else {
        labelsArea.setVisibility(GONE);
    }
    if (issue.milestone() != null) {
        Milestone milestone = issue.milestone();
        StyledText milestoneLabel = new StyledText();
        milestoneLabel.append(getString(R.string.milestone_prefix));
        milestoneLabel.append(' ');
        milestoneLabel.bold(milestone.title());
        milestoneText.setText(milestoneLabel);
        float closed = milestone.closedIssues();
        float total = closed + milestone.openIssues();
        if (total > 0) {
            ((LayoutParams) milestoneProgressArea.getLayoutParams()).weight = closed / total;
            milestoneProgressArea.setVisibility(VISIBLE);
        } else {
            milestoneProgressArea.setVisibility(GONE);
        }
        milestoneArea.setVisibility(VISIBLE);
    } else {
        milestoneArea.setVisibility(GONE);
    }
    ViewUtils.setGone(progress, true);
    ViewUtils.setGone(list, false);
    updateStateItem(issue);
}
Also used : StyledText(com.github.pockethub.android.ui.StyledText) User(com.meisolsson.githubsdk.model.User) Milestone(com.meisolsson.githubsdk.model.Milestone) Label(com.meisolsson.githubsdk.model.Label) TextView(android.widget.TextView) Date(java.util.Date)

Example 10 with StyledText

use of com.github.pockethub.android.ui.StyledText in project PocketHub by pockethub.

the class LabelDrawableSpan method setText.

private static void setText(final TextView view, final Label[] labels) {
    final Resources resources = view.getResources();
    final float paddingTop = ServiceUtils.getPixels(resources, PADDING_TOP);
    final float paddingLeft = ServiceUtils.getPixels(resources, PADDING_LEFT);
    final float paddingRight = ServiceUtils.getPixels(resources, PADDING_RIGHT);
    final float paddingBottom = ServiceUtils.getPixels(resources, PADDING_BOTTOM);
    Paint p = new Paint();
    p.setTypeface(DEFAULT_BOLD);
    p.setTextSize(view.getTextSize());
    final Rect textBounds = new Rect();
    String[] names = new String[labels.length];
    int[] nameWidths = new int[labels.length];
    int textHeight = MIN_VALUE;
    for (int i = 0; i < labels.length; i++) {
        String name = labels[i].name().toUpperCase(US);
        textBounds.setEmpty();
        p.getTextBounds(name, 0, name.length(), textBounds);
        names[i] = name;
        textHeight = Math.max(textBounds.height(), textHeight);
        nameWidths[i] = textBounds.width();
    }
    final float textSize = view.getTextSize();
    final StyledText text = new StyledText();
    for (int i = 0; i < labels.length; i++) {
        Rect bounds = new Rect();
        bounds.right = Math.round(nameWidths[i] + paddingLeft + paddingRight + 0.5F);
        bounds.bottom = Math.round(textHeight + paddingTop + paddingBottom + 0.5F);
        text.append('', new LabelDrawableSpan(resources, textSize, labels[i].color(), paddingLeft, textHeight, bounds, names[i]));
        if (i + 1 < labels.length) {
            text.append(' ');
        }
    }
    view.setText(text);
}
Also used : Rect(android.graphics.Rect) StyledText(com.github.pockethub.android.ui.StyledText) Resources(android.content.res.Resources) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Aggregations

StyledText (com.github.pockethub.android.ui.StyledText)16 TextView (android.widget.TextView)3 User (com.meisolsson.githubsdk.model.User)3 View (android.view.View)2 AdapterView (android.widget.AdapterView)2 ListView (android.widget.ListView)2 GitHubFile (com.meisolsson.githubsdk.model.GitHubFile)2 Date (java.util.Date)2 Resources (android.content.res.Resources)1 Paint (android.graphics.Paint)1 Rect (android.graphics.Rect)1 OnClickListener (android.view.View.OnClickListener)1 ImageView (android.widget.ImageView)1 Folder (com.github.pockethub.android.core.code.FullTree.Folder)1 FullCommit (com.github.pockethub.android.core.commit.FullCommit)1 Commit (com.meisolsson.githubsdk.model.Commit)1 GitHubEvent (com.meisolsson.githubsdk.model.GitHubEvent)1 Label (com.meisolsson.githubsdk.model.Label)1 Milestone (com.meisolsson.githubsdk.model.Milestone)1 GitComment (com.meisolsson.githubsdk.model.git.GitComment)1