Beispiel #1
0
  public TurboIssue(String repoId, Issue issue) {
    this.id = issue.getNumber();
    this.title = issue.getTitle() == null ? "" : issue.getTitle();
    this.creator = issue.getUser().getLogin();
    this.createdAt = Utility.dateToLocalDateTime(issue.getCreatedAt());
    this.isPullRequest = isPullRequest(issue);

    this.description = issue.getBody() == null ? "" : issue.getBody();
    this.updatedAt =
        issue.getUpdatedAt() != null
            ? Utility.dateToLocalDateTime(issue.getUpdatedAt())
            : this.createdAt;
    this.commentCount = issue.getComments();
    this.isOpen = issue.getState().equals(STATE_OPEN);
    this.assignee =
        issue.getAssignee() == null
            ? Optional.empty()
            : Optional.of(issue.getAssignee().getLogin());
    this.labels = issue.getLabels().stream().map(Label::getName).collect(Collectors.toList());
    this.milestone =
        issue.getMilestone() == null
            ? Optional.empty()
            : Optional.of(issue.getMilestone().getNumber());

    this.metadata = IssueMetadata.empty();
    this.repoId = repoId;
    this.markedReadAt = Optional.empty();
  }
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    adapter.addHeader(headerView);
    adapter.addFooter(footerView);

    issue = store.getIssue(repositoryId, issueNumber);

    TextView loadingText = (TextView) loadingView.findViewById(R.id.tv_loading);
    loadingText.setText(R.string.loading_comments);

    if (issue == null || (issue.getComments() > 0 && items == null)) adapter.addHeader(loadingView);

    if (issue != null && items != null) updateList(issue, items);
    else {
      if (issue != null) updateHeader(issue);
      refreshIssue();
    }
  }
  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (RESULT_OK != resultCode || data == null) return;

    switch (requestCode) {
      case ISSUE_EDIT:
        Issue editedIssue = (Issue) data.getSerializableExtra(EXTRA_ISSUE);
        bodyImageGetter.encode(editedIssue.getId(), editedIssue.getBodyHtml());
        updateHeader(editedIssue);
        break;
      case COMMENT_CREATE:
        Comment comment = (Comment) data.getSerializableExtra(EXTRA_COMMENT);
        if (items != null) {
          items.add(comment);
          issue.setComments(issue.getComments() + 1);
          updateList(issue, items);
        } else refreshIssue();
        break;
      case COMMENT_EDIT:
        // TODO: update the commit without reloading the full issue
        refreshIssue();
        break;
    }
  }