Search in sources :

Example 1 with LabelSpan

use of com.fastaccess.ui.widgets.LabelSpan 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 2 with LabelSpan

use of com.fastaccess.ui.widgets.LabelSpan 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 3 with LabelSpan

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

the class PinnedReposViewHolder method bind.

@Override
public void bind(@NonNull PinnedRepos pinnedRepos) {
    Repo repo = pinnedRepos.getPinnedRepo();
    if (repo == null)
        return;
    if (repo.isFork()) {
        title.setText(SpannableBuilder.builder().append(" " + forked + " ", new LabelSpan(forkColor)).append(" ").append(repo.getName(), new LabelSpan(Color.TRANSPARENT)));
    } else if (repo.isPrivateX()) {
        title.setText(SpannableBuilder.builder().append(" " + privateRepo + " ", new LabelSpan(privateColor)).append(" ").append(repo.getName(), new LabelSpan(Color.TRANSPARENT)));
    } else {
        title.setText(repo.getFullName());
    }
    String avatar = repo.getOwner() != null ? repo.getOwner().getAvatarUrl() : null;
    String login = repo.getOwner() != null ? repo.getOwner().getLogin() : null;
    boolean isOrg = repo.getOwner() != null && repo.getOwner().isOrganizationType();
    if (avatarLayout != null) {
        avatarLayout.setVisibility(View.VISIBLE);
        avatarLayout.setUrl(avatar, login, isOrg, LinkParserHelper.isEnterprise(repo.getHtmlUrl()));
    }
    if (stars != null && forks != null && date != null && language != null) {
        NumberFormat numberFormat = NumberFormat.getNumberInstance();
        stars.setText(numberFormat.format(repo.getStargazersCount()));
        forks.setText(numberFormat.format(repo.getForks()));
        date.setText(ParseDateFormat.getTimeAgo(repo.getUpdatedAt()));
        if (!InputHelper.isEmpty(repo.getLanguage())) {
            language.setText(repo.getLanguage());
            language.setTextColor(ColorsProvider.getColorAsColor(repo.getLanguage(), language.getContext()));
            language.setVisibility(View.VISIBLE);
        }
    }
}
Also used : Repo(com.fastaccess.data.dao.model.Repo) LabelSpan(com.fastaccess.ui.widgets.LabelSpan) BindString(butterknife.BindString) NumberFormat(java.text.NumberFormat)

Example 4 with LabelSpan

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

Example 5 with LabelSpan

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

the class ReposViewHolder method bind.

@Override
public void bind(@NonNull Repo repo) {
    if (repo.isFork() && !isStarred) {
        title.setText(SpannableBuilder.builder().append(" " + forked + " ", new LabelSpan(forkColor)).append(" ").append(repo.getName(), new LabelSpan(Color.TRANSPARENT)));
    } else if (repo.isPrivateX()) {
        title.setText(SpannableBuilder.builder().append(" " + privateRepo + " ", new LabelSpan(privateColor)).append(" ").append(repo.getName(), new LabelSpan(Color.TRANSPARENT)));
    } else {
        title.setText(!isStarred ? repo.getName() : repo.getFullName());
    }
    if (withImage) {
        String avatar = repo.getOwner() != null ? repo.getOwner().getAvatarUrl() : null;
        String login = repo.getOwner() != null ? repo.getOwner().getLogin() : null;
        boolean isOrg = repo.getOwner() != null && repo.getOwner().isOrganizationType();
        if (avatarLayout != null) {
            avatarLayout.setVisibility(View.VISIBLE);
            avatarLayout.setUrl(avatar, login, isOrg, LinkParserHelper.isEnterprise(repo.getHtmlUrl()));
        }
    }
    long repoSize = repo.getSize() > 0 ? (repo.getSize() * 1000) : repo.getSize();
    size.setText(Formatter.formatFileSize(size.getContext(), repoSize));
    NumberFormat numberFormat = NumberFormat.getNumberInstance();
    stars.setText(numberFormat.format(repo.getStargazersCount()));
    forks.setText(numberFormat.format(repo.getForks()));
    date.setText(ParseDateFormat.getTimeAgo(repo.getUpdatedAt()));
    if (!InputHelper.isEmpty(repo.getLanguage())) {
        language.setText(repo.getLanguage());
        language.setTextColor(ColorsProvider.getColorAsColor(repo.getLanguage(), language.getContext()));
        language.setVisibility(View.VISIBLE);
    } else {
        language.setTextColor(Color.BLACK);
        language.setVisibility(View.GONE);
        language.setText("");
    }
}
Also used : LabelSpan(com.fastaccess.ui.widgets.LabelSpan) BindString(butterknife.BindString) NumberFormat(java.text.NumberFormat)

Aggregations

LabelSpan (com.fastaccess.ui.widgets.LabelSpan)5 LabelModel (com.fastaccess.data.dao.LabelModel)3 SpannableBuilder (com.fastaccess.ui.widgets.SpannableBuilder)3 BindString (butterknife.BindString)2 NumberFormat (java.text.NumberFormat)2 Bundle (android.os.Bundle)1 MilestoneModel (com.fastaccess.data.dao.MilestoneModel)1 Repo (com.fastaccess.data.dao.model.Repo)1 User (com.fastaccess.data.dao.model.User)1