use of com.meisolsson.githubsdk.service.issues.IssueService 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.meisolsson.githubsdk.service.issues.IssueService in project gh4a by slapperwan.
the class IssueActivity method updateIssueState.
private void updateIssueState(boolean reopen) {
IssueService service = ServiceFactory.get(IssueService.class, false);
IssueRequest request = IssueRequest.builder().state(reopen ? IssueState.Open : IssueState.Closed).build();
@StringRes int dialogResId = reopen ? R.string.opening_msg : R.string.closing_msg;
@StringRes int errorMessageResId = reopen ? R.string.issue_error_reopen : R.string.issue_error_close;
service.editIssue(mRepoOwner, mRepoName, mIssueNumber, request).map(ApiHelpers::throwOnFailure).compose(RxUtils.wrapForBackgroundTask(this, dialogResId, getString(errorMessageResId, mIssueNumber))).subscribe(result -> {
mIssue = result;
updateHeader();
if (mEditFab != null) {
mEditFab.setState(mIssue.state());
}
if (mFragment != null) {
mFragment.updateState(mIssue);
}
setResult(RESULT_OK);
supportInvalidateOptionsMenu();
}, error -> handleActionFailure("Updating issue state failed", error));
}
use of com.meisolsson.githubsdk.service.issues.IssueService in project gh4a by slapperwan.
the class IssueActivity method loadIssue.
private void loadIssue(boolean force) {
IssueService service = ServiceFactory.get(IssueService.class, force);
service.getIssue(mRepoOwner, mRepoName, mIssueNumber).map(ApiHelpers::throwOnFailure).compose(makeLoaderSingle(ID_LOADER_ISSUE, force)).subscribe(result -> {
mIssue = result;
showUiIfDone();
supportInvalidateOptionsMenu();
}, this::handleLoadFailure);
}
use of com.meisolsson.githubsdk.service.issues.IssueService in project gh4a by slapperwan.
the class PullRequestActivity method load.
private void load(boolean force) {
PullRequestService prService = ServiceFactory.get(PullRequestService.class, force);
IssueService issueService = ServiceFactory.get(IssueService.class, force);
Single<PullRequest> prSingle = prService.getPullRequest(mRepoOwner, mRepoName, mPullRequestNumber).map(ApiHelpers::throwOnFailure);
Single<Issue> issueSingle = issueService.getIssue(mRepoOwner, mRepoName, mPullRequestNumber).map(ApiHelpers::throwOnFailure);
Single<Boolean> isCollaboratorSingle = SingleFactory.isAppUserRepoCollaborator(mRepoOwner, mRepoName, force);
Single.zip(issueSingle, prSingle, isCollaboratorSingle, Triplet::create).compose(makeLoaderSingle(0, force)).subscribe(result -> {
mIssue = result.first;
mPullRequest = result.second;
mIsCollaborator = result.third;
fillHeader();
setContentShown(true);
invalidateTabs();
updateFabVisibility();
supportInvalidateOptionsMenu();
if (mInitialPage >= 0 && mInitialPage < TITLES.length) {
getPager().setCurrentItem(mInitialPage);
mInitialPage = -1;
}
}, this::handleLoadFailure);
}
use of com.meisolsson.githubsdk.service.issues.IssueService in project gh4a by slapperwan.
the class IssueEditActivity method saveIssue.
private void saveIssue() {
Milestone milestone = mEditIssue.milestone();
IssueRequest.Builder builder = IssueRequest.builder();
if (!ObjectsCompat.equals(mEditIssue.title(), mOriginalIssue.title())) {
builder.title(mEditIssue.title());
}
if (!ObjectsCompat.equals(mEditIssue.body(), mOriginalIssue.body())) {
builder.body(mEditIssue.body());
}
if (!ObjectsCompat.equals(mEditIssue.milestone(), mOriginalIssue.milestone())) {
builder.milestone(milestone != null ? milestone.number() : null);
}
if (!ObjectsCompat.equals(mEditIssue.assignees(), mOriginalIssue.assignees())) {
List<String> assignees = new ArrayList<>();
for (User assignee : mEditIssue.assignees()) {
assignees.add(assignee.login());
}
builder.assignees(assignees);
}
if (!ObjectsCompat.equals(mEditIssue.labels(), mOriginalIssue.labels())) {
List<String> labels = new ArrayList<>();
for (Label label : mEditIssue.labels()) {
labels.add(label.name());
}
builder.labels(labels);
}
Integer issueNumber = mEditIssue.number();
String errorMessage = issueNumber != null ? getString(R.string.issue_error_edit, issueNumber) : getString(R.string.issue_error_create);
IssueService service = ServiceFactory.get(IssueService.class, false);
Single<Response<Issue>> single = isInEditMode() ? service.editIssue(mRepoOwner, mRepoName, issueNumber, builder.build()) : service.createIssue(mRepoOwner, mRepoName, builder.build());
single.map(ApiHelpers::throwOnFailure).compose(RxUtils.wrapForBackgroundTask(this, R.string.saving_msg, errorMessage)).subscribe(result -> {
Intent data = new Intent();
Bundle extras = new Bundle();
extras.putParcelable("issue", result);
data.putExtras(extras);
setResult(RESULT_OK, data);
finish();
}, error -> handleActionFailure("Saving issue failed", error));
}
Aggregations