use of com.meisolsson.githubsdk.model.git.GitComment 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.meisolsson.githubsdk.model.git.GitComment in project PocketHub by pockethub.
the class RefreshCommitTask method subscribe.
@Override
public void subscribe(ObservableEmitter<FullCommit> emitter) throws Exception {
try {
Commit commit = store.refreshCommit(repository, id);
GitCommit rawCommit = commit.commit();
if (rawCommit != null && rawCommit.commentCount() > 0) {
List<GitComment> comments = ServiceGenerator.createService(context, RepositoryCommentService.class).getCommitComments(repository.owner().login(), repository.name(), commit.sha(), 1).blockingGet().items();
for (GitComment comment : comments) {
imageGetter.encode(comment, comment.bodyHtml());
}
emitter.onNext(new FullCommit(commit, comments));
} else {
emitter.onNext(new FullCommit(commit));
}
} catch (IOException e) {
emitter.onError(e);
}
}
use of com.meisolsson.githubsdk.model.git.GitComment in project PocketHub by pockethub.
the class FullCommitTest method testSingleCommentSingleFile.
/**
* Test commit with one file and one commit comment
*/
public void testSingleCommentSingleFile() {
GitHubFile file = GitHubFile.builder().filename("a.txt").build();
GitComment comment = GitComment.builder().build();
Commit commit = Commit.builder().files(Collections.singletonList(file)).build();
FullCommit full = new FullCommit(commit, Collections.singletonList(comment));
assertFalse(full.isEmpty());
assertEquals(comment, full.get(0));
assertEquals(1, full.getFiles().size());
}
use of com.meisolsson.githubsdk.model.git.GitComment in project PocketHub by pockethub.
the class FullCommitTest method testSingleLineCommentSingleFile.
/**
* Test commit with one file and one line comment
*/
public void testSingleLineCommentSingleFile() {
GitHubFile file = GitHubFile.builder().filename("a.txt").build();
GitComment comment = GitComment.builder().path(file.filename()).position(10).build();
Commit commit = Commit.builder().files(Collections.singletonList(file)).build();
FullCommit full = new FullCommit(commit, new ArrayList<>(Collections.singletonList(comment)));
assertTrue(full.isEmpty());
assertEquals(1, full.getFiles().size());
assertEquals(comment, full.getFiles().get(0).get(10).get(0));
}
use of com.meisolsson.githubsdk.model.git.GitComment in project PocketHub by pockethub.
the class NewsFragment method openCommitComment.
private void openCommitComment(GitHubEvent event) {
Repository repo = ConvertUtils.eventRepoToRepo(event.repo());
if (repo == null) {
return;
}
if (repo.name().contains("/")) {
String[] repoId = repo.name().split("/");
repo = InfoUtils.createRepoFromData(repoId[0], repoId[1]);
}
CommitCommentPayload payload = ((CommitCommentPayload) event.payload());
GitComment comment = payload.comment();
if (comment == null) {
return;
}
String sha = comment.commitId();
if (!TextUtils.isEmpty(sha)) {
startActivity(CommitViewActivity.createIntent(repo, sha));
}
}
Aggregations