use of com.fastaccess.data.dao.PullRequestStatusModel 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.PullRequestStatusModel in project FastHub by k0shk0sh.
the class PullStatusViewHolder method bind.
@Override
public void bind(@NonNull PullRequestStatusModel pullRequestStatusModel) {
if (pullRequestStatusModel.getState() != null) {
StatusStateType stateType = pullRequestStatusModel.getState();
stateImage.setImageResource(stateType.getDrawableRes());
String mergeableState = pullRequestStatusModel.getMergeableState();
boolean isBlocked = "blocked".equalsIgnoreCase(mergeableState);
if (stateType == StatusStateType.failure) {
stateImage.tintDrawableColor(red);
if (pullRequestStatusModel.isMergable()) {
status.setText(R.string.checks_failed);
} else {
status.setText(SpannableBuilder.builder().append(status.getResources().getString(R.string.checks_failed)).append("\n").append(status.getResources().getString(R.string.can_not_merge_pr)));
}
} else if (stateType == StatusStateType.pending) {
if (pullRequestStatusModel.isMergable()) {
stateImage.setImageResource(R.drawable.ic_check_small);
stateImage.tintDrawableColor(green);
status.setText(!isBlocked ? R.string.commit_can_be_merged : R.string.can_not_merge_pr);
} else {
stateImage.setImageResource(stateType.getDrawableRes());
stateImage.tintDrawableColor(indigo);
status.setText(R.string.checks_pending);
}
} else {
stateImage.tintDrawableColor(green);
if (pullRequestStatusModel.isMergable()) {
status.setText(!isBlocked ? R.string.commit_can_be_merged : R.string.can_not_merge_pr);
} else {
status.setText(R.string.checks_passed);
}
}
}
if (pullRequestStatusModel.getStatuses() != null && !pullRequestStatusModel.getStatuses().isEmpty()) {
SpannableBuilder builder = SpannableBuilder.builder();
Stream.of(pullRequestStatusModel.getStatuses()).filter(statusesModel -> statusesModel != null && statusesModel.getState() != null && statusesModel.getTargetUrl() != null).forEach(statusesModel -> {
if (!InputHelper.isEmpty(statusesModel.getTargetUrl())) {
builder.append(ContextCompat.getDrawable(statuses.getContext(), statusesModel.getState().getDrawableRes()));
builder.append(" ").append(statusesModel.getContext() != null ? statusesModel.getContext() + " " : "").url(statusesModel.getDescription(), v -> SchemeParser.launchUri(v.getContext(), statusesModel.getTargetUrl())).append("\n");
}
});
if (!InputHelper.isEmpty(builder)) {
statuses.setMovementMethod(LinkMovementMethod.getInstance());
statuses.setText(builder);
statuses.setVisibility(View.VISIBLE);
} else {
statuses.setVisibility(View.GONE);
}
} else {
statuses.setVisibility(View.GONE);
}
}
Aggregations