use of com.gh4a.utils.ApiHelpers in project gh4a by slapperwan.
the class RepositoryActivity method toggleStarringState.
private void toggleStarringState() {
StarringService service = ServiceFactory.get(StarringService.class, false);
Single<Response<Void>> responseSingle = mIsStarring ? service.unstarRepository(mRepoOwner, mRepoName) : service.starRepository(mRepoOwner, mRepoName);
responseSingle.map(ApiHelpers::mapToBooleanOrThrowOnFailure).compose(RxUtils::doInBackground).subscribe(result -> {
if (mIsStarring != null) {
mIsStarring = !mIsStarring;
if (mRepositoryFragment != null) {
mRepositoryFragment.updateStargazerCount(mIsStarring);
}
supportInvalidateOptionsMenu();
}
}, error -> {
handleActionFailure("Updating repo starring state failed", error);
supportInvalidateOptionsMenu();
});
}
use of com.gh4a.utils.ApiHelpers 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));
}
use of com.gh4a.utils.ApiHelpers in project gh4a by slapperwan.
the class IssueEditActivity method loadIssueTemplate.
private void loadIssueTemplate() {
RepositoryContentService service = ServiceFactory.get(RepositoryContentService.class, false);
registerTemporarySubscription(getIssueTemplateContentSingle("/.github").flatMap(opt -> opt.orOptionalSingle(() -> getIssueTemplateContentSingle(""))).flatMap(opt -> opt.orOptionalSingle(() -> getIssueTemplateContentSingle("/docs"))).flatMap(opt -> opt.flatMap(c -> {
// noinspection CodeBlock2Expr
return service.getContents(mRepoOwner, mRepoName, c.path(), null).map(ApiHelpers::throwOnFailure).compose(RxUtils::doInBackground);
})).map(opt -> opt.map(c -> StringUtils.fromBase64(c.content()))).compose(RxUtils.wrapWithProgressDialog(this, R.string.loading_msg)).subscribe(result -> {
mDescView.setHint(null);
mDescView.setEnabled(true);
mDescView.setText(result.orNull());
}, this::handleLoadFailure));
}
use of com.gh4a.utils.ApiHelpers in project gh4a by slapperwan.
the class IssueLabelListActivity method editLabel.
private void editLabel(IssueLabelAdapter.EditableLabel label) {
Label oldLabel = label.base();
String errorMessage = getString(R.string.issue_error_edit_label, oldLabel.name());
IssueLabelService service = ServiceFactory.get(IssueLabelService.class, false);
Label newLabel = Label.builder().name(label.editedName).color(label.editedColor).build();
service.editLabel(mRepoOwner, mRepoName, oldLabel.name(), newLabel).map(ApiHelpers::throwOnFailure).compose(RxUtils.wrapForBackgroundTask(this, R.string.saving_msg, errorMessage)).subscribe(result -> {
loadLabels(true);
setResult(RESULT_OK);
}, error -> handleActionFailure("Editing label failed", error));
}
use of com.gh4a.utils.ApiHelpers in project gh4a by slapperwan.
the class CommitCompareFragment method onCreateDataSingle.
@Override
protected Single<List<Commit>> onCreateDataSingle(boolean bypassCache) {
RepositoryCommitService service = ServiceFactory.get(RepositoryCommitService.class, bypassCache);
Single<CommitCompare> compareSingle = service.compareCommits(mRepoOwner, mRepoName, mBase, mHead).map(ApiHelpers::throwOnFailure).onErrorResumeNext(error -> {
if (error instanceof ApiRequestException) {
ApiRequestException are = (ApiRequestException) error;
if (are.getStatus() == HttpURLConnection.HTTP_NOT_FOUND && mBaseLabel != null && mHeadLabel != null) {
// We got a 404; likely the history of the base branch was rewritten. Try the labels.
return service.compareCommits(mRepoOwner, mRepoName, mBaseLabel, mHeadLabel).map(ApiHelpers::throwOnFailure);
}
}
return Single.error(error);
});
return compareSingle.map(CommitCompare::commits).compose(RxUtils.mapFailureToValue(HttpURLConnection.HTTP_NOT_FOUND, new ArrayList<>()));
}
Aggregations