Search in sources :

Example 11 with StyledText

use of com.github.pockethub.android.ui.StyledText in project PocketHub by pockethub.

the class SearchRepositoryListAdapter method update.

@Override
protected void update(int position, Repository repository) {
    StyledText name = new StyledText();
    name.append(repository.owner().login()).append('/');
    name.bold(repository.name());
    setText(5, name);
    updateDetails(repository.description(), repository.language(), repository.watchersCount(), repository.forksCount(), repository.isPrivate(), repository.isFork(), null);
}
Also used : StyledText(com.github.pockethub.android.ui.StyledText)

Example 12 with StyledText

use of com.github.pockethub.android.ui.StyledText in project PocketHub by pockethub.

the class DefaultRepositoryListAdapter method update.

@Override
protected void update(int position, Repository repository) {
    String headerValue = headers.get(repository.id());
    if (headerValue != null) {
        setGone(5, false);
        setText(6, headerValue);
    } else {
        setGone(5, true);
    }
    setGone(7, noSeparators.contains(repository.id()));
    StyledText name = new StyledText();
    if (!account.get().login().equals(repository.owner().login())) {
        name.foreground(repository.owner().login(), descriptionColor).foreground('/', descriptionColor);
    }
    name.bold(repository.name());
    setText(8, name);
    updateDetails(repository.description(), repository.language(), repository.watchersCount(), repository.forksCount(), repository.isPrivate(), repository.isFork(), repository.mirrorUrl());
}
Also used : StyledText(com.github.pockethub.android.ui.StyledText)

Example 13 with StyledText

use of com.github.pockethub.android.ui.StyledText in project PocketHub by pockethub.

the class CommitFileListAdapter method update.

@Override
protected void update(final int position, final Object item, final int type) {
    switch(type) {
        case TYPE_FILE_HEADER:
            GitHubFile file = (GitHubFile) item;
            String path = file.filename();
            int lastSlash = path.lastIndexOf('/');
            if (lastSlash != -1) {
                setText(0, path.substring(lastSlash + 1));
                ViewUtils.setGone(setText(1, path.substring(0, lastSlash + 1)), false);
            } else {
                setText(0, path);
                setGone(1, true);
            }
            StyledText stats = new StyledText();
            stats.foreground('+', addTextColor);
            stats.foreground(FORMAT_INT.format(file.additions()), addTextColor);
            stats.append(' ').append(' ').append(' ');
            stats.foreground('-', removeTextColor);
            stats.foreground(FORMAT_INT.format(file.deletions()), removeTextColor);
            setText(2, stats);
            return;
        case TYPE_FILE_LINE:
            CharSequence text = (CharSequence) item;
            diffStyler.updateColors((CharSequence) item, setText(0, text));
            return;
        case TYPE_LINE_COMMENT:
        case TYPE_COMMENT:
            GitComment comment = (GitComment) item;
            avatars.bind(imageView(1), comment.user());
            setText(2, comment.user().login());
            setText(3, TimeUtils.getRelativeTime(comment.updatedAt()));
            imageGetter.bind(textView(0), comment.bodyHtml(), comment.id());
    }
}
Also used : StyledText(com.github.pockethub.android.ui.StyledText) GitHubFile(com.meisolsson.githubsdk.model.GitHubFile) GitComment(com.meisolsson.githubsdk.model.git.GitComment)

Example 14 with StyledText

use of com.github.pockethub.android.ui.StyledText in project PocketHub by pockethub.

the class IconAndViewTextManagerTest method when_event_type_is_fork_then_icon_should_be_fork_and_its_text_should_be_formatted.

@Test
public void when_event_type_is_fork_then_icon_should_be_fork_and_its_text_should_be_formatted() throws Exception {
    // Arrange
    GitHubEvent event = GitHubEvent.builder().type(GitHubEventType.ForkEvent).build();
    IconAndViewTextManager iconAndViewTextManager = new IconAndViewTextManager(null);
    IconAndViewTextManager spyIconAndViewTextManager = spy(iconAndViewTextManager);
    doNothing().when(spyIconAndViewTextManager).formatFork(event, new StyledText(), null);
    // Act
    String icon = spyIconAndViewTextManager.setIconAndFormatStyledText(event, new StyledText(), null);
    // Assert
    assertEquals(TypefaceUtils.ICON_FORK, icon);
    verify(spyIconAndViewTextManager).formatFork(event, new StyledText(), null);
}
Also used : StyledText(com.github.pockethub.android.ui.StyledText) GitHubEvent(com.meisolsson.githubsdk.model.GitHubEvent) Test(org.junit.Test)

Example 15 with StyledText

use of com.github.pockethub.android.ui.StyledText in project PocketHub by pockethub.

the class CommitUtils method formatStats.

/**
     * Format stats into {@link StyledText}
     *
     * @param files
     * @return styled text
     */
public static StyledText formatStats(final Collection<GitHubFile> files) {
    StyledText fileDetails = new StyledText();
    int added = 0;
    int deleted = 0;
    int changed = 0;
    if (files != null) {
        for (GitHubFile file : files) {
            added += file.additions();
            deleted += file.deletions();
            changed++;
        }
    }
    if (changed != 1) {
        fileDetails.append(FORMAT.format(changed)).append(" changed files");
    } else {
        fileDetails.append("1 changed file");
    }
    fileDetails.append(" with ");
    if (added != 1) {
        fileDetails.append(FORMAT.format(added)).append(" additions");
    } else {
        fileDetails.append("1 addition ");
    }
    fileDetails.append(" and ");
    if (deleted != 1) {
        fileDetails.append(FORMAT.format(deleted)).append(" deletions");
    } else {
        fileDetails.append("1 deletion");
    }
    return fileDetails;
}
Also used : StyledText(com.github.pockethub.android.ui.StyledText) GitHubFile(com.meisolsson.githubsdk.model.GitHubFile)

Aggregations

StyledText (com.github.pockethub.android.ui.StyledText)16 TextView (android.widget.TextView)3 User (com.meisolsson.githubsdk.model.User)3 View (android.view.View)2 AdapterView (android.widget.AdapterView)2 ListView (android.widget.ListView)2 GitHubFile (com.meisolsson.githubsdk.model.GitHubFile)2 Date (java.util.Date)2 Resources (android.content.res.Resources)1 Paint (android.graphics.Paint)1 Rect (android.graphics.Rect)1 OnClickListener (android.view.View.OnClickListener)1 ImageView (android.widget.ImageView)1 Folder (com.github.pockethub.android.core.code.FullTree.Folder)1 FullCommit (com.github.pockethub.android.core.commit.FullCommit)1 Commit (com.meisolsson.githubsdk.model.Commit)1 GitHubEvent (com.meisolsson.githubsdk.model.GitHubEvent)1 Label (com.meisolsson.githubsdk.model.Label)1 Milestone (com.meisolsson.githubsdk.model.Milestone)1 GitComment (com.meisolsson.githubsdk.model.git.GitComment)1