Search in sources :

Example 1 with LabelModel

use of com.fastaccess.data.dao.LabelModel 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 2 with LabelModel

use of com.fastaccess.data.dao.LabelModel 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 3 with LabelModel

use of com.fastaccess.data.dao.LabelModel in project FastHub by k0shk0sh.

the class CreateIssuePresenter method onSubmit.

@Override
public void onSubmit(@NonNull String title, @NonNull CharSequence description, @NonNull String login, @NonNull String repo, @Nullable Issue issue, @Nullable PullRequest pullRequestModel, @Nullable ArrayList<LabelModel> labels, @Nullable MilestoneModel milestoneModel, @Nullable ArrayList<User> users) {
    boolean isEmptyTitle = InputHelper.isEmpty(title);
    if (getView() != null) {
        getView().onTitleError(isEmptyTitle);
    }
    if (!isEmptyTitle) {
        if (issue == null && pullRequestModel == null) {
            CreateIssueModel createIssue = new CreateIssueModel();
            createIssue.setBody(InputHelper.toString(description));
            createIssue.setTitle(title);
            if (isCollaborator) {
                if (labels != null && !labels.isEmpty()) {
                    createIssue.setLabels(Stream.of(labels).map(LabelModel::getName).collect(Collectors.toCollection(ArrayList::new)));
                }
                if (users != null && !users.isEmpty()) {
                    createIssue.setAssignees(Stream.of(users).map(User::getLogin).collect(Collectors.toCollection(ArrayList::new)));
                }
                if (milestoneModel != null) {
                    createIssue.setMilestone((long) milestoneModel.getNumber());
                }
            }
            makeRestCall(RestProvider.getIssueService(isEnterprise()).createIssue(login, repo, createIssue), issueModel -> {
                if (issueModel != null) {
                    sendToView(view -> view.onSuccessSubmission(issueModel));
                } else {
                    sendToView(view -> view.showMessage(R.string.error, R.string.error_creating_issue));
                }
            }, false);
        } else {
            if (issue != null) {
                issue.setBody(InputHelper.toString(description));
                issue.setTitle(title);
                int number = issue.getNumber();
                if (isCollaborator) {
                    if (labels != null) {
                        LabelListModel labelModels = new LabelListModel();
                        labelModels.addAll(labels);
                        issue.setLabels(labelModels);
                    }
                    if (milestoneModel != null) {
                        issue.setMilestone(milestoneModel);
                    }
                    if (users != null) {
                        UsersListModel usersListModel = new UsersListModel();
                        usersListModel.addAll(users);
                        issue.setAssignees(usersListModel);
                    }
                }
                IssueRequestModel requestModel = IssueRequestModel.clone(issue, false);
                makeRestCall(RestProvider.getIssueService(isEnterprise()).editIssue(login, repo, number, requestModel), issueModel -> {
                    if (issueModel != null) {
                        sendToView(view -> view.onSuccessSubmission(issueModel));
                    } else {
                        sendToView(view -> view.showMessage(R.string.error, R.string.error_creating_issue));
                    }
                }, false);
            }
            if (pullRequestModel != null) {
                int number = pullRequestModel.getNumber();
                pullRequestModel.setBody(InputHelper.toString(description));
                pullRequestModel.setTitle(title);
                if (isCollaborator) {
                    if (labels != null) {
                        LabelListModel labelModels = new LabelListModel();
                        labelModels.addAll(labels);
                        pullRequestModel.setLabels(labelModels);
                    }
                    if (milestoneModel != null) {
                        pullRequestModel.setMilestone(milestoneModel);
                    }
                    if (users != null) {
                        UsersListModel usersListModel = new UsersListModel();
                        usersListModel.addAll(users);
                        pullRequestModel.setAssignees(usersListModel);
                    }
                }
                IssueRequestModel requestModel = IssueRequestModel.clone(pullRequestModel, false);
                makeRestCall(RestProvider.getPullRequestService(isEnterprise()).editPullRequest(login, repo, number, requestModel).flatMap(pullRequest1 -> RestProvider.getIssueService(isEnterprise()).getIssue(login, repo, number), (pullRequest1, issueReaction) -> {
                    // hack to get reactions from issue api
                    if (issueReaction != null) {
                        pullRequest1.setReactions(issueReaction.getReactions());
                    }
                    return pullRequest1;
                }), pr -> {
                    if (pr != null) {
                        sendToView(view -> view.onSuccessSubmission(pr));
                    } else {
                        sendToView(view -> view.showMessage(R.string.error, R.string.error_creating_issue));
                    }
                }, false);
            }
        }
    }
}
Also used : Stream(com.annimon.stream.Stream) IssueRequestModel(com.fastaccess.data.dao.IssueRequestModel) InputHelper(com.fastaccess.helper.InputHelper) Intent(android.content.Intent) NonNull(android.support.annotation.NonNull) Issue(com.fastaccess.data.dao.model.Issue) ArrayList(java.util.ArrayList) RxHelper(com.fastaccess.helper.RxHelper) MilestoneModel(com.fastaccess.data.dao.MilestoneModel) LabelListModel(com.fastaccess.data.dao.LabelListModel) User(com.fastaccess.data.dao.model.User) BasePresenter(com.fastaccess.ui.base.mvp.presenter.BasePresenter) BundleConstant(com.fastaccess.helper.BundleConstant) Login(com.fastaccess.data.dao.model.Login) RestProvider(com.fastaccess.provider.rest.RestProvider) Collectors(com.annimon.stream.Collectors) BaseMvp(com.fastaccess.ui.base.mvp.BaseMvp) CreateIssueModel(com.fastaccess.data.dao.CreateIssueModel) LabelModel(com.fastaccess.data.dao.LabelModel) PullRequest(com.fastaccess.data.dao.model.PullRequest) R(com.fastaccess.R) BuildConfig(com.fastaccess.BuildConfig) UsersListModel(com.fastaccess.data.dao.UsersListModel) Nullable(android.support.annotation.Nullable) Activity(android.app.Activity) User(com.fastaccess.data.dao.model.User) IssueRequestModel(com.fastaccess.data.dao.IssueRequestModel) UsersListModel(com.fastaccess.data.dao.UsersListModel) LabelModel(com.fastaccess.data.dao.LabelModel) LabelListModel(com.fastaccess.data.dao.LabelListModel) CreateIssueModel(com.fastaccess.data.dao.CreateIssueModel) ArrayList(java.util.ArrayList)

Example 4 with LabelModel

use of com.fastaccess.data.dao.LabelModel in project FastHub by k0shk0sh.

the class FilterIssuesActivity method getLabelsAdapter.

private LabelsAdapter getLabelsAdapter() {
    if (labelsAdapter == null) {
        if (!getPresenter().getLabels().isEmpty()) {
            LabelModel label = new LabelModel();
            label.setName(getString(R.string.clear));
            getPresenter().getLabels().add(0, label);
        }
        labelsAdapter = new LabelsAdapter(getPresenter().getLabels(), null);
        labelsAdapter.setListener(new BaseViewHolder.OnItemClickListener<LabelModel>() {

            @Override
            public void onItemClick(int position, View v, LabelModel item) {
                appendLabel(item);
            }

            @Override
            public void onItemLongClick(int position, View v, LabelModel item) {
            }
        });
    }
    return labelsAdapter;
}
Also used : BaseViewHolder(com.fastaccess.ui.widgets.recyclerview.BaseViewHolder) LabelModel(com.fastaccess.data.dao.LabelModel) LabelsAdapter(com.fastaccess.ui.adapter.LabelsAdapter) BindView(butterknife.BindView) ForegroundImageView(com.fastaccess.ui.widgets.ForegroundImageView) FontTextView(com.fastaccess.ui.widgets.FontTextView) View(android.view.View) DynamicRecyclerView(com.fastaccess.ui.widgets.recyclerview.DynamicRecyclerView) SuppressLint(android.annotation.SuppressLint)

Example 5 with LabelModel

use of com.fastaccess.data.dao.LabelModel 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)

Aggregations

LabelModel (com.fastaccess.data.dao.LabelModel)9 SpannableBuilder (com.fastaccess.ui.widgets.SpannableBuilder)4 NonNull (android.support.annotation.NonNull)3 User (com.fastaccess.data.dao.model.User)3 LabelSpan (com.fastaccess.ui.widgets.LabelSpan)3 View (android.view.View)2 MilestoneModel (com.fastaccess.data.dao.MilestoneModel)2 Issue (com.fastaccess.data.dao.model.Issue)2 RestProvider (com.fastaccess.provider.rest.RestProvider)2 BasePresenter (com.fastaccess.ui.base.mvp.presenter.BasePresenter)2 SuppressLint (android.annotation.SuppressLint)1 Activity (android.app.Activity)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 Nullable (android.support.annotation.Nullable)1 BackgroundColorSpan (android.text.style.BackgroundColorSpan)1 BindView (butterknife.BindView)1 Collectors (com.annimon.stream.Collectors)1 Stream (com.annimon.stream.Stream)1 BuildConfig (com.fastaccess.BuildConfig)1