use of com.meisolsson.githubsdk.model.GitHubComment in project PocketHub by pockethub.
the class IssueFragment method onDialogResult.
@Override
public void onDialogResult(int requestCode, int resultCode, Bundle arguments) {
if (RESULT_OK != resultCode) {
return;
}
switch(requestCode) {
case ISSUE_MILESTONE_UPDATE:
milestoneTask.edit(MilestoneDialogFragment.getSelected(arguments));
break;
case ISSUE_ASSIGNEE_UPDATE:
assigneeTask.edit(AssigneeDialogFragment.getSelected(arguments));
break;
case ISSUE_LABELS_UPDATE:
ArrayList<Label> labels = LabelsDialogFragment.getSelected(arguments);
if (labels != null && !labels.isEmpty()) {
labelsTask.edit(labels.toArray(new Label[labels.size()]));
} else {
labelsTask.edit(null);
}
break;
case ISSUE_CLOSE:
stateTask.edit(true);
break;
case ISSUE_REOPEN:
stateTask.edit(false);
break;
case COMMENT_DELETE:
final GitHubComment comment = arguments.getParcelable(EXTRA_COMMENT);
ServiceGenerator.createService(getActivity(), IssueCommentService.class).deleteIssueComment(repositoryId.owner().login(), repositoryId.name(), comment.id()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).compose(this.<Response<Boolean>>bindToLifecycle()).subscribe(new ProgressObserverAdapter<Response<Boolean>>(getActivity(), R.string.deleting_comment) {
@Override
public void onSuccess(Response<Boolean> response) {
if (items != null) {
int commentPosition = findCommentPositionInItems(comment);
if (commentPosition >= 0) {
issue = issue.toBuilder().comments(issue.comments() - 1).build();
items.remove(commentPosition);
updateList(issue, items);
}
} else {
refreshIssue();
}
dismissProgress();
}
@Override
public void onError(Throwable e) {
Log.d(TAG, "Exception deleting comment on issue", e);
ToastUtils.show(getActivity(), e.getMessage());
dismissProgress();
}
}.start());
break;
}
}
use of com.meisolsson.githubsdk.model.GitHubComment in project PocketHub by pockethub.
the class IssueFragment method onActivityResult.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (RESULT_OK != resultCode || data == null) {
return;
}
switch(requestCode) {
case ISSUE_EDIT:
Issue editedIssue = data.getParcelableExtra(EXTRA_ISSUE);
bodyImageGetter.encode(editedIssue.id(), editedIssue.bodyHtml());
updateHeader(editedIssue);
return;
case COMMENT_CREATE:
GitHubComment comment = data.getParcelableExtra(EXTRA_COMMENT);
if (items != null) {
items.add(comment);
issue = issue.toBuilder().comments(issue.comments() + 1).build();
updateList(issue, items);
} else {
refreshIssue();
}
return;
case COMMENT_EDIT:
comment = data.getParcelableExtra(EXTRA_COMMENT);
if (items != null && comment != null) {
int commentPosition = findCommentPositionInItems(comment);
if (commentPosition >= 0) {
commentImageGetter.removeFromCache(comment.id());
replaceCommentInItems(commentPosition, comment);
updateList(issue, items);
}
} else {
refreshIssue();
}
}
}
use of com.meisolsson.githubsdk.model.GitHubComment in project PocketHub by pockethub.
the class GistFragment method onDialogResult.
@Override
public void onDialogResult(int requestCode, int resultCode, Bundle arguments) {
if (RESULT_OK != resultCode) {
return;
}
switch(requestCode) {
case COMMENT_DELETE:
final GitHubComment comment = arguments.getParcelable(EXTRA_COMMENT);
ServiceGenerator.createService(getActivity(), GistCommentService.class).deleteGistComment(gistId, comment.id()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).compose(this.<Response<Boolean>>bindToLifecycle()).subscribe(new ProgressObserverAdapter<Response<Boolean>>(getActivity(), R.string.deleting_comment) {
@Override
public void onSuccess(Response<Boolean> response) {
super.onSuccess(response);
// Update comment list
if (comments != 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());
}
});
comments.remove(position);
updateList(gist, comments);
} else {
refreshGist();
}
}
@Override
public void onError(Throwable e) {
super.onError(e);
Log.d(TAG, "Exception deleting comment on gist", e);
ToastUtils.show((Activity) getContext(), e.getMessage());
}
}.start());
break;
}
}
use of com.meisolsson.githubsdk.model.GitHubComment in project PocketHub by pockethub.
the class RefreshIssueTask method subscribe.
@Override
public void subscribe(ObservableEmitter<FullIssue> emitter) throws Exception {
try {
Issue issue = store.refreshIssue(repo, issueNumber);
if (issue.pullRequest() != null) {
PullRequest pull = getPullRequest(repo.owner().login(), repo.name(), issueNumber);
issue = issue.toBuilder().pullRequest(pull).build();
}
bodyImageGetter.encode(issue.id(), issue.bodyHtml());
List<GitHubComment> comments;
if (issue.comments() > 0) {
comments = getAllComments(repo.owner().login(), repo.name(), issueNumber);
} else {
comments = Collections.emptyList();
}
for (GitHubComment comment : comments) {
commentImageGetter.encode(comment.id(), comment.bodyHtml());
}
List<IssueEvent> events = getAllEvents(repo.owner().login(), repo.name(), issueNumber);
emitter.onNext(new FullIssue(issue, comments, events));
} catch (IOException e) {
emitter.onError(e);
}
}
Aggregations