use of com.gh4a.utils.ApiHelpers in project gh4a by slapperwan.
the class GistViewerActivity method loadGist.
private void loadGist(boolean force) {
GistService service = ServiceFactory.get(GistService.class, force);
service.getGist(mGistId).map(ApiHelpers::throwOnFailure).compose(makeLoaderSingle(ID_LOADER_GIST, force)).subscribe(result -> {
mGistOwner = ApiHelpers.getUserLogin(GistViewerActivity.this, result.owner());
mGistFile = result.files().get(mFileName);
onDataReady();
}, this::handleLoadFailure);
}
use of com.gh4a.utils.ApiHelpers in project gh4a by slapperwan.
the class Github4AndroidActivity method handleIntent.
private boolean handleIntent(Intent intent) {
Uri data = intent.getData();
if (data != null && data.getScheme().equals(CALLBACK_URI.getScheme()) && data.getHost().equals(CALLBACK_URI.getHost())) {
OAuthService service = ServiceGenerator.createAuthService();
RequestToken request = RequestToken.builder().clientId(BuildConfig.CLIENT_ID).clientSecret(BuildConfig.CLIENT_SECRET).code(data.getQueryParameter(PARAM_CODE)).build();
service.getToken(request).map(ApiHelpers::throwOnFailure).flatMap(token -> {
UserService userService = ServiceFactory.get(UserService.class, true, null, token.accessToken(), null);
Single<User> userSingle = userService.getUser().map(ApiHelpers::throwOnFailure);
return Single.zip(Single.just(token), userSingle, (t, user) -> Pair.create(t.accessToken(), user));
}).compose(RxUtils::doInBackground).subscribe(pair -> onLoginFinished(pair.first, pair.second), this::handleLoadFailure);
return true;
}
return false;
}
use of com.gh4a.utils.ApiHelpers 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.gh4a.utils.ApiHelpers 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.gh4a.utils.ApiHelpers in project gh4a by slapperwan.
the class IssueLabelListActivity method addLabel.
private void addLabel(IssueLabelAdapter.EditableLabel label) {
String errorMessage = getString(R.string.issue_error_create_label, label.name());
IssueLabelService service = ServiceFactory.get(IssueLabelService.class, false);
Label newLabel = Label.builder().name(label.name()).color(label.color()).build();
service.createLabel(mRepoOwner, mRepoName, newLabel).map(ApiHelpers::throwOnFailure).compose(RxUtils.wrapForBackgroundTask(this, R.string.saving_msg, errorMessage)).subscribe(result -> {
mAddedLabel = null;
loadLabels(true);
setResult(RESULT_OK);
}, error -> handleActionFailure("Adding label failed", error));
}
Aggregations