Search in sources :

Example 6 with GitComment

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());
    }
}
Also used : StyledText(com.github.pockethub.android.ui.StyledText) GitHubFile(com.meisolsson.githubsdk.model.GitHubFile) GitComment(com.meisolsson.githubsdk.model.git.GitComment)

Example 7 with GitComment

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);
    }
}
Also used : GitCommit(com.meisolsson.githubsdk.model.git.GitCommit) Commit(com.meisolsson.githubsdk.model.Commit) GitCommit(com.meisolsson.githubsdk.model.git.GitCommit) RepositoryCommentService(com.meisolsson.githubsdk.service.repositories.RepositoryCommentService) GitComment(com.meisolsson.githubsdk.model.git.GitComment) IOException(java.io.IOException)

Example 8 with GitComment

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());
}
Also used : Commit(com.meisolsson.githubsdk.model.Commit) FullCommit(com.github.pockethub.android.core.commit.FullCommit) GitHubFile(com.meisolsson.githubsdk.model.GitHubFile) FullCommit(com.github.pockethub.android.core.commit.FullCommit) GitComment(com.meisolsson.githubsdk.model.git.GitComment)

Example 9 with GitComment

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));
}
Also used : Commit(com.meisolsson.githubsdk.model.Commit) FullCommit(com.github.pockethub.android.core.commit.FullCommit) GitHubFile(com.meisolsson.githubsdk.model.GitHubFile) FullCommit(com.github.pockethub.android.core.commit.FullCommit) GitComment(com.meisolsson.githubsdk.model.git.GitComment)

Example 10 with GitComment

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));
    }
}
Also used : Repository(com.meisolsson.githubsdk.model.Repository) GitComment(com.meisolsson.githubsdk.model.git.GitComment) CommitCommentPayload(com.meisolsson.githubsdk.model.payload.CommitCommentPayload)

Aggregations

GitComment (com.meisolsson.githubsdk.model.git.GitComment)10 Commit (com.meisolsson.githubsdk.model.Commit)5 FullCommit (com.github.pockethub.android.core.commit.FullCommit)4 GitHubFile (com.meisolsson.githubsdk.model.GitHubFile)4 FullCommitFile (com.github.pockethub.android.core.commit.FullCommitFile)1 StyledText (com.github.pockethub.android.ui.StyledText)1 Repository (com.meisolsson.githubsdk.model.Repository)1 GitCommit (com.meisolsson.githubsdk.model.git.GitCommit)1 CommitCommentPayload (com.meisolsson.githubsdk.model.payload.CommitCommentPayload)1 RepositoryCommentService (com.meisolsson.githubsdk.service.repositories.RepositoryCommentService)1 IOException (java.io.IOException)1