use of com.fastaccess.ui.widgets.SpannableBuilder in project FastHub by k0shk0sh.
the class FeedsViewHolder method appendPushEvent.
private void appendPushEvent(SpannableBuilder spannableBuilder, Event eventsModel) {
String ref = eventsModel.getPayload().getRef();
if (ref.startsWith("refs/heads/")) {
ref = ref.substring(11);
}
spannableBuilder.bold("pushed to").append(" ").append(ref).append(" ").bold("at").append(" ").append(eventsModel.getRepo().getName());
final List<GitCommitModel> commits = eventsModel.getPayload().getCommits();
int size = commits != null ? commits.size() : -1;
SpannableBuilder spanCommits = SpannableBuilder.builder();
if (size > 0) {
if (size != 1)
spanCommits.append(String.valueOf(eventsModel.getPayload().getSize())).append(" new commits").append("\n");
else
spanCommits.append("1 new commit").append("\n");
int max = 5;
int appended = 0;
for (GitCommitModel commit : commits) {
if (commit == null)
continue;
String sha = commit.getSha();
if (TextUtils.isEmpty(sha))
continue;
sha = sha.length() > 7 ? sha.substring(0, 7) : sha;
spanCommits.url(sha).append(" ").append(commit.getMessage() != null ? commit.getMessage().replaceAll("\\r?\\n|\\r", " ") : "").append("\n");
appended++;
if (appended == max)
break;
}
}
if (spanCommits.length() > 0) {
int last = spanCommits.length();
description.setMaxLines(5);
description.setText(spanCommits.delete(last - 1, last));
description.setVisibility(View.VISIBLE);
} else {
description.setText("");
description.setMaxLines(2);
description.setVisibility(View.GONE);
}
}
use of com.fastaccess.ui.widgets.SpannableBuilder in project FastHub by k0shk0sh.
the class FeedsViewHolder method bind.
@Override
public void bind(@NonNull Event eventsModel) {
appendAvatar(eventsModel);
SpannableBuilder spannableBuilder = SpannableBuilder.builder();
appendActor(eventsModel, spannableBuilder);
description.setMaxLines(2);
description.setText("");
description.setVisibility(View.GONE);
if (eventsModel.getType() != null) {
EventsType type = eventsModel.getType();
if (type == EventsType.WatchEvent) {
appendWatch(spannableBuilder, type, eventsModel);
} else if (type == EventsType.CreateEvent) {
appendCreateEvent(spannableBuilder, eventsModel);
} else if (type == EventsType.CommitCommentEvent) {
appendCommitComment(spannableBuilder, eventsModel);
} else if (type == EventsType.DownloadEvent) {
appendDownloadEvent(spannableBuilder, eventsModel);
} else if (type == EventsType.FollowEvent) {
appendFollowEvent(spannableBuilder, eventsModel);
} else if (type == EventsType.ForkEvent) {
appendForkEvent(spannableBuilder, eventsModel);
} else if (type == EventsType.GistEvent) {
appendGistEvent(spannableBuilder, eventsModel);
} else if (type == EventsType.GollumEvent) {
appendGollumEvent(spannableBuilder, eventsModel);
} else if (type == EventsType.IssueCommentEvent) {
appendIssueCommentEvent(spannableBuilder, eventsModel);
} else if (type == EventsType.IssuesEvent) {
appendIssueEvent(spannableBuilder, eventsModel);
} else if (type == EventsType.MemberEvent) {
appendMemberEvent(spannableBuilder, eventsModel);
} else if (type == EventsType.PublicEvent) {
appendPublicEvent(spannableBuilder, eventsModel);
} else if (type == EventsType.PullRequestEvent) {
appendPullRequestEvent(spannableBuilder, eventsModel);
} else if (type == EventsType.PullRequestReviewCommentEvent) {
appendPullRequestReviewCommentEvent(spannableBuilder, eventsModel);
} else if (type == EventsType.PullRequestReviewEvent) {
appendPullRequestReviewCommentEvent(spannableBuilder, eventsModel);
} else if (type == EventsType.RepositoryEvent) {
appendPublicEvent(spannableBuilder, eventsModel);
} else if (type == EventsType.PushEvent) {
appendPushEvent(spannableBuilder, eventsModel);
} else if (type == EventsType.TeamAddEvent) {
appendTeamEvent(spannableBuilder, eventsModel);
} else if (type == EventsType.DeleteEvent) {
appendDeleteEvent(spannableBuilder, eventsModel);
} else if (type == EventsType.ReleaseEvent) {
appendReleaseEvent(spannableBuilder, eventsModel);
} else if (type == EventsType.ForkApplyEvent) {
appendForkApplyEvent(spannableBuilder, eventsModel);
} else if (type == EventsType.OrgBlockEvent) {
appendOrgBlockEvent(spannableBuilder, eventsModel);
} else if (type == EventsType.ProjectCardEvent) {
appendProjectCardEvent(spannableBuilder, eventsModel, false);
} else if (type == EventsType.ProjectColumnEvent) {
appendProjectCardEvent(spannableBuilder, eventsModel, true);
} else if (type == EventsType.OrganizationEvent) {
appendOrganizationEvent(spannableBuilder, eventsModel);
} else if (type == EventsType.ProjectEvent) {
appendProjectCardEvent(spannableBuilder, eventsModel, false);
}
date.setGravity(Gravity.CENTER);
date.setEventsIcon(type.getDrawableRes());
}
title.setText(spannableBuilder);
date.setText(ParseDateFormat.getTimeAgo(eventsModel.getCreatedAt()));
}
use of com.fastaccess.ui.widgets.SpannableBuilder in project FastHub by k0shk0sh.
the class IssueDetailsViewHolder method setupLabels.
private void setupLabels(@Nullable List<LabelModel> labelList) {
if (labelList != null && !labelList.isEmpty()) {
SpannableBuilder builder = SpannableBuilder.builder();
for (LabelModel labelModel : labelList) {
int color = Color.parseColor("#" + labelModel.getColor());
builder.append(" ").append(" " + labelModel.getName() + " ", new LabelSpan(color));
}
labels.setText(builder);
labelsHolder.setVisibility(View.VISIBLE);
} else {
labels.setText("");
labelsHolder.setVisibility(View.GONE);
}
}
use of com.fastaccess.ui.widgets.SpannableBuilder in project FastHub by k0shk0sh.
the class PullStatusViewHolder method bind.
@Override
public void bind(@NonNull PullRequestStatusModel pullRequestStatusModel) {
if (pullRequestStatusModel.getState() != null) {
StatusStateType stateType = pullRequestStatusModel.getState();
stateImage.setImageResource(stateType.getDrawableRes());
String mergeableState = pullRequestStatusModel.getMergeableState();
boolean isBlocked = "blocked".equalsIgnoreCase(mergeableState);
if (stateType == StatusStateType.failure) {
stateImage.tintDrawableColor(red);
if (pullRequestStatusModel.isMergable()) {
status.setText(R.string.checks_failed);
} else {
status.setText(SpannableBuilder.builder().append(status.getResources().getString(R.string.checks_failed)).append("\n").append(status.getResources().getString(R.string.can_not_merge_pr)));
}
} else if (stateType == StatusStateType.pending) {
if (pullRequestStatusModel.isMergable()) {
stateImage.setImageResource(R.drawable.ic_check_small);
stateImage.tintDrawableColor(green);
status.setText(!isBlocked ? R.string.commit_can_be_merged : R.string.can_not_merge_pr);
} else {
stateImage.setImageResource(stateType.getDrawableRes());
stateImage.tintDrawableColor(indigo);
status.setText(R.string.checks_pending);
}
} else {
stateImage.tintDrawableColor(green);
if (pullRequestStatusModel.isMergable()) {
status.setText(!isBlocked ? R.string.commit_can_be_merged : R.string.can_not_merge_pr);
} else {
status.setText(R.string.checks_passed);
}
}
}
if (pullRequestStatusModel.getStatuses() != null && !pullRequestStatusModel.getStatuses().isEmpty()) {
SpannableBuilder builder = SpannableBuilder.builder();
Stream.of(pullRequestStatusModel.getStatuses()).filter(statusesModel -> statusesModel != null && statusesModel.getState() != null && statusesModel.getTargetUrl() != null).forEach(statusesModel -> {
if (!InputHelper.isEmpty(statusesModel.getTargetUrl())) {
builder.append(ContextCompat.getDrawable(statuses.getContext(), statusesModel.getState().getDrawableRes()));
builder.append(" ").append(statusesModel.getContext() != null ? statusesModel.getContext() + " " : "").url(statusesModel.getDescription(), v -> SchemeParser.launchUri(v.getContext(), statusesModel.getTargetUrl())).append("\n");
}
});
if (!InputHelper.isEmpty(builder)) {
statuses.setMovementMethod(LinkMovementMethod.getInstance());
statuses.setText(builder);
statuses.setVisibility(View.VISIBLE);
} else {
statuses.setVisibility(View.GONE);
}
} else {
statuses.setVisibility(View.GONE);
}
}
use of com.fastaccess.ui.widgets.SpannableBuilder in project FastHub by k0shk0sh.
the class CreateIssueActivity method onSelectedLabels.
@Override
public void onSelectedLabels(@NonNull ArrayList<LabelModel> labelModels) {
this.labelModels.clear();
this.labelModels.addAll(labelModels);
SpannableBuilder builder = SpannableBuilder.builder();
for (int i = 0; i < labelModels.size(); i++) {
LabelModel labelModel = labelModels.get(i);
int color = Color.parseColor("#" + labelModel.getColor());
if (i > 0) {
builder.append(" ").append(" " + labelModel.getName() + " ", new LabelSpan(color));
} else {
builder.append(labelModel.getName() + " ", new LabelSpan(color));
}
}
this.labels.setText(builder);
}
Aggregations