Search in sources :

Example 6 with ProgressObserverAdapter

use of com.github.pockethub.android.rx.ProgressObserverAdapter 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 7 with ProgressObserverAdapter

use of com.github.pockethub.android.rx.ProgressObserverAdapter 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 8 with ProgressObserverAdapter

use of com.github.pockethub.android.rx.ProgressObserverAdapter in project PocketHub by pockethub.

the class IssueFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Bundle args = getArguments();
    repositoryId = InfoUtils.createRepoFromData(args.getString(EXTRA_REPOSITORY_OWNER), args.getString(EXTRA_REPOSITORY_NAME));
    issueNumber = args.getInt(EXTRA_ISSUE_NUMBER);
    user = args.getParcelable(EXTRA_USER);
    canWrite = args.getBoolean(EXTRA_CAN_WRITE_REPO, false);
    BaseActivity dialogActivity = (BaseActivity) getActivity();
    ProgressObserverAdapter<Issue> observer = new ProgressObserverAdapter<Issue>(getActivity()) {

        @Override
        public void onNext(Issue issue) {
            super.onNext(issue);
            updateHeader(issue);
            refreshIssue();
        }
    };
    milestoneTask = new EditMilestoneTask(dialogActivity, repositoryId, issueNumber, observer);
    assigneeTask = new EditAssigneeTask(dialogActivity, repositoryId, issueNumber, observer);
    labelsTask = new EditLabelsTask(dialogActivity, repositoryId, issueNumber, observer);
    stateTask = new EditStateTask(dialogActivity, repositoryId, issueNumber, observer);
}
Also used : Issue(com.meisolsson.githubsdk.model.Issue) FullIssue(com.github.pockethub.android.core.issue.FullIssue) Bundle(android.os.Bundle) ProgressObserverAdapter(com.github.pockethub.android.rx.ProgressObserverAdapter) BaseActivity(com.github.pockethub.android.ui.BaseActivity)

Example 9 with ProgressObserverAdapter

use of com.github.pockethub.android.rx.ProgressObserverAdapter in project PocketHub by pockethub.

the class LabelsDialog method load.

private void load(final Collection<Label> selectedLabels) {
    getPageAndNext(1).subscribe(new ProgressObserverAdapter<Page<Label>>(activity, R.string.loading_labels) {

        List<Label> repositoryLabels = new ArrayList<>();

        @Override
        public void onNext(Page<Label> page) {
            repositoryLabels.addAll(page.items());
        }

        @Override
        public void onComplete() {
            super.onComplete();
            Map<String, Label> loadedLabels = new TreeMap<>(CASE_INSENSITIVE_ORDER);
            for (Label label : repositoryLabels) {
                loadedLabels.put(label.name(), label);
            }
            labels = loadedLabels;
            dismissProgress();
            show(selectedLabels);
        }

        @Override
        public void onError(Throwable error) {
            dismissProgress();
            Log.e(TAG, "Exception loading labels", error);
            ToastUtils.show(activity, error, R.string.error_labels_load);
        }
    }.start());
}
Also used : ProgressObserverAdapter(com.github.pockethub.android.rx.ProgressObserverAdapter) Label(com.meisolsson.githubsdk.model.Label) ArrayList(java.util.ArrayList) List(java.util.List) Page(com.meisolsson.githubsdk.model.Page) TreeMap(java.util.TreeMap)

Aggregations

ProgressObserverAdapter (com.github.pockethub.android.rx.ProgressObserverAdapter)9 ArrayList (java.util.ArrayList)4 GitHubComment (com.meisolsson.githubsdk.model.GitHubComment)3 Label (com.meisolsson.githubsdk.model.Label)3 Page (com.meisolsson.githubsdk.model.Page)3 List (java.util.List)3 TreeMap (java.util.TreeMap)3 Issue (com.meisolsson.githubsdk.model.Issue)2 IssueCommentService (com.meisolsson.githubsdk.service.issues.IssueCommentService)2 Response (retrofit2.Response)2 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 FullIssue (com.github.pockethub.android.core.issue.FullIssue)1 BaseActivity (com.github.pockethub.android.ui.BaseActivity)1 Gist (com.meisolsson.githubsdk.model.Gist)1 GistFile (com.meisolsson.githubsdk.model.GistFile)1 User (com.meisolsson.githubsdk.model.User)1 GitReference (com.meisolsson.githubsdk.model.git.GitReference)1 CommentRequest (com.meisolsson.githubsdk.model.request.CommentRequest)1 CreateGist (com.meisolsson.githubsdk.model.request.gist.CreateGist)1