use of com.meisolsson.githubsdk.model.Status in project gh4a by slapperwan.
the class CommitStatusBox method onClick.
@Override
public void onClick(View v) {
switch(v.getId()) {
case R.id.row_commit_status:
Status status = (Status) v.getTag();
IntentUtils.launchBrowser(getContext(), Uri.parse(status.targetUrl()));
break;
case R.id.commit_status_header:
setStatusesExpanded(mStatusContainer.getVisibility() != View.VISIBLE);
break;
}
}
use of com.meisolsson.githubsdk.model.Status in project gh4a by slapperwan.
the class CommitStatusBox method fillStatus.
public void fillStatus(List<Status> statuses, PullRequest.MergeableState mergableState) {
final int statusIconDrawableAttrId;
final int statusLabelResId;
switch(mergableState) {
case Behind:
statusIconDrawableAttrId = R.attr.pullRequestMergeDirtyIcon;
statusLabelResId = R.string.pull_merge_status_behind;
break;
case Blocked:
statusIconDrawableAttrId = R.attr.pullRequestMergeDirtyIcon;
statusLabelResId = R.string.pull_merge_status_blocked;
break;
case Clean:
statusIconDrawableAttrId = R.attr.pullRequestMergeOkIcon;
statusLabelResId = statuses.isEmpty() ? R.string.pull_merge_status_mergable : R.string.pull_merge_status_clean;
break;
case Unstable:
statusIconDrawableAttrId = R.attr.pullRequestMergeDirtyIcon;
statusLabelResId = R.string.pull_merge_status_unstable;
break;
case Dirty:
statusIconDrawableAttrId = R.attr.pullRequestMergeDirtyIcon;
statusLabelResId = R.string.pull_merge_status_dirty;
break;
default:
if (statuses.isEmpty()) {
// Unknown status, no commit statuses -> nothing to display
setVisibility(View.GONE);
return;
}
statusIconDrawableAttrId = R.attr.pullRequestMergeUnknownIcon;
statusLabelResId = R.string.pull_merge_status_unknown;
break;
}
setVisibility(View.VISIBLE);
int statusIconResId = UiUtils.resolveDrawable(getContext(), statusIconDrawableAttrId);
mStatusIcon.setImageResource(statusIconResId);
mStatusLabel.setText(statusLabelResId);
mStatusContainer.removeAllViews();
if (statuses.isEmpty()) {
mStatusContainer.setVisibility(View.GONE);
mDropDownIcon.setVisibility(View.GONE);
mHeader.setClickable(false);
mSummaryTextView.setText(R.string.pull_no_commit_status);
return;
}
mHeader.setClickable(true);
mDropDownIcon.setVisibility(View.VISIBLE);
mStatusContainer.setVisibility(View.VISIBLE);
int failingCount = 0;
int pendingCount = 0;
int successCount = 0;
for (Status status : statuses) {
View statusRow = mInflater.inflate(R.layout.row_commit_status, mStatusContainer, false);
if (status.targetUrl() != null) {
statusRow.setTag(status);
statusRow.setOnClickListener(this);
}
final int iconDrawableAttrId;
switch(status.state()) {
case Error:
case Failure:
iconDrawableAttrId = R.attr.commitStatusFailIcon;
failingCount += 1;
break;
case Success:
iconDrawableAttrId = R.attr.commitStatusOkIcon;
successCount += 1;
break;
default:
iconDrawableAttrId = R.attr.commitStatusUnknownIcon;
pendingCount += 1;
break;
}
ImageView icon = statusRow.findViewById(R.id.iv_status_icon);
icon.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
icon.setImageResource(UiUtils.resolveDrawable(getContext(), iconDrawableAttrId));
TextView context = statusRow.findViewById(R.id.tv_context);
context.setText(status.context());
TextView description = statusRow.findViewById(R.id.tv_desc);
description.setText(status.description());
mStatusContainer.addView(statusRow);
}
if (mergableState == PullRequest.MergeableState.Unstable && pendingCount > 0) {
int resId = UiUtils.resolveDrawable(getContext(), R.attr.pullRequestMergeUnknownIcon);
mStatusIcon.setImageResource(resId);
mStatusLabel.setText(R.string.pull_merge_status_pending);
}
setSummaryText(failingCount, pendingCount, successCount);
setStatusesExpanded(failingCount + pendingCount > 0);
}
use of com.meisolsson.githubsdk.model.Status in project gh4a by slapperwan.
the class PullRequestFragment method loadCommitStatusesIfOpen.
private void loadCommitStatusesIfOpen(boolean force) {
if (mPullRequest.state() != IssueState.Open) {
return;
}
RepositoryStatusService service = ServiceFactory.get(RepositoryStatusService.class, force);
String sha = mPullRequest.head().sha();
ApiHelpers.PageIterator.toSingle(page -> service.getStatuses(mRepoOwner, mRepoName, sha, page)).compose(RxUtils.sortList(STATUS_TIMESTAMP_COMPARATOR)).map(statuses -> {
Set<String> seenContexts = new HashSet<>();
Iterator<Status> iter = statuses.iterator();
while (iter.hasNext()) {
Status status = iter.next();
if (seenContexts.contains(status.context())) {
iter.remove();
} else {
seenContexts.add(status.context());
}
}
return statuses;
}).compose(RxUtils.sortList(STATUS_AND_CONTEXT_COMPARATOR)).compose(makeLoaderSingle(ID_LOADER_STATUS, force)).subscribe(this::fillStatus, this::handleLoadFailure);
}
Aggregations