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