use of com.gh4a.widget.IntentSpan in project gh4a by slapperwan.
the class EventViewHolder method formatEvent.
private CharSequence formatEvent(final IssueEvent event, final User user, int typefaceValue, boolean isPullRequestEvent) {
String textBase = null;
int textResId = 0;
switch(event.event()) {
case Closed:
if (isPullRequestEvent) {
textResId = event.commitId() != null ? R.string.pull_request_event_closed_with_commit : R.string.pull_request_event_closed;
} else {
textResId = event.commitId() != null ? R.string.issue_event_closed_with_commit : R.string.issue_event_closed;
}
break;
case Reopened:
textResId = isPullRequestEvent ? R.string.pull_request_event_reopened : R.string.issue_event_reopened;
break;
case Merged:
textResId = event.commitId() != null ? R.string.pull_request_event_merged_with_commit : R.string.pull_request_event_merged;
break;
case Referenced:
if (isPullRequestEvent) {
textResId = event.commitId() != null ? R.string.pull_request_event_referenced_with_commit : R.string.pull_request_event_referenced;
} else {
textResId = event.commitId() != null ? R.string.issue_event_referenced_with_commit : R.string.issue_event_referenced;
}
break;
case Assigned:
case Unassigned:
{
boolean isAssign = event.event() == IssueEventType.Assigned;
String actorLogin = user != null ? user.login() : null;
String assigneeLogin = event.assignee() != null ? event.assignee().login() : null;
if (assigneeLogin != null && assigneeLogin.equals(actorLogin)) {
if (isAssign) {
textResId = isPullRequestEvent ? R.string.pull_request_event_assigned_self : R.string.issue_event_assigned_self;
} else {
textResId = R.string.issue_event_unassigned_self;
}
} else {
textResId = isAssign ? R.string.issue_event_assigned : R.string.issue_event_unassigned;
textBase = mContext.getString(textResId, ApiHelpers.getUserLogin(mContext, user), ApiHelpers.getUserLogin(mContext, event.assignee()));
}
break;
}
case Labeled:
textResId = R.string.issue_event_labeled;
break;
case Unlabeled:
textResId = R.string.issue_event_unlabeled;
break;
case Locked:
textResId = R.string.issue_event_locked;
break;
case Unlocked:
textResId = R.string.issue_event_unlocked;
break;
case Milestoned:
case Demilestoned:
textResId = event.event() == IssueEventType.Milestoned ? R.string.issue_event_milestoned : R.string.issue_event_demilestoned;
textBase = mContext.getString(textResId, ApiHelpers.getUserLogin(mContext, user), event.milestone().title());
break;
case Renamed:
{
Rename rename = event.rename();
textBase = mContext.getString(R.string.issue_event_renamed, ApiHelpers.getUserLogin(mContext, user), rename.from(), rename.to());
break;
}
case ReviewRequested:
case ReviewRequestRemoved:
{
final String reviewerNames;
if (event.requestedReviewers() != null) {
ArrayList<String> reviewers = new ArrayList<>();
for (User reviewer : event.requestedReviewers()) {
reviewers.add(ApiHelpers.getUserLogin(mContext, reviewer));
}
reviewerNames = TextUtils.join(", ", reviewers);
} else {
reviewerNames = ApiHelpers.getUserLogin(mContext, event.requestedReviewer());
}
@StringRes int stringResId = event.event() == IssueEventType.ReviewRequested ? R.string.pull_request_event_review_requested : R.string.pull_request_event_review_request_removed;
textBase = mContext.getString(stringResId, ApiHelpers.getUserLogin(mContext, event.reviewRequester()), reviewerNames);
break;
}
case HeadRefDeleted:
textResId = R.string.pull_request_event_ref_deleted;
break;
case HeadRefRestored:
textResId = R.string.pull_request_event_ref_restored;
break;
default:
return null;
}
if (textBase == null) {
textBase = mContext.getString(textResId, ApiHelpers.getUserLogin(mContext, user));
}
SpannableStringBuilder text = StringUtils.applyBoldTags(textBase, typefaceValue);
int pos = text.toString().indexOf("[commit]");
if (event.commitId() != null && pos >= 0) {
text.replace(pos, pos + 8, event.commitId().substring(0, 7));
text.setSpan(new IntentSpan(mContext, context -> {
// The commit might be in a different repo. The API doesn't provide
// that information directly, so get it indirectly by parsing the URL
String repoOwner = mRepoOwner;
String repoName = mRepoName;
String url = event.commitUrl();
if (url != null) {
Matcher matcher = COMMIT_URL_REPO_NAME_AND_OWNER_PATTERN.matcher(url);
if (matcher.find()) {
repoOwner = matcher.group(1);
repoName = matcher.group(2);
}
}
return CommitActivity.makeIntent(context, repoOwner, repoName, event.commitId());
}), pos, pos + 7, 0);
text.setSpan(new TypefaceSpan("monospace"), pos, pos + 7, 0);
}
pos = text.toString().indexOf("[label]");
Label label = event.label();
if (label != null && pos >= 0) {
int length = label.name().length();
text.replace(pos, pos + 7, label.name());
text.setSpan(new IssueLabelSpan(mContext, label, false), pos, pos + length, 0);
}
CharSequence time = event.createdAt() != null ? StringUtils.formatRelativeTime(mContext, event.createdAt(), true) : "";
pos = text.toString().indexOf("[time]");
if (pos >= 0) {
text.replace(pos, pos + 6, time);
if (event.createdAt() != null) {
text.setSpan(new TimestampToastSpan(event.createdAt()), pos, pos + time.length(), 0);
}
}
return text;
}
use of com.gh4a.widget.IntentSpan in project gh4a by slapperwan.
the class RepositoryFragment method fillData.
private void fillData() {
TextView tvRepoName = mContentView.findViewById(R.id.tv_repo_name);
IntentSpan repoSpan = new IntentSpan(tvRepoName.getContext(), context -> UserActivity.makeIntent(context, mRepository.owner()));
SpannableStringBuilder repoName = new SpannableStringBuilder();
repoName.append(mRepository.owner().login());
repoName.append("/");
repoName.append(mRepository.name());
repoName.setSpan(repoSpan, 0, mRepository.owner().login().length(), 0);
tvRepoName.setText(repoName);
tvRepoName.setMovementMethod(UiUtils.CHECKING_LINK_METHOD);
TextView tvParentRepo = mContentView.findViewById(R.id.tv_parent);
if (mRepository.isFork() && mRepository.parent() != null) {
Repository parent = mRepository.parent();
tvParentRepo.setVisibility(View.VISIBLE);
tvParentRepo.setText(getString(R.string.forked_from, parent.owner().login() + "/" + parent.name()));
tvParentRepo.setOnClickListener(this);
tvParentRepo.setTag(parent);
} else {
tvParentRepo.setVisibility(View.GONE);
}
fillTextView(R.id.tv_desc, 0, mRepository.description());
fillTextView(R.id.tv_language, R.string.repo_language, mRepository.language());
fillTextView(R.id.tv_url, 0, !StringUtils.isBlank(mRepository.homepage()) ? mRepository.homepage() : mRepository.htmlUrl());
mContentView.findViewById(R.id.cell_stargazers).setOnClickListener(this);
mContentView.findViewById(R.id.cell_forks).setOnClickListener(this);
mContentView.findViewById(R.id.cell_pull_requests).setOnClickListener(this);
mContentView.findViewById(R.id.tv_contributors_label).setOnClickListener(this);
mContentView.findViewById(R.id.other_info).setOnClickListener(this);
mContentView.findViewById(R.id.tv_releases_label).setOnClickListener(this);
mReadmeTitleView.setOnClickListener(this);
Permissions permissions = mRepository.permissions();
updateClickableLabel(R.id.tv_collaborators_label, permissions != null && permissions.push());
updateClickableLabel(R.id.tv_wiki_label, mRepository.hasWiki());
TextView tvStargazersCount = mContentView.findViewById(R.id.tv_stargazers_count);
tvStargazersCount.setText(String.valueOf(mRepository.watchersCount()));
TextView tvForksCount = mContentView.findViewById(R.id.tv_forks_count);
tvForksCount.setText(String.valueOf(mRepository.forksCount()));
LinearLayout llIssues = mContentView.findViewById(R.id.cell_issues);
if (mRepository.hasIssues()) {
llIssues.setVisibility(View.VISIBLE);
llIssues.setOnClickListener(this);
// value will be filled when PR count arrives
} else {
llIssues.setVisibility(View.GONE);
}
mContentView.findViewById(R.id.tv_private).setVisibility(mRepository.isPrivate() ? View.VISIBLE : View.GONE);
}
Aggregations