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