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);
}
}
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));
}
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);
}
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);
}
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);
}
Aggregations