Search in sources :

Example 6 with Milestone

use of com.meisolsson.githubsdk.model.Milestone in project PocketHub by pockethub.

the class IssueFilterTest method testEqualFilter.

/**
 * Verify {@link IssueFilter#equals(Object)}
 */
@Test
public void testEqualFilter() {
    Repository repo = Repository.builder().id(1L).build();
    IssueFilter filter1 = new IssueFilter(repo, UUID.randomUUID().toString());
    assertFalse(filter1.equals(null));
    assertFalse(filter1.equals(""));
    assertTrue(filter1.equals(filter1));
    IssueFilter filter2 = new IssueFilter(repo, UUID.randomUUID().toString());
    assertEquals(filter1, filter2);
    assertEquals(filter1.hashCode(), filter2.hashCode());
    User user = User.builder().id(2L).build();
    filter1.setAssignee(user);
    assertFalse(filter1.equals(filter2));
    filter2.setAssignee(user);
    assertEquals(filter1, filter2);
    assertEquals(filter1.hashCode(), filter2.hashCode());
    filter1.setOpen(false);
    assertFalse(filter1.equals(filter2));
    filter2.setOpen(false);
    assertEquals(filter1, filter2);
    assertEquals(filter1.hashCode(), filter2.hashCode());
    Milestone milestone = Milestone.builder().number(3).build();
    filter1.setMilestone(milestone);
    assertFalse(filter1.equals(filter2));
    filter2.setMilestone(milestone);
    assertEquals(filter1, filter2);
    assertEquals(filter1.hashCode(), filter2.hashCode());
}
Also used : Repository(com.meisolsson.githubsdk.model.Repository) User(com.meisolsson.githubsdk.model.User) Milestone(com.meisolsson.githubsdk.model.Milestone) IssueFilter(com.github.pockethub.android.core.issue.IssueFilter) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test)

Example 7 with Milestone

use of com.meisolsson.githubsdk.model.Milestone in project PocketHub by pockethub.

the class IssueFragment method updateHeader.

private void updateHeader(final Issue issue) {
    if (!isUsable()) {
        return;
    }
    titleText.setText(issue.title());
    String body = issue.bodyHtml();
    if (!TextUtils.isEmpty(body)) {
        bodyImageGetter.bind(bodyText, body, issue.id());
    } else {
        bodyText.setText(R.string.no_description_given);
    }
    authorText.setText(issue.user().login());
    createdDateText.setText(new StyledText().append(getString(R.string.prefix_opened)).append(issue.createdAt()));
    avatars.bind(creatorAvatar, issue.user());
    if (IssueUtils.isPullRequest(issue) && issue.pullRequest().commits() != null && issue.pullRequest().commits() > 0) {
        ViewUtils.setGone(commitsView, false);
        TextView icon = (TextView) headerView.findViewById(R.id.tv_commit_icon);
        TypefaceUtils.setOcticons(icon);
        icon.setText(ICON_COMMIT);
        String commits = getString(R.string.pull_request_commits, issue.pullRequest().commits());
        ((TextView) headerView.findViewById(R.id.tv_pull_request_commits)).setText(commits);
    } else {
        ViewUtils.setGone(commitsView, true);
    }
    boolean open = IssueState.open.equals(issue.state());
    if (!open) {
        StyledText text = new StyledText();
        text.bold(getString(R.string.closed));
        Date closedAt = issue.closedAt();
        if (closedAt != null) {
            text.append(' ').append(closedAt);
        }
        stateText.setText(text);
    }
    ViewUtils.setGone(stateText, open);
    User assignee = issue.assignee();
    if (assignee != null) {
        StyledText name = new StyledText();
        name.bold(assignee.login());
        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.labels();
    if (labels != null && !labels.isEmpty()) {
        LabelDrawableSpan.setText(labelsArea, labels);
        labelsArea.setVisibility(VISIBLE);
    } else {
        labelsArea.setVisibility(GONE);
    }
    if (issue.milestone() != null) {
        Milestone milestone = issue.milestone();
        StyledText milestoneLabel = new StyledText();
        milestoneLabel.append(getString(R.string.milestone_prefix));
        milestoneLabel.append(' ');
        milestoneLabel.bold(milestone.title());
        milestoneText.setText(milestoneLabel);
        float closed = milestone.closedIssues();
        float total = closed + milestone.openIssues();
        if (total > 0) {
            ((LayoutParams) milestoneProgressArea.getLayoutParams()).weight = closed / total;
            milestoneProgressArea.setVisibility(VISIBLE);
        } else {
            milestoneProgressArea.setVisibility(GONE);
        }
        milestoneArea.setVisibility(VISIBLE);
    } else {
        milestoneArea.setVisibility(GONE);
    }
    ViewUtils.setGone(progress, true);
    ViewUtils.setGone(list, false);
    updateStateItem(issue);
}
Also used : StyledText(com.github.pockethub.android.ui.StyledText) User(com.meisolsson.githubsdk.model.User) Milestone(com.meisolsson.githubsdk.model.Milestone) Label(com.meisolsson.githubsdk.model.Label) TextView(android.widget.TextView) Date(java.util.Date)

Example 8 with Milestone

use of com.meisolsson.githubsdk.model.Milestone in project gh4a by slapperwan.

the class IssueEditActivity method saveIssue.

private void saveIssue() {
    Milestone milestone = mEditIssue.milestone();
    IssueRequest.Builder builder = IssueRequest.builder();
    if (!ObjectsCompat.equals(mEditIssue.title(), mOriginalIssue.title())) {
        builder.title(mEditIssue.title());
    }
    if (!ObjectsCompat.equals(mEditIssue.body(), mOriginalIssue.body())) {
        builder.body(mEditIssue.body());
    }
    if (!ObjectsCompat.equals(mEditIssue.milestone(), mOriginalIssue.milestone())) {
        builder.milestone(milestone != null ? milestone.number() : null);
    }
    if (!ObjectsCompat.equals(mEditIssue.assignees(), mOriginalIssue.assignees())) {
        List<String> assignees = new ArrayList<>();
        for (User assignee : mEditIssue.assignees()) {
            assignees.add(assignee.login());
        }
        builder.assignees(assignees);
    }
    if (!ObjectsCompat.equals(mEditIssue.labels(), mOriginalIssue.labels())) {
        List<String> labels = new ArrayList<>();
        for (Label label : mEditIssue.labels()) {
            labels.add(label.name());
        }
        builder.labels(labels);
    }
    Integer issueNumber = mEditIssue.number();
    String errorMessage = issueNumber != null ? getString(R.string.issue_error_edit, issueNumber) : getString(R.string.issue_error_create);
    IssueService service = ServiceFactory.get(IssueService.class, false);
    Single<Response<Issue>> single = isInEditMode() ? service.editIssue(mRepoOwner, mRepoName, issueNumber, builder.build()) : service.createIssue(mRepoOwner, mRepoName, builder.build());
    single.map(ApiHelpers::throwOnFailure).compose(RxUtils.wrapForBackgroundTask(this, R.string.saving_msg, errorMessage)).subscribe(result -> {
        Intent data = new Intent();
        Bundle extras = new Bundle();
        extras.putParcelable("issue", result);
        data.putExtras(extras);
        setResult(RESULT_OK, data);
        finish();
    }, error -> handleActionFailure("Saving issue failed", error));
}
Also used : IssueService(com.meisolsson.githubsdk.service.issues.IssueService) User(com.meisolsson.githubsdk.model.User) Milestone(com.meisolsson.githubsdk.model.Milestone) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) Label(com.meisolsson.githubsdk.model.Label) Intent(android.content.Intent) Response(retrofit2.Response) IssueRequest(com.meisolsson.githubsdk.model.request.issue.IssueRequest) ApiHelpers(com.gh4a.utils.ApiHelpers)

Aggregations

Milestone (com.meisolsson.githubsdk.model.Milestone)8 User (com.meisolsson.githubsdk.model.User)6 Label (com.meisolsson.githubsdk.model.Label)5 Bundle (android.os.Bundle)3 TextView (android.widget.TextView)3 Intent (android.content.Intent)2 LayoutInflater (android.view.LayoutInflater)2 View (android.view.View)2 ApiHelpers (com.gh4a.utils.ApiHelpers)2 Activity (android.app.Activity)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 Typeface (android.graphics.Typeface)1 IdRes (android.support.annotation.IdRes)1 Nullable (android.support.annotation.Nullable)1 AppBarLayout (android.support.design.widget.AppBarLayout)1 CoordinatorLayout (android.support.design.widget.CoordinatorLayout)1 FloatingActionButton (android.support.design.widget.FloatingActionButton)1 TextInputLayout (android.support.design.widget.TextInputLayout)1 ContextCompat (android.support.v4.content.ContextCompat)1