use of com.fastaccess.data.dao.types.StatusStateType 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