Search in sources :

Example 6 with SpannableBuilder

use of com.fastaccess.ui.widgets.SpannableBuilder in project FastHub by k0shk0sh.

the class FeedsViewHolder method appendPushEvent.

private void appendPushEvent(SpannableBuilder spannableBuilder, Event eventsModel) {
    String ref = eventsModel.getPayload().getRef();
    if (ref.startsWith("refs/heads/")) {
        ref = ref.substring(11);
    }
    spannableBuilder.bold("pushed to").append(" ").append(ref).append(" ").bold("at").append(" ").append(eventsModel.getRepo().getName());
    final List<GitCommitModel> commits = eventsModel.getPayload().getCommits();
    int size = commits != null ? commits.size() : -1;
    SpannableBuilder spanCommits = SpannableBuilder.builder();
    if (size > 0) {
        if (size != 1)
            spanCommits.append(String.valueOf(eventsModel.getPayload().getSize())).append(" new commits").append("\n");
        else
            spanCommits.append("1 new commit").append("\n");
        int max = 5;
        int appended = 0;
        for (GitCommitModel commit : commits) {
            if (commit == null)
                continue;
            String sha = commit.getSha();
            if (TextUtils.isEmpty(sha))
                continue;
            sha = sha.length() > 7 ? sha.substring(0, 7) : sha;
            spanCommits.url(sha).append(" ").append(commit.getMessage() != null ? commit.getMessage().replaceAll("\\r?\\n|\\r", " ") : "").append("\n");
            appended++;
            if (appended == max)
                break;
        }
    }
    if (spanCommits.length() > 0) {
        int last = spanCommits.length();
        description.setMaxLines(5);
        description.setText(spanCommits.delete(last - 1, last));
        description.setVisibility(View.VISIBLE);
    } else {
        description.setText("");
        description.setMaxLines(2);
        description.setVisibility(View.GONE);
    }
}
Also used : SpannableBuilder(com.fastaccess.ui.widgets.SpannableBuilder) GitCommitModel(com.fastaccess.data.dao.GitCommitModel)

Example 7 with SpannableBuilder

use of com.fastaccess.ui.widgets.SpannableBuilder in project FastHub by k0shk0sh.

the class FeedsViewHolder method bind.

@Override
public void bind(@NonNull Event eventsModel) {
    appendAvatar(eventsModel);
    SpannableBuilder spannableBuilder = SpannableBuilder.builder();
    appendActor(eventsModel, spannableBuilder);
    description.setMaxLines(2);
    description.setText("");
    description.setVisibility(View.GONE);
    if (eventsModel.getType() != null) {
        EventsType type = eventsModel.getType();
        if (type == EventsType.WatchEvent) {
            appendWatch(spannableBuilder, type, eventsModel);
        } else if (type == EventsType.CreateEvent) {
            appendCreateEvent(spannableBuilder, eventsModel);
        } else if (type == EventsType.CommitCommentEvent) {
            appendCommitComment(spannableBuilder, eventsModel);
        } else if (type == EventsType.DownloadEvent) {
            appendDownloadEvent(spannableBuilder, eventsModel);
        } else if (type == EventsType.FollowEvent) {
            appendFollowEvent(spannableBuilder, eventsModel);
        } else if (type == EventsType.ForkEvent) {
            appendForkEvent(spannableBuilder, eventsModel);
        } else if (type == EventsType.GistEvent) {
            appendGistEvent(spannableBuilder, eventsModel);
        } else if (type == EventsType.GollumEvent) {
            appendGollumEvent(spannableBuilder, eventsModel);
        } else if (type == EventsType.IssueCommentEvent) {
            appendIssueCommentEvent(spannableBuilder, eventsModel);
        } else if (type == EventsType.IssuesEvent) {
            appendIssueEvent(spannableBuilder, eventsModel);
        } else if (type == EventsType.MemberEvent) {
            appendMemberEvent(spannableBuilder, eventsModel);
        } else if (type == EventsType.PublicEvent) {
            appendPublicEvent(spannableBuilder, eventsModel);
        } else if (type == EventsType.PullRequestEvent) {
            appendPullRequestEvent(spannableBuilder, eventsModel);
        } else if (type == EventsType.PullRequestReviewCommentEvent) {
            appendPullRequestReviewCommentEvent(spannableBuilder, eventsModel);
        } else if (type == EventsType.PullRequestReviewEvent) {
            appendPullRequestReviewCommentEvent(spannableBuilder, eventsModel);
        } else if (type == EventsType.RepositoryEvent) {
            appendPublicEvent(spannableBuilder, eventsModel);
        } else if (type == EventsType.PushEvent) {
            appendPushEvent(spannableBuilder, eventsModel);
        } else if (type == EventsType.TeamAddEvent) {
            appendTeamEvent(spannableBuilder, eventsModel);
        } else if (type == EventsType.DeleteEvent) {
            appendDeleteEvent(spannableBuilder, eventsModel);
        } else if (type == EventsType.ReleaseEvent) {
            appendReleaseEvent(spannableBuilder, eventsModel);
        } else if (type == EventsType.ForkApplyEvent) {
            appendForkApplyEvent(spannableBuilder, eventsModel);
        } else if (type == EventsType.OrgBlockEvent) {
            appendOrgBlockEvent(spannableBuilder, eventsModel);
        } else if (type == EventsType.ProjectCardEvent) {
            appendProjectCardEvent(spannableBuilder, eventsModel, false);
        } else if (type == EventsType.ProjectColumnEvent) {
            appendProjectCardEvent(spannableBuilder, eventsModel, true);
        } else if (type == EventsType.OrganizationEvent) {
            appendOrganizationEvent(spannableBuilder, eventsModel);
        } else if (type == EventsType.ProjectEvent) {
            appendProjectCardEvent(spannableBuilder, eventsModel, false);
        }
        date.setGravity(Gravity.CENTER);
        date.setEventsIcon(type.getDrawableRes());
    }
    title.setText(spannableBuilder);
    date.setText(ParseDateFormat.getTimeAgo(eventsModel.getCreatedAt()));
}
Also used : SpannableBuilder(com.fastaccess.ui.widgets.SpannableBuilder) EventsType(com.fastaccess.data.dao.types.EventsType)

Example 8 with SpannableBuilder

use of com.fastaccess.ui.widgets.SpannableBuilder in project FastHub by k0shk0sh.

the class IssueDetailsViewHolder method setupLabels.

private void setupLabels(@Nullable List<LabelModel> labelList) {
    if (labelList != null && !labelList.isEmpty()) {
        SpannableBuilder builder = SpannableBuilder.builder();
        for (LabelModel labelModel : labelList) {
            int color = Color.parseColor("#" + labelModel.getColor());
            builder.append(" ").append(" " + labelModel.getName() + " ", new LabelSpan(color));
        }
        labels.setText(builder);
        labelsHolder.setVisibility(View.VISIBLE);
    } else {
        labels.setText("");
        labelsHolder.setVisibility(View.GONE);
    }
}
Also used : LabelModel(com.fastaccess.data.dao.LabelModel) SpannableBuilder(com.fastaccess.ui.widgets.SpannableBuilder) LabelSpan(com.fastaccess.ui.widgets.LabelSpan)

Example 9 with SpannableBuilder

use of com.fastaccess.ui.widgets.SpannableBuilder 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)

Example 10 with SpannableBuilder

use of com.fastaccess.ui.widgets.SpannableBuilder in project FastHub by k0shk0sh.

the class CreateIssueActivity method onSelectedLabels.

@Override
public void onSelectedLabels(@NonNull ArrayList<LabelModel> labelModels) {
    this.labelModels.clear();
    this.labelModels.addAll(labelModels);
    SpannableBuilder builder = SpannableBuilder.builder();
    for (int i = 0; i < labelModels.size(); i++) {
        LabelModel labelModel = labelModels.get(i);
        int color = Color.parseColor("#" + labelModel.getColor());
        if (i > 0) {
            builder.append(" ").append(" " + labelModel.getName() + " ", new LabelSpan(color));
        } else {
            builder.append(labelModel.getName() + " ", new LabelSpan(color));
        }
    }
    this.labels.setText(builder);
}
Also used : LabelModel(com.fastaccess.data.dao.LabelModel) SpannableBuilder(com.fastaccess.ui.widgets.SpannableBuilder) LabelSpan(com.fastaccess.ui.widgets.LabelSpan)

Aggregations

SpannableBuilder (com.fastaccess.ui.widgets.SpannableBuilder)12 NonNull (android.support.annotation.NonNull)4 LabelModel (com.fastaccess.data.dao.LabelModel)4 User (com.fastaccess.data.dao.model.User)3 LabelSpan (com.fastaccess.ui.widgets.LabelSpan)3 PullsIssuesParser (com.fastaccess.data.dao.PullsIssuesParser)2 Bundle (android.os.Bundle)1 ContextCompat (android.support.v4.content.ContextCompat)1 LinkMovementMethod (android.text.method.LinkMovementMethod)1 BackgroundColorSpan (android.text.style.BackgroundColorSpan)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 FilesListModel (com.fastaccess.data.dao.FilesListModel)1 GitCommitModel (com.fastaccess.data.dao.GitCommitModel)1 MilestoneModel (com.fastaccess.data.dao.MilestoneModel)1 PullRequestStatusModel (com.fastaccess.data.dao.PullRequestStatusModel)1