Search in sources :

Example 11 with Label

use of com.meisolsson.githubsdk.model.Label in project PocketHub by pockethub.

the class IssueFragment method updateHeader.

private void updateHeader(final Issue issue) {
    if (!isUsable()) {
        return;
    }
    titleText.setText(issue.title());
    String body = issue.bodyHtml();
    if (!TextUtils.isEmpty(body)) {
        bodyImageGetter.bind(bodyText, body, issue.id());
    } else {
        bodyText.setText(R.string.no_description_given);
    }
    authorText.setText(issue.user().login());
    createdDateText.setText(new StyledText().append(getString(R.string.prefix_opened)).append(issue.createdAt()));
    avatars.bind(creatorAvatar, issue.user());
    if (IssueUtils.isPullRequest(issue) && issue.pullRequest().commits() != null && issue.pullRequest().commits() > 0) {
        ViewUtils.setGone(commitsView, false);
        TextView icon = (TextView) headerView.findViewById(R.id.tv_commit_icon);
        TypefaceUtils.setOcticons(icon);
        icon.setText(ICON_COMMIT);
        String commits = getString(R.string.pull_request_commits, issue.pullRequest().commits());
        ((TextView) headerView.findViewById(R.id.tv_pull_request_commits)).setText(commits);
    } else {
        ViewUtils.setGone(commitsView, true);
    }
    boolean open = IssueState.open.equals(issue.state());
    if (!open) {
        StyledText text = new StyledText();
        text.bold(getString(R.string.closed));
        Date closedAt = issue.closedAt();
        if (closedAt != null) {
            text.append(' ').append(closedAt);
        }
        stateText.setText(text);
    }
    ViewUtils.setGone(stateText, open);
    User assignee = issue.assignee();
    if (assignee != null) {
        StyledText name = new StyledText();
        name.bold(assignee.login());
        name.append(' ').append(getString(R.string.assigned));
        assigneeText.setText(name);
        assigneeAvatar.setVisibility(VISIBLE);
        avatars.bind(assigneeAvatar, assignee);
    } else {
        assigneeAvatar.setVisibility(GONE);
        assigneeText.setText(R.string.unassigned);
    }
    List<Label> labels = issue.labels();
    if (labels != null && !labels.isEmpty()) {
        LabelDrawableSpan.setText(labelsArea, labels);
        labelsArea.setVisibility(VISIBLE);
    } else {
        labelsArea.setVisibility(GONE);
    }
    if (issue.milestone() != null) {
        Milestone milestone = issue.milestone();
        StyledText milestoneLabel = new StyledText();
        milestoneLabel.append(getString(R.string.milestone_prefix));
        milestoneLabel.append(' ');
        milestoneLabel.bold(milestone.title());
        milestoneText.setText(milestoneLabel);
        float closed = milestone.closedIssues();
        float total = closed + milestone.openIssues();
        if (total > 0) {
            ((LayoutParams) milestoneProgressArea.getLayoutParams()).weight = closed / total;
            milestoneProgressArea.setVisibility(VISIBLE);
        } else {
            milestoneProgressArea.setVisibility(GONE);
        }
        milestoneArea.setVisibility(VISIBLE);
    } else {
        milestoneArea.setVisibility(GONE);
    }
    ViewUtils.setGone(progress, true);
    ViewUtils.setGone(list, false);
    updateStateItem(issue);
}
Also used : StyledText(com.github.pockethub.android.ui.StyledText) User(com.meisolsson.githubsdk.model.User) Milestone(com.meisolsson.githubsdk.model.Milestone) Label(com.meisolsson.githubsdk.model.Label) TextView(android.widget.TextView) Date(java.util.Date)

Example 12 with Label

use of com.meisolsson.githubsdk.model.Label in project PocketHub by pockethub.

the class LabelsDialog method load.

private void load(final Collection<Label> selectedLabels) {
    getPageAndNext(1).subscribe(new ProgressObserverAdapter<Page<Label>>(activity, R.string.loading_labels) {

        List<Label> repositoryLabels = new ArrayList<>();

        @Override
        public void onNext(Page<Label> page) {
            repositoryLabels.addAll(page.items());
        }

        @Override
        public void onComplete() {
            super.onComplete();
            Map<String, Label> loadedLabels = new TreeMap<>(CASE_INSENSITIVE_ORDER);
            for (Label label : repositoryLabels) {
                loadedLabels.put(label.name(), label);
            }
            labels = loadedLabels;
            dismissProgress();
            show(selectedLabels);
        }

        @Override
        public void onError(Throwable error) {
            dismissProgress();
            Log.e(TAG, "Exception loading labels", error);
            ToastUtils.show(activity, error, R.string.error_labels_load);
        }
    }.start());
}
Also used : ProgressObserverAdapter(com.github.pockethub.android.rx.ProgressObserverAdapter) Label(com.meisolsson.githubsdk.model.Label) ArrayList(java.util.ArrayList) List(java.util.List) Page(com.meisolsson.githubsdk.model.Page) TreeMap(java.util.TreeMap)

Aggregations

Label (com.meisolsson.githubsdk.model.Label)12 ArrayList (java.util.ArrayList)7 ProgressObserverAdapter (com.github.pockethub.android.rx.ProgressObserverAdapter)3 Milestone (com.meisolsson.githubsdk.model.Milestone)3 User (com.meisolsson.githubsdk.model.User)3 Bundle (android.os.Bundle)2 TextView (android.widget.TextView)2 IssueRequest (com.meisolsson.githubsdk.model.request.issue.IssueRequest)2 Activity (android.app.Activity)1 Intent (android.content.Intent)1 LayoutInflater (android.view.LayoutInflater)1 ListView (android.widget.ListView)1 DialogAction (com.afollestad.materialdialogs.DialogAction)1 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)1 BaseActivity (com.github.pockethub.android.ui.BaseActivity)1 StyledText (com.github.pockethub.android.ui.StyledText)1 GitHubComment (com.meisolsson.githubsdk.model.GitHubComment)1 Issue (com.meisolsson.githubsdk.model.Issue)1 Page (com.meisolsson.githubsdk.model.Page)1 IssueCommentService (com.meisolsson.githubsdk.service.issues.IssueCommentService)1