Search in sources :

Example 1 with Label

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

the class EditIssueActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case R.id.m_apply:
            IssueRequest.Builder request = IssueRequest.builder().body(bodyText.getText().toString()).title(titleText.getText().toString()).state(issue.state());
            if (issue.assignee() != null) {
                request.assignees(Collections.singletonList(issue.assignee().login()));
            }
            if (issue.milestone() != null) {
                request.milestone(issue.milestone().number());
            }
            if (issue.labels() != null) {
                List<String> labels = new ArrayList<>();
                for (Label label : issue.labels()) {
                    labels.add(label.name());
                }
                request.labels(labels);
            }
            IssueService service = ServiceGenerator.createService(this, IssueService.class);
            Single<Issue> single;
            int message;
            if (issue.number() != null && issue.number() > 0) {
                single = service.editIssue(repository.owner().login(), repository.name(), issue.number(), request.build());
                message = R.string.updating_issue;
            } else {
                single = service.createIssue(repository.owner().login(), repository.name(), request.build());
                message = R.string.creating_issue;
            }
            single.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).compose(this.<Issue>bindToLifecycle()).subscribe(new ProgressObserverAdapter<Issue>(this, message) {

                @Override
                public void onSuccess(Issue issue) {
                    super.onSuccess(issue);
                    Intent intent = new Intent();
                    intent.putExtra(EXTRA_ISSUE, issue);
                    setResult(RESULT_OK, intent);
                    finish();
                }

                @Override
                public void onError(Throwable e) {
                    super.onError(e);
                    Log.e(TAG, "Exception creating issue", e);
                    ToastUtils.show(EditIssueActivity.this, e.getMessage());
                }
            }.start());
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
Also used : IssueService(com.meisolsson.githubsdk.service.issues.IssueService) Issue(com.meisolsson.githubsdk.model.Issue) ProgressObserverAdapter(com.github.pockethub.android.rx.ProgressObserverAdapter) ArrayList(java.util.ArrayList) Label(com.meisolsson.githubsdk.model.Label) Intent(android.content.Intent) IssueRequest(com.meisolsson.githubsdk.model.request.issue.IssueRequest)

Example 2 with Label

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

the class EditLabelsTask method subscribe.

@Override
public void subscribe(ObservableEmitter<Issue> emitter) throws Exception {
    try {
        List<String> labelNames = new ArrayList<>(labels.length);
        for (Label label : labels) {
            labelNames.add(label.name());
        }
        IssueRequest editIssue = IssueRequest.builder().labels(labelNames).build();
        emitter.onNext(store.editIssue(repositoryId, issueNumber, editIssue));
    } catch (IOException e) {
        emitter.onError(e);
    }
}
Also used : IssueRequest(com.meisolsson.githubsdk.model.request.issue.IssueRequest) ArrayList(java.util.ArrayList) Label(com.meisolsson.githubsdk.model.Label) IOException(java.io.IOException)

Example 3 with Label

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

the class FilterListAdapter method update.

@Override
protected void update(int position, IssueFilter filter) {
    avatars.bind(imageView(0), filter.getRepository().owner());
    setText(1, InfoUtils.createRepoId(filter.getRepository()));
    if (filter.isOpen()) {
        setText(2, R.string.open_issues);
    } else {
        setText(2, R.string.closed_issues);
    }
    Collection<Label> labels = filter.getLabels();
    if (labels != null && !labels.isEmpty()) {
        TextView labelsText = textView(3);
        LabelDrawableSpan.setText(labelsText, labels);
        ViewUtils.setGone(labelsText, false);
    } else {
        setGone(3, true);
    }
    Milestone milestone = filter.getMilestone();
    if (milestone != null) {
        ViewUtils.setGone(setText(4, milestone.title()), false);
    } else {
        setGone(4, true);
    }
    User assignee = filter.getAssignee();
    if (assignee != null) {
        avatars.bind(imageView(7), assignee);
        ViewUtils.setGone(setText(6, assignee.login()), false);
    } else {
        setGone(5, true);
    }
}
Also used : User(com.meisolsson.githubsdk.model.User) Milestone(com.meisolsson.githubsdk.model.Milestone) Label(com.meisolsson.githubsdk.model.Label) TextView(android.widget.TextView)

Example 4 with Label

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

the class IssueFilter method toDisplay.

/**
     * Get display {@link CharSequence} representing this filter
     *
     * @return display
     */
public CharSequence toDisplay() {
    List<String> segments = new ArrayList<>();
    if (open) {
        segments.add("Open issues");
    } else {
        segments.add("Closed issues");
    }
    if (assignee != null) {
        segments.add("Assignee: " + assignee.login());
    }
    if (milestone != null) {
        segments.add("Milestone: " + milestone.title());
    }
    if (labels != null && !labels.isEmpty()) {
        StringBuilder builder = new StringBuilder("Labels: ");
        for (Label label : labels) {
            builder.append(label.name()).append(',').append(' ');
        }
        builder.deleteCharAt(builder.length() - 1);
        builder.deleteCharAt(builder.length() - 1);
        segments.add(builder.toString());
    }
    if (segments.isEmpty()) {
        return "";
    }
    StringBuilder all = new StringBuilder();
    for (String segment : segments) {
        all.append(segment).append(',').append(' ');
    }
    all.deleteCharAt(all.length() - 1);
    all.deleteCharAt(all.length() - 1);
    return all;
}
Also used : ArrayList(java.util.ArrayList) Label(com.meisolsson.githubsdk.model.Label)

Example 5 with Label

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

the class IssuesFragment method updateFilterSummary.

private void updateFilterSummary() {
    if (filter.isOpen()) {
        state.setText(R.string.open_issues);
    } else {
        state.setText(R.string.closed_issues);
    }
    Collection<Label> filterLabels = filter.getLabels();
    if (filterLabels != null && !filterLabels.isEmpty()) {
        LabelDrawableSpan.setText(labels, filterLabels);
        labels.setVisibility(VISIBLE);
    } else {
        labels.setVisibility(GONE);
    }
    Milestone filterMilestone = filter.getMilestone();
    if (filterMilestone != null) {
        milestone.setText(filterMilestone.title());
        milestone.setVisibility(VISIBLE);
    } else {
        milestone.setVisibility(GONE);
    }
    User user = filter.getAssignee();
    if (user != null) {
        avatars.bind(assigneeAvatar, user);
        assignee.setText(user.login());
        assigneeArea.setVisibility(VISIBLE);
    } else {
        assigneeArea.setVisibility(GONE);
    }
}
Also used : User(com.meisolsson.githubsdk.model.User) Milestone(com.meisolsson.githubsdk.model.Milestone) Label(com.meisolsson.githubsdk.model.Label)

Aggregations

Label (com.meisolsson.githubsdk.model.Label)12 ArrayList (java.util.ArrayList)7 ProgressObserverAdapter (com.github.pockethub.android.rx.ProgressObserverAdapter)3 Milestone (com.meisolsson.githubsdk.model.Milestone)3 User (com.meisolsson.githubsdk.model.User)3 Bundle (android.os.Bundle)2 TextView (android.widget.TextView)2 IssueRequest (com.meisolsson.githubsdk.model.request.issue.IssueRequest)2 Activity (android.app.Activity)1 Intent (android.content.Intent)1 LayoutInflater (android.view.LayoutInflater)1 ListView (android.widget.ListView)1 DialogAction (com.afollestad.materialdialogs.DialogAction)1 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)1 BaseActivity (com.github.pockethub.android.ui.BaseActivity)1 StyledText (com.github.pockethub.android.ui.StyledText)1 GitHubComment (com.meisolsson.githubsdk.model.GitHubComment)1 Issue (com.meisolsson.githubsdk.model.Issue)1 Page (com.meisolsson.githubsdk.model.Page)1 IssueCommentService (com.meisolsson.githubsdk.service.issues.IssueCommentService)1