Search in sources :

Example 6 with GitHubComment

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;
    }
}
Also used : Response(retrofit2.Response) IssueCommentService(com.meisolsson.githubsdk.service.issues.IssueCommentService) ProgressObserverAdapter(com.github.pockethub.android.rx.ProgressObserverAdapter) Label(com.meisolsson.githubsdk.model.Label) GitHubComment(com.meisolsson.githubsdk.model.GitHubComment)

Example 7 with GitHubComment

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();
            }
    }
}
Also used : Issue(com.meisolsson.githubsdk.model.Issue) FullIssue(com.github.pockethub.android.core.issue.FullIssue) GitHubComment(com.meisolsson.githubsdk.model.GitHubComment)

Example 8 with GitHubComment

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;
    }
}
Also used : GistCommentService(com.meisolsson.githubsdk.service.gists.GistCommentService) Response(retrofit2.Response) ProgressObserverAdapter(com.github.pockethub.android.rx.ProgressObserverAdapter) GitHubComment(com.meisolsson.githubsdk.model.GitHubComment)

Example 9 with GitHubComment

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);
    }
}
Also used : Issue(com.meisolsson.githubsdk.model.Issue) PullRequest(com.meisolsson.githubsdk.model.PullRequest) GitHubComment(com.meisolsson.githubsdk.model.GitHubComment) IOException(java.io.IOException) IssueEvent(com.meisolsson.githubsdk.model.IssueEvent)

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