Search in sources :

Example 1 with SpannableBuilder

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

the class CommentsHelper method appendEmojies.

public static void appendEmojies(@NonNull ReactionsModel reaction, @NonNull TextView thumbsUp, @NonNull TextView thumbsUpReaction, @NonNull TextView thumbsDown, @NonNull TextView thumbsDownReaction, @NonNull TextView hurray, @NonNull TextView hurrayReaction, @NonNull TextView sad, @NonNull TextView sadReaction, @NonNull TextView laugh, @NonNull TextView laughReaction, @NonNull TextView heart, @NonNull TextView heartReaction, @NonNull View reactionsList) {
    SpannableBuilder spannableBuilder = SpannableBuilder.builder().append(CommentsHelper.getThumbsUp()).append(" ").append(String.valueOf(reaction.getPlusOne())).append("   ");
    thumbsUp.setText(spannableBuilder);
    thumbsUpReaction.setText(spannableBuilder);
    thumbsUpReaction.setVisibility(reaction.getPlusOne() > 0 ? View.VISIBLE : View.GONE);
    spannableBuilder = SpannableBuilder.builder().append(CommentsHelper.getThumbsDown()).append(" ").append(String.valueOf(reaction.getMinusOne())).append("   ");
    thumbsDown.setText(spannableBuilder);
    thumbsDownReaction.setText(spannableBuilder);
    thumbsDownReaction.setVisibility(reaction.getMinusOne() > 0 ? View.VISIBLE : View.GONE);
    spannableBuilder = SpannableBuilder.builder().append(CommentsHelper.getHooray()).append(" ").append(String.valueOf(reaction.getHooray())).append("   ");
    hurray.setText(spannableBuilder);
    hurrayReaction.setText(spannableBuilder);
    hurrayReaction.setVisibility(reaction.getHooray() > 0 ? View.VISIBLE : View.GONE);
    spannableBuilder = SpannableBuilder.builder().append(CommentsHelper.getSad()).append(" ").append(String.valueOf(reaction.getConfused())).append("   ");
    sad.setText(spannableBuilder);
    sadReaction.setText(spannableBuilder);
    sadReaction.setVisibility(reaction.getConfused() > 0 ? View.VISIBLE : View.GONE);
    spannableBuilder = SpannableBuilder.builder().append(CommentsHelper.getLaugh()).append(" ").append(String.valueOf(reaction.getLaugh())).append("   ");
    laugh.setText(spannableBuilder);
    laughReaction.setText(spannableBuilder);
    laughReaction.setVisibility(reaction.getLaugh() > 0 ? View.VISIBLE : View.GONE);
    spannableBuilder = SpannableBuilder.builder().append(CommentsHelper.getHeart()).append(" ").append(String.valueOf(reaction.getHeart()));
    heart.setText(spannableBuilder);
    heartReaction.setText(spannableBuilder);
    heartReaction.setVisibility(reaction.getHeart() > 0 ? View.VISIBLE : View.GONE);
    if (reaction.getPlusOne() > 0 || reaction.getMinusOne() > 0 || reaction.getLaugh() > 0 || reaction.getHooray() > 0 || reaction.getConfused() > 0 || reaction.getHeart() > 0) {
        reactionsList.setVisibility(View.VISIBLE);
        reactionsList.setTag(true);
    } else {
        reactionsList.setVisibility(View.GONE);
        reactionsList.setTag(false);
    }
}
Also used : SpannableBuilder(com.fastaccess.ui.widgets.SpannableBuilder)

Example 2 with SpannableBuilder

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

the class TimelineProvider method getStyledEvents.

@NonNull
public static SpannableBuilder getStyledEvents(@NonNull GenericEvent issueEventModel, @NonNull Context context, boolean isMerged) {
    IssueEventType event = issueEventModel.getEvent();
    SpannableBuilder spannableBuilder = SpannableBuilder.builder();
    Date date = issueEventModel.getCreatedAt() != null ? issueEventModel.getCreatedAt() : issueEventModel.getAuthor() != null ? issueEventModel.getAuthor().getDate() : null;
    if (event != null) {
        String to = context.getString(R.string.to);
        String from = context.getString(R.string.from);
        String thisString = context.getString(R.string.this_value);
        String in = context.getString(R.string.in_value);
        if (event == IssueEventType.labeled || event == IssueEventType.unlabeled) {
            spannableBuilder.bold(issueEventModel.getActor() != null ? issueEventModel.getActor().getLogin() : "anonymous");
            spannableBuilder.append(" ").append(event.name().replaceAll("_", " "));
            LabelModel labelModel = issueEventModel.getLabel();
            int color = Color.parseColor("#" + labelModel.getColor());
            spannableBuilder.append(" ").append(" " + labelModel.getName() + " ", new CodeSpan(color, ViewHelper.generateTextColor(color), 5));
            spannableBuilder.append(" ").append(getDate(issueEventModel.getCreatedAt()));
        } else if (event == IssueEventType.committed) {
            spannableBuilder.append(issueEventModel.getMessage().replaceAll("\n", " ")).append(" ").url(substring(issueEventModel.getSha()));
        } else {
            User user = null;
            if (issueEventModel.getAssignee() != null && issueEventModel.getAssigner() != null) {
                user = issueEventModel.getAssigner();
            } else if (issueEventModel.getActor() != null) {
                user = issueEventModel.getActor();
            } else if (issueEventModel.getAuthor() != null) {
                user = issueEventModel.getAuthor();
            }
            if (user != null) {
                spannableBuilder.bold(user.getLogin());
            }
            if ((event == IssueEventType.review_requested || (event == IssueEventType.review_dismissed || event == IssueEventType.review_request_removed)) && user != null) {
                appendReviews(issueEventModel, event, spannableBuilder, from, issueEventModel.getReviewRequester());
            } else if (event == IssueEventType.closed || event == IssueEventType.reopened) {
                if (isMerged) {
                    spannableBuilder.append(" ").append(IssueEventType.merged.name());
                } else {
                    spannableBuilder.append(" ").append(event.name().replaceAll("_", " ")).append(" ").append(thisString);
                }
                if (issueEventModel.getCommitId() != null) {
                    spannableBuilder.append(" ").append(in).append(" ").url(substring(issueEventModel.getCommitId()));
                }
            } else if (event == IssueEventType.assigned || event == IssueEventType.unassigned) {
                spannableBuilder.append(" ");
                if ((user != null && issueEventModel.getAssignee() != null) && user.getLogin().equalsIgnoreCase(issueEventModel.getAssignee().getLogin())) {
                    spannableBuilder.append(event == IssueEventType.assigned ? "self-assigned this" : "removed their assignment");
                } else {
                    spannableBuilder.append(event == IssueEventType.assigned ? "assigned" : "unassigned");
                    spannableBuilder.append(" ").bold(issueEventModel.getAssignee() != null ? issueEventModel.getAssignee().getLogin() : "");
                }
            } else if (event == IssueEventType.locked || event == IssueEventType.unlocked) {
                spannableBuilder.append(" ").append(event == IssueEventType.locked ? "locked and limited conversation to collaborators" : "unlocked this " + "conversation");
            } else if (event == IssueEventType.head_ref_deleted || event == IssueEventType.head_ref_restored) {
                spannableBuilder.append(" ").append(event.name().replaceAll("_", " "), new BackgroundColorSpan(HtmlHelper.getWindowBackground(PrefGetter.getThemeType())));
            } else if (event == IssueEventType.milestoned || event == IssueEventType.demilestoned) {
                spannableBuilder.append(" ").append(event == IssueEventType.milestoned ? "added this to the" : "removed this from the").append(" ").bold(issueEventModel.getMilestone().getTitle()).append(" ").append("milestone");
            } else if (event == IssueEventType.deployed) {
                spannableBuilder.append(" ").bold("deployed");
            } else {
                spannableBuilder.append(" ").append(event.name().replaceAll("_", " "));
            }
            if (event == IssueEventType.renamed) {
                spannableBuilder.append(" ").append(from).append(" ").bold(issueEventModel.getRename().getFromValue()).append(" ").append(to).append(" ").bold(issueEventModel.getRename().getToValue());
            } else if (event == IssueEventType.referenced || event == IssueEventType.merged) {
                spannableBuilder.append(" ").append("commit").append(" ").url(substring(issueEventModel.getCommitId()));
            } else if (event == IssueEventType.cross_referenced) {
                SourceModel sourceModel = issueEventModel.getSource();
                if (sourceModel != null) {
                    String type = sourceModel.getType();
                    SpannableBuilder title = SpannableBuilder.builder();
                    if (sourceModel.getPullRequest() != null) {
                        if (sourceModel.getIssue() != null)
                            title.url("#" + sourceModel.getIssue().getNumber());
                        type = "pull request";
                    } else if (sourceModel.getIssue() != null) {
                        title.url("#" + sourceModel.getIssue().getNumber());
                    } else if (sourceModel.getCommit() != null) {
                        title.url(substring(sourceModel.getCommit().getSha()));
                    } else if (sourceModel.getRepository() != null) {
                        title.url(sourceModel.getRepository().getName());
                    }
                    if (!InputHelper.isEmpty(title)) {
                        spannableBuilder.append(" ").append(thisString).append(" in ").append(type).append(" ").append(title);
                    }
                }
            }
            spannableBuilder.append(" ").append(getDate(date));
        }
    }
    return spannableBuilder;
}
Also used : SourceModel(com.fastaccess.data.dao.timeline.SourceModel) IssueEventType(com.fastaccess.data.dao.types.IssueEventType) User(com.fastaccess.data.dao.model.User) LabelModel(com.fastaccess.data.dao.LabelModel) SpannableBuilder(com.fastaccess.ui.widgets.SpannableBuilder) CodeSpan(com.zzhoujay.markdown.style.CodeSpan) Date(java.util.Date) BackgroundColorSpan(android.text.style.BackgroundColorSpan) NonNull(android.support.annotation.NonNull)

Example 3 with SpannableBuilder

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

the class IssuePopupFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    toolbar.setNavigationIcon(R.drawable.ic_clear);
    toolbar.setNavigationOnClickListener(view1 -> dismiss());
    Bundle bundle = getArguments();
    String titleString = bundle.getString(BundleConstant.EXTRA);
    String bodyString = bundle.getString(BundleConstant.EXTRA_TWO);
    User user = bundle.getParcelable(BundleConstant.EXTRA_THREE);
    User assigneeModel = bundle.getParcelable(BundleConstant.EXTRA_FOUR);
    ArrayList<LabelModel> labelsList = bundle.getParcelableArrayList(BundleConstant.EXTRA_FIVE);
    MilestoneModel milestoneModel = bundle.getParcelable(BundleConstant.EXTRA_SIX);
    boolean canComment = bundle.getBoolean(BundleConstant.YES_NO_EXTRA);
    commentSection.setVisibility(canComment ? View.VISIBLE : View.GONE);
    toolbar.setTitle(String.format("#%s", bundle.getInt(BundleConstant.ID)));
    title.setText(titleString);
    MarkDownProvider.setMdText(body, bodyString);
    if (user != null) {
        name.setText(user.getLogin());
        avatarLayout.setUrl(user.getAvatarUrl(), user.getLogin(), false, LinkParserHelper.isEnterprise(user.getUrl()));
    }
    if (assigneeModel == null) {
        assigneeLayout.setVisibility(View.GONE);
    } else {
        assignee.setText(assigneeModel.getLogin());
    }
    if (labelsList == null || labelsList.isEmpty()) {
        labelsLayout.setVisibility(View.GONE);
    } else {
        SpannableBuilder builder = SpannableBuilder.builder();
        for (LabelModel label : labelsList) {
            int color = Color.parseColor("#" + label.getColor());
            builder.append(" ").append(" " + label.getName() + " ", new LabelSpan(color));
        }
        labels.setText(builder);
    }
    if (milestoneModel == null) {
        milestoneLayout.setVisibility(View.GONE);
    } else {
        milestoneTitle.setText(milestoneModel.getTitle());
        milestoneDescription.setText(milestoneModel.getDescription());
        if (milestoneModel.getDescription() == null) {
            milestoneDescription.setVisibility(View.GONE);
        }
    }
}
Also used : User(com.fastaccess.data.dao.model.User) MilestoneModel(com.fastaccess.data.dao.MilestoneModel) LabelModel(com.fastaccess.data.dao.LabelModel) Bundle(android.os.Bundle) SpannableBuilder(com.fastaccess.ui.widgets.SpannableBuilder) LabelSpan(com.fastaccess.ui.widgets.LabelSpan)

Example 4 with SpannableBuilder

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

the class AbstractGist method getDisplayTitle.

@NonNull
public SpannableBuilder getDisplayTitle(boolean isFromProfile, boolean gistView) {
    SpannableBuilder spannableBuilder = SpannableBuilder.builder();
    boolean addDescription = true;
    if (!isFromProfile) {
        if (owner != null) {
            spannableBuilder.bold(owner.getLogin());
        } else if (user != null) {
            spannableBuilder.bold(user.getLogin());
        } else {
            spannableBuilder.bold("Anonymous");
        }
        if (!gistView) {
            List<FilesListModel> files = getFilesAsList();
            if (!files.isEmpty()) {
                FilesListModel filesListModel = files.get(0);
                if (!InputHelper.isEmpty(filesListModel.getFilename()) && filesListModel.getFilename().trim().length() > 2) {
                    spannableBuilder.append(" ").append("/").append(" ").append(filesListModel.getFilename());
                    addDescription = false;
                }
            }
        }
    }
    if (!InputHelper.isEmpty(description) && addDescription) {
        if (!InputHelper.isEmpty(spannableBuilder.toString())) {
            spannableBuilder.append(" ").append("/").append(" ");
        }
        spannableBuilder.append(description);
    }
    if (InputHelper.isEmpty(spannableBuilder.toString())) {
        if (isFromProfile) {
            List<FilesListModel> files = getFilesAsList();
            if (!files.isEmpty()) {
                FilesListModel filesListModel = files.get(0);
                if (!InputHelper.isEmpty(filesListModel.getFilename()) && filesListModel.getFilename().trim().length() > 2) {
                    spannableBuilder.append(" ").append(filesListModel.getFilename());
                }
            }
        }
    }
    return spannableBuilder;
}
Also used : SpannableBuilder(com.fastaccess.ui.widgets.SpannableBuilder) FilesListModel(com.fastaccess.data.dao.FilesListModel) NonNull(android.support.annotation.NonNull)

Example 5 with SpannableBuilder

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

the class AbstractPullRequest method getMergeBy.

@NonNull
public static SpannableBuilder getMergeBy(@NonNull PullRequest pullRequest, @NonNull Context context, boolean showRepoName) {
    boolean isMerge = pullRequest.isMerged() || !InputHelper.isEmpty(pullRequest.mergedAt);
    if (isMerge) {
        User merger = pullRequest.getMergedBy();
        SpannableBuilder builder = SpannableBuilder.builder();
        if (showRepoName) {
            PullsIssuesParser parser = PullsIssuesParser.getForPullRequest(pullRequest.getHtmlUrl());
            if (parser != null)
                builder.bold(parser.getLogin()).append("/").bold(parser.getRepoId()).append(" ").bold("#").bold(String.valueOf(pullRequest.getNumber())).append(" ");
        } else {
            builder.bold("#" + pullRequest.getNumber()).append(" ").append(merger != null ? merger.getLogin() + " " : "");
        }
        builder.append(context.getString(R.string.merged).toLowerCase()).append(" ");
        if (pullRequest.getHead() != null) {
            builder.bold(pullRequest.getHead().getRef()).append(" ").append(context.getString(R.string.to)).append(" ").bold(pullRequest.getBase().getRef()).append(" ");
        }
        builder.append(ParseDateFormat.getTimeAgo(pullRequest.getMergedAt()));
        return builder;
    } else {
        User user = pullRequest.getUser();
        String status = context.getString(pullRequest.getState().getStatus());
        SpannableBuilder builder = SpannableBuilder.builder();
        if (showRepoName) {
            PullsIssuesParser parser = PullsIssuesParser.getForPullRequest(pullRequest.getHtmlUrl());
            if (parser != null) {
                builder.bold(parser.getLogin()).append("/").bold(parser.getRepoId()).append(" ").bold("#").bold(String.valueOf(pullRequest.getNumber())).append(" ");
            }
        } else {
            builder.bold("#" + pullRequest.getNumber()).append(" ").append(user.getLogin()).append(" ");
        }
        if (pullRequest.getState() == IssueState.open && pullRequest.getHead() != null && pullRequest.getBase() != null) {
            return builder.append(context.getString(R.string.want_to_merge)).append(" ").bold(pullRequest.getHead().getRef()).append(" ").append(context.getString(R.string.to)).append(" ").bold(pullRequest.getBase().getRef()).append(" ").append(ParseDateFormat.getTimeAgo(pullRequest.getState() == IssueState.closed ? pullRequest.getClosedAt() : pullRequest.getCreatedAt()));
        } else {
            return builder.bold(status.toLowerCase()).append(" ").bold(pullRequest.getHead() != null ? pullRequest.getHead().getRef() : "").append(" ").append(ParseDateFormat.getTimeAgo(pullRequest.getState() == IssueState.closed ? pullRequest.getClosedAt() : pullRequest.getCreatedAt()));
        }
    }
}
Also used : SpannableBuilder(com.fastaccess.ui.widgets.SpannableBuilder) PullsIssuesParser(com.fastaccess.data.dao.PullsIssuesParser) NonNull(android.support.annotation.NonNull)

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