Search in sources :

Example 6 with PullRequest

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

the class PullRequestTimelinePresenter method onCallApi.

@Override
public boolean onCallApi(int page, @Nullable PullRequest parameter) {
    if (parameter == null) {
        sendToView(BaseMvp.FAView::hideProgress);
        return false;
    }
    String login = parameter.getLogin();
    String repoId = parameter.getRepoId();
    int number = parameter.getNumber();
    if (page <= 1) {
        lastPage = Integer.MAX_VALUE;
        sendToView(view -> view.getLoadMore().reset());
        pages.clear();
    }
    if (page > lastPage || lastPage == 0) {
        sendToView(PullRequestTimelineMvp.View::hideProgress);
        return false;
    }
    if (page == 1) {
        manageObservable(RestProvider.getRepoService(isEnterprise()).isCollaborator(login, repoId, Login.getUser().getLogin()).doOnNext(booleanResponse -> isCollaborator = booleanResponse.code() == 204));
    }
    setCurrentPage(page);
    if (parameter.getHead() != null) {
        Observable<List<TimelineModel>> observable = Observable.zip(RestProvider.getIssueService(isEnterprise()).getTimeline(login, repoId, number, page), RestProvider.getReviewService(isEnterprise()).getPrReviewComments(login, repoId, number), RestProvider.getPullRequestService(isEnterprise()).getPullStatus(login, repoId, parameter.getHead().getSha()).onErrorReturn(throwable -> RestProvider.getPullRequestService(isEnterprise()).getPullStatus(login, repoId, parameter.getBase().getSha()).blockingFirst(new PullRequestStatusModel())), (response, comments, status) -> {
            if (response != null) {
                lastPage = response.getLast();
                List<TimelineModel> models = TimelineConverter.INSTANCE.convert(response.getItems(), comments);
                if (page == 1 && status != null) {
                    status.setMergable(parameter.isMergeable());
                    status.setMergeableState(parameter.getMergeableState());
                    if (status.getState() != null) {
                        models.add(0, new TimelineModel(status));
                    }
                }
                return models;
            } else {
                return Collections.emptyList();
            }
        });
        makeRestCall(observable, timeline -> sendToView(view -> view.onNotifyAdapter(timeline, page)));
        return true;
    }
    return false;
}
Also used : PullRequestStatusModel(com.fastaccess.data.dao.PullRequestStatusModel) Comment(com.fastaccess.data.dao.model.Comment) GenericEvent(com.fastaccess.data.dao.timeline.GenericEvent) Bundle(android.os.Bundle) SourceModel(com.fastaccess.data.dao.timeline.SourceModel) ActivityHelper(com.fastaccess.helper.ActivityHelper) TimelineModel(com.fastaccess.data.dao.TimelineModel) CommentsHelper(com.fastaccess.provider.timeline.CommentsHelper) Uri(android.net.Uri) InputHelper(com.fastaccess.helper.InputHelper) NonNull(android.support.annotation.NonNull) CreateIssueActivity(com.fastaccess.ui.modules.repos.issues.create.CreateIssueActivity) SchemeParser(com.fastaccess.provider.scheme.SchemeParser) ArrayList(java.util.ArrayList) RxHelper(com.fastaccess.helper.RxHelper) PopupMenu(android.widget.PopupMenu) EditReviewCommentModel(com.fastaccess.data.dao.EditReviewCommentModel) View(android.view.View) Observable(io.reactivex.Observable) ReactionTypes(com.fastaccess.data.dao.types.ReactionTypes) 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) GroupedReviewModel(com.fastaccess.data.dao.GroupedReviewModel) BaseMvp(com.fastaccess.ui.base.mvp.BaseMvp) ReactionsProvider(com.fastaccess.provider.timeline.ReactionsProvider) SparseArray(android.util.SparseArray) List(java.util.List) PullRequest(com.fastaccess.data.dao.model.PullRequest) IssueEventType(com.fastaccess.data.dao.types.IssueEventType) R(com.fastaccess.R) FilterIssuesActivity(com.fastaccess.ui.modules.filter.issues.FilterIssuesActivity) ReviewCommentModel(com.fastaccess.data.dao.ReviewCommentModel) TimelineConverter(com.fastaccess.provider.timeline.TimelineConverter) Nullable(android.support.annotation.Nullable) Activity(android.app.Activity) Collections(java.util.Collections) PullRequestStatusModel(com.fastaccess.data.dao.PullRequestStatusModel) ArrayList(java.util.ArrayList) List(java.util.List) View(android.view.View) TimelineModel(com.fastaccess.data.dao.TimelineModel)

Example 7 with PullRequest

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

the class PullRequestPagerActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
        onNavToRepoClicked();
        return true;
    }
    PullRequest pullRequest = getPresenter().getPullRequest();
    if (pullRequest == null)
        return false;
    if (item.getItemId() == R.id.share) {
        ActivityHelper.shareUrl(this, pullRequest.getHtmlUrl());
        return true;
    } else if (item.getItemId() == R.id.closeIssue) {
        MessageDialogView.newInstance(pullRequest.getState() == IssueState.open ? getString(R.string.close_issue) : getString(R.string.re_open_issue), getString(R.string.confirm_message), Bundler.start().put(BundleConstant.EXTRA, true).end()).show(getSupportFragmentManager(), MessageDialogView.TAG);
        return true;
    } else if (item.getItemId() == R.id.lockIssue) {
        if (!getPresenter().isLocked()) {
            LockIssuePrBottomSheetDialog.Companion.newInstance().show(getSupportFragmentManager(), MessageDialogView.TAG);
        } else {
            MessageDialogView.newInstance(getString(R.string.unlock_issue), getString(R.string.unlock_issue_details), Bundler.start().put(BundleConstant.EXTRA_TWO, true).put(BundleConstant.YES_NO_EXTRA, true).end()).show(getSupportFragmentManager(), MessageDialogView.TAG);
        }
        return true;
    } else if (item.getItemId() == R.id.labels) {
        LabelsDialogFragment.newInstance(getPresenter().getPullRequest() != null ? getPresenter().getPullRequest().getLabels() : null, getPresenter().getRepoId(), getPresenter().getLogin()).show(getSupportFragmentManager(), "LabelsDialogFragment");
        return true;
    } else if (item.getItemId() == R.id.edit) {
        CreateIssueActivity.startForResult(this, getPresenter().getLogin(), getPresenter().getRepoId(), pullRequest, isEnterprise());
        return true;
    } else if (item.getItemId() == R.id.milestone) {
        MilestoneDialogFragment.newInstance(getPresenter().getLogin(), getPresenter().getRepoId()).show(getSupportFragmentManager(), "MilestoneDialogFragment");
        return true;
    } else if (item.getItemId() == R.id.assignees) {
        AssigneesDialogFragment.newInstance(getPresenter().getLogin(), getPresenter().getRepoId(), true).show(getSupportFragmentManager(), "AssigneesDialogFragment");
        return true;
    } else if (item.getItemId() == R.id.reviewers) {
        AssigneesDialogFragment.newInstance(getPresenter().getLogin(), getPresenter().getRepoId(), false).show(getSupportFragmentManager(), "AssigneesDialogFragment");
        return true;
    } else if (item.getItemId() == R.id.merge) {
        if (getPresenter().getPullRequest() != null) {
            String msg = getPresenter().getPullRequest().getTitle();
            MergePullRequestDialogFragment.newInstance(msg).show(getSupportFragmentManager(), "MergePullRequestDialogFragment");
        }
    } else if (item.getItemId() == R.id.browser) {
        ActivityHelper.startCustomTab(this, pullRequest.getHtmlUrl());
        return true;
    } else if (item.getItemId() == R.id.reviewChanges) {
        if (PrefGetter.isProEnabled()) {
            addPrReview(item.getActionView() == null ? title : item.getActionView());
        } else {
            PremiumActivity.Companion.startActivity(this);
        }
        return true;
    } else if (item.getItemId() == R.id.subscribe) {
        getPresenter().onSubscribeOrMute(false);
        return true;
    } else if (item.getItemId() == R.id.mute) {
        getPresenter().onSubscribeOrMute(true);
        return true;
    } else if (item.getItemId() == R.id.pinUnpin) {
        if (PrefGetter.isProEnabled()) {
            getPresenter().onPinUnpinPullRequest();
        } else {
            PremiumActivity.Companion.startActivity(this);
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
}
Also used : PullRequest(com.fastaccess.data.dao.model.PullRequest)

Example 8 with PullRequest

use of com.fastaccess.data.dao.model.PullRequest 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 9 with PullRequest

use of com.fastaccess.data.dao.model.PullRequest 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 10 with PullRequest

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

the class PullRequestPagerActivity method onActivityResult.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {
        if (requestCode == BundleConstant.REQUEST_CODE) {
            if (data == null)
                return;
            Bundle bundle = data.getExtras();
            PullRequest pullRequest = bundle.getParcelable(BundleConstant.ITEM);
            if (pullRequest != null) {
                getPresenter().onUpdatePullRequest(pullRequest);
            } else {
                getPresenter().onRefresh();
            }
        }
    }
}
Also used : Bundle(android.os.Bundle) PullRequest(com.fastaccess.data.dao.model.PullRequest)

Aggregations

PullRequest (com.fastaccess.data.dao.model.PullRequest)20 Bundle (android.os.Bundle)7 NonNull (android.support.annotation.NonNull)6 Nullable (android.support.annotation.Nullable)6 R (com.fastaccess.R)6 Login (com.fastaccess.data.dao.model.Login)6 BundleConstant (com.fastaccess.helper.BundleConstant)6 InputHelper (com.fastaccess.helper.InputHelper)6 RxHelper (com.fastaccess.helper.RxHelper)6 RestProvider (com.fastaccess.provider.rest.RestProvider)6 BaseMvp (com.fastaccess.ui.base.mvp.BaseMvp)6 BasePresenter (com.fastaccess.ui.base.mvp.presenter.BasePresenter)6 Observable (io.reactivex.Observable)6 ArrayList (java.util.ArrayList)6 Activity (android.app.Activity)5 CommentRequestModel (com.fastaccess.data.dao.CommentRequestModel)5 Comment (com.fastaccess.data.dao.model.Comment)5 PopupMenu (android.widget.PopupMenu)4 EditReviewCommentModel (com.fastaccess.data.dao.EditReviewCommentModel)4 GroupedReviewModel (com.fastaccess.data.dao.GroupedReviewModel)4