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);
}
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());
}
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());
}
}
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);
}
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;
}
Aggregations