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;
}
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);
}
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))));
}
}
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);
}
}
}
}
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();
}
}
}
}
Aggregations