Search in sources :

Example 1 with IssueRequestModel

use of com.fastaccess.data.dao.IssueRequestModel in project FastHub by k0shk0sh.

the class PullRequestPagerPresenter method onOpenCloseIssue.

@Override
public void onOpenCloseIssue() {
    if (getPullRequest() != null) {
        IssueRequestModel requestModel = IssueRequestModel.clone(getPullRequest(), true);
        manageDisposable(RxHelper.getObservable(RestProvider.getPullRequestService(isEnterprise()).editPullRequest(login, repoId, issueNumber, requestModel)).doOnSubscribe(disposable -> sendToView(view -> view.showProgress(0))).subscribe(issue -> {
            if (issue != null) {
                sendToView(view -> view.showSuccessIssueActionMsg(getPullRequest().getState() == IssueState.open));
                issue.setRepoId(getPullRequest().getRepoId());
                issue.setLogin(getPullRequest().getLogin());
                pullRequest = issue;
                sendToView(view -> view.onSetupIssue(false));
            }
        }, throwable -> sendToView(view -> view.showErrorIssueActionMsg(getPullRequest().getState() == IssueState.open))));
    }
}
Also used : Context(android.content.Context) Bundle(android.os.Bundle) Stream(com.annimon.stream.Stream) IssueRequestModel(com.fastaccess.data.dao.IssueRequestModel) IssueState(com.fastaccess.data.dao.types.IssueState) InputHelper(com.fastaccess.helper.InputHelper) Intent(android.content.Intent) NonNull(android.support.annotation.NonNull) Response(retrofit2.Response) ArrayList(java.util.ArrayList) RxHelper(com.fastaccess.helper.RxHelper) MilestoneModel(com.fastaccess.data.dao.MilestoneModel) LabelListModel(com.fastaccess.data.dao.LabelListModel) PinnedPullRequests(com.fastaccess.data.dao.model.PinnedPullRequests) Observable(io.reactivex.Observable) User(com.fastaccess.data.dao.model.User) BasePresenter(com.fastaccess.ui.base.mvp.presenter.BasePresenter) BundleConstant(com.fastaccess.helper.BundleConstant) CommentRequestModel(com.fastaccess.data.dao.CommentRequestModel) Login(com.fastaccess.data.dao.model.Login) RestProvider(com.fastaccess.provider.rest.RestProvider) Collectors(com.annimon.stream.Collectors) BaseMvp(com.fastaccess.ui.base.mvp.BaseMvp) IssueService(com.fastaccess.data.service.IssueService) AssigneesRequestModel(com.fastaccess.data.dao.AssigneesRequestModel) NotificationSubscriptionBodyModel(com.fastaccess.data.dao.NotificationSubscriptionBodyModel) LabelModel(com.fastaccess.data.dao.LabelModel) TextUtils(android.text.TextUtils) PullsIssuesParser(com.fastaccess.data.dao.PullsIssuesParser) SpannableBuilder(com.fastaccess.ui.widgets.SpannableBuilder) LockIssuePrModel(com.fastaccess.data.dao.LockIssuePrModel) PullRequest(com.fastaccess.data.dao.model.PullRequest) R(com.fastaccess.R) UsersListModel(com.fastaccess.data.dao.UsersListModel) Nullable(android.support.annotation.Nullable) MergeRequestModel(com.fastaccess.data.dao.MergeRequestModel) IssueRequestModel(com.fastaccess.data.dao.IssueRequestModel)

Example 2 with IssueRequestModel

use of com.fastaccess.data.dao.IssueRequestModel in project FastHub by k0shk0sh.

the class CreateIssuePresenter method onSubmit.

@Override
public void onSubmit(@NonNull String title, @NonNull CharSequence description, @NonNull String login, @NonNull String repo, @Nullable Issue issue, @Nullable PullRequest pullRequestModel, @Nullable ArrayList<LabelModel> labels, @Nullable MilestoneModel milestoneModel, @Nullable ArrayList<User> users) {
    boolean isEmptyTitle = InputHelper.isEmpty(title);
    if (getView() != null) {
        getView().onTitleError(isEmptyTitle);
    }
    if (!isEmptyTitle) {
        if (issue == null && pullRequestModel == null) {
            CreateIssueModel createIssue = new CreateIssueModel();
            createIssue.setBody(InputHelper.toString(description));
            createIssue.setTitle(title);
            if (isCollaborator) {
                if (labels != null && !labels.isEmpty()) {
                    createIssue.setLabels(Stream.of(labels).map(LabelModel::getName).collect(Collectors.toCollection(ArrayList::new)));
                }
                if (users != null && !users.isEmpty()) {
                    createIssue.setAssignees(Stream.of(users).map(User::getLogin).collect(Collectors.toCollection(ArrayList::new)));
                }
                if (milestoneModel != null) {
                    createIssue.setMilestone((long) milestoneModel.getNumber());
                }
            }
            makeRestCall(RestProvider.getIssueService(isEnterprise()).createIssue(login, repo, createIssue), issueModel -> {
                if (issueModel != null) {
                    sendToView(view -> view.onSuccessSubmission(issueModel));
                } else {
                    sendToView(view -> view.showMessage(R.string.error, R.string.error_creating_issue));
                }
            }, false);
        } else {
            if (issue != null) {
                issue.setBody(InputHelper.toString(description));
                issue.setTitle(title);
                int number = issue.getNumber();
                if (isCollaborator) {
                    if (labels != null) {
                        LabelListModel labelModels = new LabelListModel();
                        labelModels.addAll(labels);
                        issue.setLabels(labelModels);
                    }
                    if (milestoneModel != null) {
                        issue.setMilestone(milestoneModel);
                    }
                    if (users != null) {
                        UsersListModel usersListModel = new UsersListModel();
                        usersListModel.addAll(users);
                        issue.setAssignees(usersListModel);
                    }
                }
                IssueRequestModel requestModel = IssueRequestModel.clone(issue, false);
                makeRestCall(RestProvider.getIssueService(isEnterprise()).editIssue(login, repo, number, requestModel), issueModel -> {
                    if (issueModel != null) {
                        sendToView(view -> view.onSuccessSubmission(issueModel));
                    } else {
                        sendToView(view -> view.showMessage(R.string.error, R.string.error_creating_issue));
                    }
                }, false);
            }
            if (pullRequestModel != null) {
                int number = pullRequestModel.getNumber();
                pullRequestModel.setBody(InputHelper.toString(description));
                pullRequestModel.setTitle(title);
                if (isCollaborator) {
                    if (labels != null) {
                        LabelListModel labelModels = new LabelListModel();
                        labelModels.addAll(labels);
                        pullRequestModel.setLabels(labelModels);
                    }
                    if (milestoneModel != null) {
                        pullRequestModel.setMilestone(milestoneModel);
                    }
                    if (users != null) {
                        UsersListModel usersListModel = new UsersListModel();
                        usersListModel.addAll(users);
                        pullRequestModel.setAssignees(usersListModel);
                    }
                }
                IssueRequestModel requestModel = IssueRequestModel.clone(pullRequestModel, false);
                makeRestCall(RestProvider.getPullRequestService(isEnterprise()).editPullRequest(login, repo, number, requestModel).flatMap(pullRequest1 -> RestProvider.getIssueService(isEnterprise()).getIssue(login, repo, number), (pullRequest1, issueReaction) -> {
                    // hack to get reactions from issue api
                    if (issueReaction != null) {
                        pullRequest1.setReactions(issueReaction.getReactions());
                    }
                    return pullRequest1;
                }), pr -> {
                    if (pr != null) {
                        sendToView(view -> view.onSuccessSubmission(pr));
                    } else {
                        sendToView(view -> view.showMessage(R.string.error, R.string.error_creating_issue));
                    }
                }, false);
            }
        }
    }
}
Also used : Stream(com.annimon.stream.Stream) IssueRequestModel(com.fastaccess.data.dao.IssueRequestModel) InputHelper(com.fastaccess.helper.InputHelper) Intent(android.content.Intent) NonNull(android.support.annotation.NonNull) Issue(com.fastaccess.data.dao.model.Issue) ArrayList(java.util.ArrayList) RxHelper(com.fastaccess.helper.RxHelper) MilestoneModel(com.fastaccess.data.dao.MilestoneModel) LabelListModel(com.fastaccess.data.dao.LabelListModel) User(com.fastaccess.data.dao.model.User) BasePresenter(com.fastaccess.ui.base.mvp.presenter.BasePresenter) BundleConstant(com.fastaccess.helper.BundleConstant) Login(com.fastaccess.data.dao.model.Login) RestProvider(com.fastaccess.provider.rest.RestProvider) Collectors(com.annimon.stream.Collectors) BaseMvp(com.fastaccess.ui.base.mvp.BaseMvp) CreateIssueModel(com.fastaccess.data.dao.CreateIssueModel) LabelModel(com.fastaccess.data.dao.LabelModel) PullRequest(com.fastaccess.data.dao.model.PullRequest) R(com.fastaccess.R) BuildConfig(com.fastaccess.BuildConfig) UsersListModel(com.fastaccess.data.dao.UsersListModel) Nullable(android.support.annotation.Nullable) Activity(android.app.Activity) User(com.fastaccess.data.dao.model.User) IssueRequestModel(com.fastaccess.data.dao.IssueRequestModel) UsersListModel(com.fastaccess.data.dao.UsersListModel) LabelModel(com.fastaccess.data.dao.LabelModel) LabelListModel(com.fastaccess.data.dao.LabelListModel) CreateIssueModel(com.fastaccess.data.dao.CreateIssueModel) ArrayList(java.util.ArrayList)

Example 3 with IssueRequestModel

use of com.fastaccess.data.dao.IssueRequestModel in project FastHub by k0shk0sh.

the class IssuePagerPresenter method onOpenCloseIssue.

@Override
public void onOpenCloseIssue() {
    Issue currentIssue = getIssue();
    if (currentIssue != null) {
        IssueRequestModel requestModel = IssueRequestModel.clone(currentIssue, true);
        manageDisposable(RxHelper.getObservable(RestProvider.getIssueService(isEnterprise()).editIssue(login, repoId, issueNumber, requestModel)).doOnSubscribe(disposable -> sendToView(view -> view.showProgress(0))).subscribe(issue -> {
            if (issue != null) {
                sendToView(view -> view.showSuccessIssueActionMsg(currentIssue.getState() == IssueState.open));
                issue.setRepoId(issueModel.getRepoId());
                issue.setLogin(issueModel.getLogin());
                issueModel = issue;
                sendToView(view -> view.onSetupIssue(false));
            }
        }, this::onError));
    }
}
Also used : Bundle(android.os.Bundle) Stream(com.annimon.stream.Stream) IssueRequestModel(com.fastaccess.data.dao.IssueRequestModel) IssueState(com.fastaccess.data.dao.types.IssueState) InputHelper(com.fastaccess.helper.InputHelper) Intent(android.content.Intent) NonNull(android.support.annotation.NonNull) Issue(com.fastaccess.data.dao.model.Issue) Response(retrofit2.Response) ArrayList(java.util.ArrayList) RxHelper(com.fastaccess.helper.RxHelper) MilestoneModel(com.fastaccess.data.dao.MilestoneModel) LabelListModel(com.fastaccess.data.dao.LabelListModel) Observable(io.reactivex.Observable) User(com.fastaccess.data.dao.model.User) BasePresenter(com.fastaccess.ui.base.mvp.presenter.BasePresenter) BundleConstant(com.fastaccess.helper.BundleConstant) Login(com.fastaccess.data.dao.model.Login) RestProvider(com.fastaccess.provider.rest.RestProvider) Collectors(com.annimon.stream.Collectors) BaseMvp(com.fastaccess.ui.base.mvp.BaseMvp) PinnedIssues(com.fastaccess.data.dao.model.PinnedIssues) IssueService(com.fastaccess.data.service.IssueService) AssigneesRequestModel(com.fastaccess.data.dao.AssigneesRequestModel) NotificationSubscriptionBodyModel(com.fastaccess.data.dao.NotificationSubscriptionBodyModel) LabelModel(com.fastaccess.data.dao.LabelModel) TextUtils(android.text.TextUtils) Logger(com.fastaccess.helper.Logger) PullsIssuesParser(com.fastaccess.data.dao.PullsIssuesParser) LockIssuePrModel(com.fastaccess.data.dao.LockIssuePrModel) R(com.fastaccess.R) UsersListModel(com.fastaccess.data.dao.UsersListModel) Nullable(android.support.annotation.Nullable) Issue(com.fastaccess.data.dao.model.Issue) IssueRequestModel(com.fastaccess.data.dao.IssueRequestModel)

Example 4 with IssueRequestModel

use of com.fastaccess.data.dao.IssueRequestModel in project FastHub by k0shk0sh.

the class IssuePagerPresenter method onPutMilestones.

@Override
public void onPutMilestones(@NonNull MilestoneModel milestone) {
    issueModel.setMilestone(milestone);
    IssueRequestModel issueRequestModel = IssueRequestModel.clone(issueModel, false);
    makeRestCall(RestProvider.getIssueService(isEnterprise()).editIssue(login, repoId, issueNumber, issueRequestModel), issue -> {
        this.issueModel.setMilestone(issue.getMilestone());
        manageObservable(issue.save(issueModel).toObservable());
        sendToView(view -> updateTimeline(view, R.string.labels_added_successfully));
    });
}
Also used : IssueRequestModel(com.fastaccess.data.dao.IssueRequestModel)

Example 5 with IssueRequestModel

use of com.fastaccess.data.dao.IssueRequestModel in project FastHub by k0shk0sh.

the class PullRequestPagerPresenter method onPutMilestones.

@Override
public void onPutMilestones(@NonNull MilestoneModel milestone) {
    pullRequest.setMilestone(milestone);
    IssueRequestModel issueRequestModel = IssueRequestModel.clone(pullRequest, false);
    makeRestCall(RestProvider.getPullRequestService(isEnterprise()).editIssue(login, repoId, issueNumber, issueRequestModel), pr -> {
        this.pullRequest.setMilestone(pr.getMilestone());
        manageObservable(pr.save(pullRequest).toObservable());
        sendToView(view -> updateTimeline(view, R.string.labels_added_successfully));
    });
}
Also used : IssueRequestModel(com.fastaccess.data.dao.IssueRequestModel)

Aggregations

IssueRequestModel (com.fastaccess.data.dao.IssueRequestModel)5 Intent (android.content.Intent)3 NonNull (android.support.annotation.NonNull)3 Nullable (android.support.annotation.Nullable)3 Collectors (com.annimon.stream.Collectors)3 Stream (com.annimon.stream.Stream)3 R (com.fastaccess.R)3 LabelListModel (com.fastaccess.data.dao.LabelListModel)3 LabelModel (com.fastaccess.data.dao.LabelModel)3 MilestoneModel (com.fastaccess.data.dao.MilestoneModel)3 UsersListModel (com.fastaccess.data.dao.UsersListModel)3 Login (com.fastaccess.data.dao.model.Login)3 User (com.fastaccess.data.dao.model.User)3 BundleConstant (com.fastaccess.helper.BundleConstant)3 InputHelper (com.fastaccess.helper.InputHelper)3 RxHelper (com.fastaccess.helper.RxHelper)3 RestProvider (com.fastaccess.provider.rest.RestProvider)3 BaseMvp (com.fastaccess.ui.base.mvp.BaseMvp)3 BasePresenter (com.fastaccess.ui.base.mvp.presenter.BasePresenter)3 ArrayList (java.util.ArrayList)3