Search in sources :

Example 1 with Status

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;
    }
}
Also used : Status(com.meisolsson.githubsdk.model.Status)

Example 2 with Status

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);
}
Also used : Status(com.meisolsson.githubsdk.model.Status) TextView(android.widget.TextView) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View)

Example 3 with Status

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);
}
Also used : HttpURLConnection(java.net.HttpURLConnection) IssueCommentService(com.meisolsson.githubsdk.service.issues.IssueCommentService) Bundle(android.os.Bundle) PullRequestReviewService(com.meisolsson.githubsdk.service.pull_request.PullRequestReviewService) Status(com.meisolsson.githubsdk.model.Status) GitHubFile(com.meisolsson.githubsdk.model.GitHubFile) RepositoryStatusService(com.meisolsson.githubsdk.service.repositories.RepositoryStatusService) PullRequest(com.meisolsson.githubsdk.model.PullRequest) PullRequestReviewCommentService(com.meisolsson.githubsdk.service.pull_request.PullRequestReviewCommentService) IssueState(com.meisolsson.githubsdk.model.IssueState) Map(java.util.Map) Issue(com.meisolsson.githubsdk.model.Issue) View(android.view.View) AttrRes(android.support.annotation.AttrRes) PullRequestBranchInfoView(com.gh4a.widget.PullRequestBranchInfoView) IntentUtils(com.gh4a.utils.IntentUtils) Review(com.meisolsson.githubsdk.model.Review) Set(java.util.Set) EditPullRequestCommentActivity(com.gh4a.activities.EditPullRequestCommentActivity) List(java.util.List) RxUtils(com.gh4a.utils.RxUtils) GitService(com.meisolsson.githubsdk.service.git.GitService) Optional(com.gh4a.utils.Optional) EditIssueCommentActivity(com.gh4a.activities.EditIssueCommentActivity) TimelineItem(com.gh4a.model.TimelineItem) ReviewState(com.meisolsson.githubsdk.model.ReviewState) Repository(com.meisolsson.githubsdk.model.Repository) LongSparseArray(android.support.v4.util.LongSparseArray) Pair(android.util.Pair) GitHubCommentBase(com.meisolsson.githubsdk.model.GitHubCommentBase) Intent(android.content.Intent) HashMap(java.util.HashMap) GitReference(com.meisolsson.githubsdk.model.git.GitReference) Response(retrofit2.Response) Single(io.reactivex.Single) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) PullRequestService(com.meisolsson.githubsdk.service.pull_request.PullRequestService) MenuInflater(android.view.MenuInflater) CommitStatusBox(com.gh4a.widget.CommitStatusBox) IssueEventService(com.meisolsson.githubsdk.service.issues.IssueEventService) Menu(android.view.Menu) R(com.gh4a.R) Observable(io.reactivex.Observable) CreateGitReference(com.meisolsson.githubsdk.model.request.git.CreateGitReference) ApiHelpers(com.gh4a.utils.ApiHelpers) Iterator(java.util.Iterator) PullRequestMarker(com.meisolsson.githubsdk.model.PullRequestMarker) ReviewComment(com.meisolsson.githubsdk.model.ReviewComment) TextUtils(android.text.TextUtils) AlertDialog(android.support.v7.app.AlertDialog) ServiceFactory(com.gh4a.ServiceFactory) Comparator(java.util.Comparator) Collections(java.util.Collections) Status(com.meisolsson.githubsdk.model.Status) Set(java.util.Set) HashSet(java.util.HashSet) RepositoryStatusService(com.meisolsson.githubsdk.service.repositories.RepositoryStatusService) Iterator(java.util.Iterator)

Aggregations

Status (com.meisolsson.githubsdk.model.Status)3 View (android.view.View)2 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 AttrRes (android.support.annotation.AttrRes)1 LongSparseArray (android.support.v4.util.LongSparseArray)1 AlertDialog (android.support.v7.app.AlertDialog)1 TextUtils (android.text.TextUtils)1 Pair (android.util.Pair)1 Menu (android.view.Menu)1 MenuInflater (android.view.MenuInflater)1 MenuItem (android.view.MenuItem)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 R (com.gh4a.R)1 ServiceFactory (com.gh4a.ServiceFactory)1 EditIssueCommentActivity (com.gh4a.activities.EditIssueCommentActivity)1 EditPullRequestCommentActivity (com.gh4a.activities.EditPullRequestCommentActivity)1 TimelineItem (com.gh4a.model.TimelineItem)1 ApiHelpers (com.gh4a.utils.ApiHelpers)1