private void openPullRequestCommits() {
    if (IssueUtils.isPullRequest(issue)) {
      PullRequest pullRequest = issue.getPullRequest();

      String base = pullRequest.getBase().getSha();
      String head = pullRequest.getHead().getSha();
      Repository repo = pullRequest.getBase().getRepo();
      startActivity(CommitCompareViewActivity.createIntent(repo, base, head));
    }
  }
Example #2
0
 private static boolean isPullRequest(Issue issue) {
   return issue.getPullRequest() != null && issue.getPullRequest().getUrl() != null;
 }
  private void updateHeader(final Issue issue) {
    if (!isUsable()) return;

    boolean isPullRequest = IssueUtils.isPullRequest(issue);
    titleText.setText(issue.getTitle());

    String body = issue.getBodyHtml();
    if (!TextUtils.isEmpty(body)) bodyImageGetter.bind(bodyText, body, issue.getId());
    else bodyText.setText(R.string.no_description_given);

    authorText.setText(issue.getUser().getLogin());
    createdDateText.setText(
        new StyledText().append(getString(R.string.prefix_opened)).append(issue.getCreatedAt()));
    avatars.bind(creatorAvatar, issue.getUser());

    if (isPullRequest && issue.getPullRequest().getCommits() > 0) {
      ViewUtils.setGone(commitsView, false);

      TextView icon = (TextView) headerView.findViewById(R.id.tv_commit_icon);
      TypefaceUtils.setOcticons(icon);
      icon.setText(TypefaceUtils.ICON_GIT_COMMIT);

      String commits =
          getString(R.string.pull_request_commits, issue.getPullRequest().getCommits());
      ((TextView) headerView.findViewById(R.id.tv_pull_request_commits)).setText(commits);
    } else ViewUtils.setGone(commitsView, true);

    boolean open = STATE_OPEN.equals(issue.getState());
    if (!open) {
      StyledText text = new StyledText();
      if (isPullRequest && issue.getPullRequest().isMerged()) {
        text.bold(getString(R.string.merged));
        stateText.setBackgroundResource(R.color.state_background_merged);
      } else {
        text.bold(getString(R.string.closed));
        stateText.setBackgroundResource(R.color.state_background_closed);
      }
      Date closedAt = issue.getClosedAt();
      if (closedAt != null) text.append(' ').append(closedAt);
      stateText.setText(text);
    }
    ViewUtils.setGone(stateText, open);

    User assignee = issue.getAssignee();
    if (assignee != null) {
      StyledText name = new StyledText();
      name.bold(assignee.getLogin());
      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.getLabels();
    if (labels != null && !labels.isEmpty()) {
      LabelDrawableSpan.setText(labelsArea, labels);
      labelsArea.setVisibility(VISIBLE);
    } else labelsArea.setVisibility(GONE);

    if (issue.getMilestone() != null) {
      Milestone milestone = issue.getMilestone();
      StyledText milestoneLabel = new StyledText();
      milestoneLabel.append(getString(R.string.milestone_prefix));
      milestoneLabel.append(' ');
      milestoneLabel.bold(milestone.getTitle());
      milestoneText.setText(milestoneLabel);
      float closed = milestone.getClosedIssues();
      float total = closed + milestone.getOpenIssues();
      if (total > 0) {
        ((LayoutParams) milestoneProgressArea.getLayoutParams()).weight = closed / total;
        milestoneProgressArea.setVisibility(VISIBLE);
      } else milestoneProgressArea.setVisibility(GONE);
      milestoneArea.setVisibility(VISIBLE);
    } else milestoneArea.setVisibility(GONE);

    String state = issue.getState();
    if (state != null && state.length() > 0)
      state = state.substring(0, 1).toUpperCase(Locale.US) + state.substring(1);
    else state = "";

    ViewUtils.setGone(progress, true);
    ViewUtils.setGone(list, false);
    updateStateItem(issue);
  }
  protected void updateEvent(final IssueEvent event) {
    TypefaceUtils.setOcticons(textView(0));
    String message = String.format("<b>%s</b> %s", event.getActor().getLogin(), event.getEvent());
    avatars.bind(imageView(2), event.getActor());

    String eventString = event.getEvent();

    switch (eventString) {
      case "assigned":
      case "unassigned":
        setText(0, TypefaceUtils.ICON_PERSON);
        textView(0).setTextColor(context.getResources().getColor(R.color.text_description));
        break;
      case "labeled":
      case "unlabeled":
        setText(0, TypefaceUtils.ICON_TAG);
        textView(0).setTextColor(context.getResources().getColor(R.color.text_description));
        break;
      case "referenced":
        setText(0, TypefaceUtils.ICON_BOOKMARK);
        textView(0).setTextColor(context.getResources().getColor(R.color.text_description));
        break;
      case "milestoned":
      case "demilestoned":
        setText(0, TypefaceUtils.ICON_MILESTONE);
        textView(0).setTextColor(context.getResources().getColor(R.color.text_description));
        break;
      case "closed":
        setText(0, TypefaceUtils.ICON_ISSUE_CLOSE);
        textView(0).setTextColor(context.getResources().getColor(R.color.issue_event_closed));
        break;
      case "reopened":
        setText(0, TypefaceUtils.ICON_ISSUE_REOPEN);
        textView(0).setTextColor(context.getResources().getColor(R.color.issue_event_reopened));
        break;
      case "renamed":
        setText(0, TypefaceUtils.ICON_EDIT);
        textView(0).setTextColor(context.getResources().getColor(R.color.text_description));
        break;
      case "merged":
        message +=
            String.format(
                " commit <b>%s</b> into <tt>%s</tt> from <tt>%s</tt>",
                event.getCommitId().substring(0, 6),
                issue.getPullRequest().getBase().getRef(),
                issue.getPullRequest().getHead().getRef());
        setText(0, TypefaceUtils.ICON_MERGE);
        textView(0).setTextColor(context.getResources().getColor(R.color.issue_event_merged));
        break;
      case "locked":
        setText(0, TypefaceUtils.ICON_LOCK);
        textView(0).setTextColor(context.getResources().getColor(R.color.issue_event_lock));
        break;
      case "unlocked":
        setText(0, TypefaceUtils.ICON_KEY);
        textView(0).setTextColor(context.getResources().getColor(R.color.issue_event_lock));
        break;
    }

    message += " " + TimeUtils.getRelativeTime(event.getCreatedAt());
    setText(1, Html.fromHtml(message));
  }