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