Search in sources :

Example 51 with ApiHelpers

use of com.gh4a.utils.ApiHelpers in project gh4a by slapperwan.

the class IssueMilestoneEditActivity method setMilestoneState.

private void setMilestoneState(boolean open) {
    @StringRes int dialogMessageResId = open ? R.string.opening_msg : R.string.closing_msg;
    String errorMessage = getString(open ? R.string.issue_milestone_reopen_error : R.string.issue_milestone_close_error, mMilestone.title());
    IssueMilestoneService service = ServiceFactory.get(IssueMilestoneService.class, false);
    CreateMilestone request = CreateMilestone.builder().state(open ? IssueState.Open : IssueState.Closed).build();
    service.editMilestone(mRepoOwner, mRepoName, mMilestone.id(), request).map(ApiHelpers::throwOnFailure).compose(RxUtils.wrapForBackgroundTask(this, dialogMessageResId, errorMessage)).subscribe(result -> {
        mMilestone = result;
        updateHighlightColor();
        supportInvalidateOptionsMenu();
        setResult(RESULT_OK);
    }, error -> handleActionFailure("Updating milestone failed", error));
}
Also used : IssueMilestoneService(com.meisolsson.githubsdk.service.issues.IssueMilestoneService) StringRes(android.support.annotation.StringRes) CreateMilestone(com.meisolsson.githubsdk.model.request.issue.CreateMilestone) ApiHelpers(com.gh4a.utils.ApiHelpers)

Example 52 with ApiHelpers

use of com.gh4a.utils.ApiHelpers in project gh4a by slapperwan.

the class IssueMilestoneEditActivity method saveMilestone.

private void saveMilestone(String title, String desc) {
    String errorMessage = getString(R.string.issue_error_create_milestone, title);
    IssueMilestoneService service = ServiceFactory.get(IssueMilestoneService.class, false);
    CreateMilestone request = CreateMilestone.builder().title(title).description(desc).state(mMilestone.state()).dueOn(mMilestone.dueOn()).build();
    Single<Response<Milestone>> responseSingle = isInEditMode() ? service.editMilestone(mRepoOwner, mRepoName, mMilestone.id(), request) : service.createMilestone(mRepoOwner, mRepoName, request);
    responseSingle.map(ApiHelpers::throwOnFailure).compose(RxUtils.wrapForBackgroundTask(this, R.string.saving_msg, errorMessage)).subscribe(result -> {
        mMilestone = result;
        setResult(RESULT_OK);
        finish();
    }, error -> handleActionFailure("Saving milestone failed", error));
}
Also used : IssueMilestoneService(com.meisolsson.githubsdk.service.issues.IssueMilestoneService) Response(retrofit2.Response) CreateMilestone(com.meisolsson.githubsdk.model.request.issue.CreateMilestone) ApiHelpers(com.gh4a.utils.ApiHelpers)

Example 53 with ApiHelpers

use of com.gh4a.utils.ApiHelpers in project gh4a by slapperwan.

the class PullRequestActivity method mergePullRequest.

private void mergePullRequest(String commitMessage, MergeRequest.Method mergeMethod) {
    String errorMessage = getString(R.string.pull_error_merge, mPullRequest.number());
    PullRequestService service = ServiceFactory.get(PullRequestService.class, false);
    MergeRequest request = MergeRequest.builder().commitMessage(commitMessage).method(mergeMethod).build();
    service.mergePullRequest(mRepoOwner, mRepoName, mPullRequestNumber, request).map(ApiHelpers::throwOnFailure).compose(RxUtils.wrapForBackgroundTask(this, R.string.merging_msg, errorMessage)).subscribe(result -> {
        if (result.merged()) {
            mPullRequest = mPullRequest.toBuilder().merged(true).state(IssueState.Closed).build();
        }
        handlePullRequestUpdate();
    }, error -> handleActionFailure("Merging pull request failed", error));
}
Also used : PullRequestService(com.meisolsson.githubsdk.service.pull_request.PullRequestService) MergeRequest(com.meisolsson.githubsdk.model.request.pull_request.MergeRequest) ApiHelpers(com.gh4a.utils.ApiHelpers)

Example 54 with ApiHelpers

use of com.gh4a.utils.ApiHelpers 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 55 with ApiHelpers

use of com.gh4a.utils.ApiHelpers in project gh4a by slapperwan.

the class PullRequestDiffViewerActivity method addReaction.

@Override
public Single<Reaction> addReaction(ReactionBar.Item item, String content) {
    CommitCommentWrapper comment = (CommitCommentWrapper) item;
    ReactionService service = ServiceFactory.get(ReactionService.class, false);
    ReactionRequest request = ReactionRequest.builder().content(content).build();
    return service.createPullRequestReviewCommentReaction(mRepoOwner, mRepoName, comment.comment.id(), request).map(ApiHelpers::throwOnFailure);
}
Also used : ReactionRequest(com.meisolsson.githubsdk.model.request.ReactionRequest) ReactionService(com.meisolsson.githubsdk.service.reactions.ReactionService) ApiHelpers(com.gh4a.utils.ApiHelpers)

Aggregations

ApiHelpers (com.gh4a.utils.ApiHelpers)68 Response (retrofit2.Response)13 RxUtils (com.gh4a.utils.RxUtils)12 ServiceFactory (com.gh4a.ServiceFactory)11 Intent (android.content.Intent)10 Bundle (android.os.Bundle)10 Optional (com.gh4a.utils.Optional)10 PullRequestReviewCommentService (com.meisolsson.githubsdk.service.pull_request.PullRequestReviewCommentService)10 Single (io.reactivex.Single)9 Context (android.content.Context)7 LayoutInflater (android.view.LayoutInflater)7 CommentRequest (com.meisolsson.githubsdk.model.request.CommentRequest)7 List (java.util.List)7 View (android.view.View)6 R (com.gh4a.R)6 IntentUtils (com.gh4a.utils.IntentUtils)6 User (com.meisolsson.githubsdk.model.User)6 ReactionRequest (com.meisolsson.githubsdk.model.request.ReactionRequest)6 CreateReviewComment (com.meisolsson.githubsdk.model.request.pull_request.CreateReviewComment)6 ReactionService (com.meisolsson.githubsdk.service.reactions.ReactionService)6