Search in sources :

Example 1 with IssueService

use of com.meisolsson.githubsdk.service.issues.IssueService 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 IssueService

use of com.meisolsson.githubsdk.service.issues.IssueService in project gh4a by slapperwan.

the class IssueActivity method updateIssueState.

private void updateIssueState(boolean reopen) {
    IssueService service = ServiceFactory.get(IssueService.class, false);
    IssueRequest request = IssueRequest.builder().state(reopen ? IssueState.Open : IssueState.Closed).build();
    @StringRes int dialogResId = reopen ? R.string.opening_msg : R.string.closing_msg;
    @StringRes int errorMessageResId = reopen ? R.string.issue_error_reopen : R.string.issue_error_close;
    service.editIssue(mRepoOwner, mRepoName, mIssueNumber, request).map(ApiHelpers::throwOnFailure).compose(RxUtils.wrapForBackgroundTask(this, dialogResId, getString(errorMessageResId, mIssueNumber))).subscribe(result -> {
        mIssue = result;
        updateHeader();
        if (mEditFab != null) {
            mEditFab.setState(mIssue.state());
        }
        if (mFragment != null) {
            mFragment.updateState(mIssue);
        }
        setResult(RESULT_OK);
        supportInvalidateOptionsMenu();
    }, error -> handleActionFailure("Updating issue state failed", error));
}
Also used : IssueService(com.meisolsson.githubsdk.service.issues.IssueService) IssueRequest(com.meisolsson.githubsdk.model.request.issue.IssueRequest) StringRes(android.support.annotation.StringRes) ApiHelpers(com.gh4a.utils.ApiHelpers)

Example 3 with IssueService

use of com.meisolsson.githubsdk.service.issues.IssueService in project gh4a by slapperwan.

the class IssueActivity method loadIssue.

private void loadIssue(boolean force) {
    IssueService service = ServiceFactory.get(IssueService.class, force);
    service.getIssue(mRepoOwner, mRepoName, mIssueNumber).map(ApiHelpers::throwOnFailure).compose(makeLoaderSingle(ID_LOADER_ISSUE, force)).subscribe(result -> {
        mIssue = result;
        showUiIfDone();
        supportInvalidateOptionsMenu();
    }, this::handleLoadFailure);
}
Also used : IssueService(com.meisolsson.githubsdk.service.issues.IssueService) ApiHelpers(com.gh4a.utils.ApiHelpers)

Example 4 with IssueService

use of com.meisolsson.githubsdk.service.issues.IssueService in project gh4a by slapperwan.

the class PullRequestActivity method load.

private void load(boolean force) {
    PullRequestService prService = ServiceFactory.get(PullRequestService.class, force);
    IssueService issueService = ServiceFactory.get(IssueService.class, force);
    Single<PullRequest> prSingle = prService.getPullRequest(mRepoOwner, mRepoName, mPullRequestNumber).map(ApiHelpers::throwOnFailure);
    Single<Issue> issueSingle = issueService.getIssue(mRepoOwner, mRepoName, mPullRequestNumber).map(ApiHelpers::throwOnFailure);
    Single<Boolean> isCollaboratorSingle = SingleFactory.isAppUserRepoCollaborator(mRepoOwner, mRepoName, force);
    Single.zip(issueSingle, prSingle, isCollaboratorSingle, Triplet::create).compose(makeLoaderSingle(0, force)).subscribe(result -> {
        mIssue = result.first;
        mPullRequest = result.second;
        mIsCollaborator = result.third;
        fillHeader();
        setContentShown(true);
        invalidateTabs();
        updateFabVisibility();
        supportInvalidateOptionsMenu();
        if (mInitialPage >= 0 && mInitialPage < TITLES.length) {
            getPager().setCurrentItem(mInitialPage);
            mInitialPage = -1;
        }
    }, this::handleLoadFailure);
}
Also used : PullRequestService(com.meisolsson.githubsdk.service.pull_request.PullRequestService) IssueService(com.meisolsson.githubsdk.service.issues.IssueService) Issue(com.meisolsson.githubsdk.model.Issue) Triplet(com.gh4a.utils.Triplet) PullRequest(com.meisolsson.githubsdk.model.PullRequest) EditPullRequest(com.meisolsson.githubsdk.model.request.pull_request.EditPullRequest) ApiHelpers(com.gh4a.utils.ApiHelpers)

Example 5 with IssueService

use of com.meisolsson.githubsdk.service.issues.IssueService 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

IssueService (com.meisolsson.githubsdk.service.issues.IssueService)5 ApiHelpers (com.gh4a.utils.ApiHelpers)4 IssueRequest (com.meisolsson.githubsdk.model.request.issue.IssueRequest)3 Intent (android.content.Intent)2 Issue (com.meisolsson.githubsdk.model.Issue)2 Label (com.meisolsson.githubsdk.model.Label)2 ArrayList (java.util.ArrayList)2 Bundle (android.os.Bundle)1 StringRes (android.support.annotation.StringRes)1 Triplet (com.gh4a.utils.Triplet)1 ProgressObserverAdapter (com.github.pockethub.android.rx.ProgressObserverAdapter)1 Milestone (com.meisolsson.githubsdk.model.Milestone)1 PullRequest (com.meisolsson.githubsdk.model.PullRequest)1 User (com.meisolsson.githubsdk.model.User)1 EditPullRequest (com.meisolsson.githubsdk.model.request.pull_request.EditPullRequest)1 PullRequestService (com.meisolsson.githubsdk.service.pull_request.PullRequestService)1 Response (retrofit2.Response)1