Search in sources :

Example 1 with GitHubComment

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

the class GistFragment method onActivityResult.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (RESULT_OK != resultCode || data == null) {
        return;
    }
    switch(requestCode) {
        case COMMENT_CREATE:
            GitHubComment comment = data.getParcelableExtra(EXTRA_COMMENT);
            if (comments != null) {
                comments.add(comment);
                gist = gist.toBuilder().comments(gist.comments() + 1).build();
                updateList(gist, comments);
            } else {
                refreshGist();
            }
            return;
        case COMMENT_EDIT:
            comment = data.getParcelableExtra(EXTRA_COMMENT);
            if (comments != null && comment != null) {
                int position = Collections.binarySearch(comments, comment, new Comparator<GitHubComment>() {

                    @Override
                    public int compare(GitHubComment lhs, GitHubComment rhs) {
                        return Integer.valueOf(lhs.id()).compareTo(rhs.id());
                    }
                });
                imageGetter.removeFromCache(comment.id());
                comments.set(position, comment);
                updateList(gist, comments);
            } else {
                refreshGist();
            }
            return;
    }
    super.onActivityResult(requestCode, resultCode, data);
}
Also used : GitHubComment(com.meisolsson.githubsdk.model.GitHubComment)

Example 2 with GitHubComment

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

the class CreateCommentActivity method createComment.

@Override
protected void createComment(String comment) {
    CommentRequest commentRequest = CommentRequest.builder().body(comment).build();
    ServiceGenerator.createService(this, IssueCommentService.class).createIssueComment(repositoryId.owner().login(), repositoryId.name(), issueNumber, commentRequest).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).compose(this.<GitHubComment>bindToLifecycle()).subscribe(new ObserverAdapter<GitHubComment>() {

        @Override
        public void onSuccess(GitHubComment githubComment) {
            finish(githubComment);
        }
    });
}
Also used : CommentRequest(com.meisolsson.githubsdk.model.request.CommentRequest) IssueCommentService(com.meisolsson.githubsdk.service.issues.IssueCommentService) GitHubComment(com.meisolsson.githubsdk.model.GitHubComment)

Example 3 with GitHubComment

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

the class EditCommentActivity method editComment.

/**
     * Edit comment.
     *
     * @param commentText
     */
protected void editComment(String commentText) {
    CommentRequest commentRequest = CommentRequest.builder().body(commentText).build();
    ServiceGenerator.createService(this, IssueCommentService.class).editIssueComment(repositoryId.owner().login(), repositoryId.name(), comment.id(), commentRequest).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).compose(this.<GitHubComment>bindToLifecycle()).subscribe(new ProgressObserverAdapter<GitHubComment>(this, R.string.editing_comment) {

        @Override
        public void onSuccess(GitHubComment edited) {
            super.onSuccess(edited);
            dismissProgress();
            finish(edited);
        }

        @Override
        public void onError(Throwable e) {
            super.onError(e);
            Log.d(TAG, "Exception editing comment on issue", e);
            ToastUtils.show(EditCommentActivity.this, e.getMessage());
        }
    }.start());
}
Also used : CommentRequest(com.meisolsson.githubsdk.model.request.CommentRequest) IssueCommentService(com.meisolsson.githubsdk.service.issues.IssueCommentService) ProgressObserverAdapter(com.github.pockethub.android.rx.ProgressObserverAdapter) GitHubComment(com.meisolsson.githubsdk.model.GitHubComment)

Example 4 with GitHubComment

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

the class CreateCommentActivity method createComment.

@Override
protected void createComment(final String comment) {
    CommentRequest commentRequest = CommentRequest.builder().body(comment).build();
    ServiceGenerator.createService(this, GistCommentService.class).createGistComment(gist.id(), commentRequest).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).compose(this.<GitHubComment>bindToLifecycle()).subscribe(new ObserverAdapter<GitHubComment>() {

        @Override
        public void onSuccess(GitHubComment githubComment) {
            finish(githubComment);
        }

        @Override
        public void onError(Throwable error) {
            Log.e(TAG, "Exception creating comment on gist", error);
            ToastUtils.show(CreateCommentActivity.this, error.getMessage());
        }
    });
}
Also used : CommentRequest(com.meisolsson.githubsdk.model.request.CommentRequest) GistCommentService(com.meisolsson.githubsdk.service.gists.GistCommentService) GitHubComment(com.meisolsson.githubsdk.model.GitHubComment)

Example 5 with GitHubComment

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

the class RefreshGistTask method subscribe.

@Override
public void subscribe(ObservableEmitter<FullGist> emitter) throws Exception {
    try {
        Gist gist = store.refreshGist(id);
        List<GitHubComment> comments;
        if (gist.comments() > 0) {
            comments = ServiceGenerator.createService(context, GistCommentService.class).getGistComments(id, 0).blockingGet().items();
        } else {
            comments = Collections.emptyList();
        }
        for (GitHubComment comment : comments) {
            imageGetter.encode(comment, comment.bodyHtml());
        }
        Response<Boolean> response = ServiceGenerator.createService(context, GistService.class).checkIfGistIsStarred(id).blockingGet();
        boolean starred = response.code() == 204;
        emitter.onNext(new FullGist(gist, starred, comments));
    } catch (IOException e) {
        emitter.onError(e);
    }
}
Also used : Gist(com.meisolsson.githubsdk.model.Gist) GitHubComment(com.meisolsson.githubsdk.model.GitHubComment) IOException(java.io.IOException)

Aggregations

GitHubComment (com.meisolsson.githubsdk.model.GitHubComment)9 ProgressObserverAdapter (com.github.pockethub.android.rx.ProgressObserverAdapter)3 CommentRequest (com.meisolsson.githubsdk.model.request.CommentRequest)3 IssueCommentService (com.meisolsson.githubsdk.service.issues.IssueCommentService)3 Issue (com.meisolsson.githubsdk.model.Issue)2 GistCommentService (com.meisolsson.githubsdk.service.gists.GistCommentService)2 IOException (java.io.IOException)2 Response (retrofit2.Response)2 FullIssue (com.github.pockethub.android.core.issue.FullIssue)1 Gist (com.meisolsson.githubsdk.model.Gist)1 IssueEvent (com.meisolsson.githubsdk.model.IssueEvent)1 Label (com.meisolsson.githubsdk.model.Label)1 PullRequest (com.meisolsson.githubsdk.model.PullRequest)1