Search in sources :

Example 1 with ProgressObserverAdapter

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

the class EditIssueActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case R.id.m_apply:
            IssueRequest.Builder request = IssueRequest.builder().body(bodyText.getText().toString()).title(titleText.getText().toString()).state(issue.state());
            if (issue.assignee() != null) {
                request.assignees(Collections.singletonList(issue.assignee().login()));
            }
            if (issue.milestone() != null) {
                request.milestone(issue.milestone().number());
            }
            if (issue.labels() != null) {
                List<String> labels = new ArrayList<>();
                for (Label label : issue.labels()) {
                    labels.add(label.name());
                }
                request.labels(labels);
            }
            IssueService service = ServiceGenerator.createService(this, IssueService.class);
            Single<Issue> single;
            int message;
            if (issue.number() != null && issue.number() > 0) {
                single = service.editIssue(repository.owner().login(), repository.name(), issue.number(), request.build());
                message = R.string.updating_issue;
            } else {
                single = service.createIssue(repository.owner().login(), repository.name(), request.build());
                message = R.string.creating_issue;
            }
            single.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).compose(this.<Issue>bindToLifecycle()).subscribe(new ProgressObserverAdapter<Issue>(this, message) {

                @Override
                public void onSuccess(Issue issue) {
                    super.onSuccess(issue);
                    Intent intent = new Intent();
                    intent.putExtra(EXTRA_ISSUE, issue);
                    setResult(RESULT_OK, intent);
                    finish();
                }

                @Override
                public void onError(Throwable e) {
                    super.onError(e);
                    Log.e(TAG, "Exception creating issue", e);
                    ToastUtils.show(EditIssueActivity.this, e.getMessage());
                }
            }.start());
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
Also used : IssueService(com.meisolsson.githubsdk.service.issues.IssueService) Issue(com.meisolsson.githubsdk.model.Issue) ProgressObserverAdapter(com.github.pockethub.android.rx.ProgressObserverAdapter) ArrayList(java.util.ArrayList) Label(com.meisolsson.githubsdk.model.Label) Intent(android.content.Intent) IssueRequest(com.meisolsson.githubsdk.model.request.issue.IssueRequest)

Example 2 with ProgressObserverAdapter

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

the class AssigneeDialog method load.

private void load(final User selectedAssignee) {
    getPageAndNext(1).subscribe(new ProgressObserverAdapter<Page<User>>(activity, R.string.loading_collaborators) {

        List<User> users = new ArrayList<>();

        @Override
        public void onError(Throwable error) {
            dismissProgress();
            Log.d(TAG, "Exception loading collaborators", error);
            ToastUtils.show(activity, error, R.string.error_collaborators_load);
        }

        @Override
        public void onComplete() {
            super.onComplete();
            Map<String, User> loadedCollaborators = new TreeMap<>(CASE_INSENSITIVE_ORDER);
            for (User user : users) {
                loadedCollaborators.put(user.login(), user);
            }
            collaborators = loadedCollaborators;
            dismissProgress();
            show(selectedAssignee);
        }

        @Override
        public void onNext(Page<User> page) {
            users.addAll(page.items());
        }
    }.start());
}
Also used : User(com.meisolsson.githubsdk.model.User) ProgressObserverAdapter(com.github.pockethub.android.rx.ProgressObserverAdapter) ArrayList(java.util.ArrayList) List(java.util.List) Page(com.meisolsson.githubsdk.model.Page) TreeMap(java.util.TreeMap)

Example 3 with ProgressObserverAdapter

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

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

the class CreateGistActivity method createGist.

private void createGist() {
    final boolean isPublic = publicCheckBox.isChecked();
    String enteredDescription = descriptionText.getText().toString().trim();
    final String description = enteredDescription.length() > 0 ? enteredDescription : getString(R.string.gist_description_hint);
    String enteredName = nameText.getText().toString().trim();
    final String name = enteredName.length() > 0 ? enteredName : getString(R.string.gist_file_name_hint);
    final String content = contentText.getText().toString();
    Map<String, GistFile> map = new HashMap<>();
    map.put(name, GistFile.builder().filename(name).content(content).build());
    CreateGist createGist = CreateGist.builder().files(map).description(description).isPublic(isPublic).build();
    ServiceGenerator.createService(this, GistService.class).createGist(createGist).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).compose(this.<Gist>bindToLifecycle()).subscribe(new ProgressObserverAdapter<Gist>(this, R.string.creating_gist) {

        @Override
        public void onSuccess(Gist gist) {
            super.onSuccess(gist);
            startActivity(GistsViewActivity.createIntent(gist));
            setResult(RESULT_OK);
            finish();
        }

        @Override
        public void onError(Throwable e) {
            super.onError(e);
            Log.d(TAG, "Exception creating Gist", e);
            ToastUtils.show(CreateGistActivity.this, e.getMessage());
        }
    }.start());
}
Also used : Gist(com.meisolsson.githubsdk.model.Gist) CreateGist(com.meisolsson.githubsdk.model.request.gist.CreateGist) HashMap(java.util.HashMap) CreateGist(com.meisolsson.githubsdk.model.request.gist.CreateGist) ProgressObserverAdapter(com.github.pockethub.android.rx.ProgressObserverAdapter) GistFile(com.meisolsson.githubsdk.model.GistFile) GistService(com.meisolsson.githubsdk.service.gists.GistService)

Example 5 with ProgressObserverAdapter

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

the class RefDialog method load.

private void load(final GitReference selectedRef) {
    getPageAndNext(1).subscribe(new ProgressObserverAdapter<Page<GitReference>>(activity, R.string.loading_refs) {

        List<GitReference> allRefs = new ArrayList<>();

        @Override
        public void onNext(Page<GitReference> page) {
            super.onNext(page);
            allRefs.addAll(page.items());
        }

        @Override
        public void onComplete() {
            super.onComplete();
            Map<String, GitReference> loadedRefs = new TreeMap<>(CASE_INSENSITIVE_ORDER);
            for (GitReference ref : allRefs) {
                if (RefUtils.isValid(ref)) {
                    loadedRefs.put(ref.ref(), ref);
                }
            }
            refs = loadedRefs;
            show(selectedRef);
        }

        @Override
        public void onError(Throwable e) {
            super.onError(e);
            Log.d(TAG, "Exception loading references", e);
            ToastUtils.show(activity, e, R.string.error_refs_load);
        }
    }.start());
}
Also used : ProgressObserverAdapter(com.github.pockethub.android.rx.ProgressObserverAdapter) ArrayList(java.util.ArrayList) List(java.util.List) Page(com.meisolsson.githubsdk.model.Page) TreeMap(java.util.TreeMap) GitReference(com.meisolsson.githubsdk.model.git.GitReference)

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