Search in sources :

Example 1 with StatusStateType

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);
    }
}
Also used : PullRequestStatusModel(com.fastaccess.data.dao.PullRequestStatusModel) BaseViewHolder(com.fastaccess.ui.widgets.recyclerview.BaseViewHolder) Stream(com.annimon.stream.Stream) ContextCompat(android.support.v4.content.ContextCompat) InputHelper(com.fastaccess.helper.InputHelper) BindColor(butterknife.BindColor) NonNull(android.support.annotation.NonNull) LinkMovementMethod(android.text.method.LinkMovementMethod) ViewGroup(android.view.ViewGroup) SchemeParser(com.fastaccess.provider.scheme.SchemeParser) SpannableBuilder(com.fastaccess.ui.widgets.SpannableBuilder) BindView(butterknife.BindView) StatusStateType(com.fastaccess.data.dao.types.StatusStateType) ForegroundImageView(com.fastaccess.ui.widgets.ForegroundImageView) R(com.fastaccess.R) FontTextView(com.fastaccess.ui.widgets.FontTextView) View(android.view.View) StatusStateType(com.fastaccess.data.dao.types.StatusStateType) SpannableBuilder(com.fastaccess.ui.widgets.SpannableBuilder)

Aggregations

NonNull (android.support.annotation.NonNull)1 ContextCompat (android.support.v4.content.ContextCompat)1 LinkMovementMethod (android.text.method.LinkMovementMethod)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 BindColor (butterknife.BindColor)1 BindView (butterknife.BindView)1 Stream (com.annimon.stream.Stream)1 R (com.fastaccess.R)1 PullRequestStatusModel (com.fastaccess.data.dao.PullRequestStatusModel)1 StatusStateType (com.fastaccess.data.dao.types.StatusStateType)1 InputHelper (com.fastaccess.helper.InputHelper)1 SchemeParser (com.fastaccess.provider.scheme.SchemeParser)1 FontTextView (com.fastaccess.ui.widgets.FontTextView)1 ForegroundImageView (com.fastaccess.ui.widgets.ForegroundImageView)1 SpannableBuilder (com.fastaccess.ui.widgets.SpannableBuilder)1 BaseViewHolder (com.fastaccess.ui.widgets.recyclerview.BaseViewHolder)1