Search in sources :

Example 11 with ApiHelpers

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);
}
Also used : ApiHelpers(com.gh4a.utils.ApiHelpers) GistService(com.meisolsson.githubsdk.service.gists.GistService)

Example 12 with ApiHelpers

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;
}
Also used : OAuthService(com.meisolsson.githubsdk.service.OAuthService) User(com.meisolsson.githubsdk.model.User) UserService(com.meisolsson.githubsdk.service.users.UserService) RequestToken(com.meisolsson.githubsdk.model.request.RequestToken) ApiHelpers(com.gh4a.utils.ApiHelpers) Uri(android.net.Uri)

Example 13 with ApiHelpers

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));
}
Also used : IssueService(com.meisolsson.githubsdk.service.issues.IssueService) IssueRequest(com.meisolsson.githubsdk.model.request.issue.IssueRequest) StringRes(android.support.annotation.StringRes) ApiHelpers(com.gh4a.utils.ApiHelpers)

Example 14 with ApiHelpers

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);
}
Also used : IssueService(com.meisolsson.githubsdk.service.issues.IssueService) ApiHelpers(com.gh4a.utils.ApiHelpers)

Example 15 with ApiHelpers

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));
}
Also used : Label(com.meisolsson.githubsdk.model.Label) IssueLabelService(com.meisolsson.githubsdk.service.issues.IssueLabelService) ApiHelpers(com.gh4a.utils.ApiHelpers)

Aggregations

ApiHelpers (com.gh4a.utils.ApiHelpers)68 Response (retrofit2.Response)13 RxUtils (com.gh4a.utils.RxUtils)12 ServiceFactory (com.gh4a.ServiceFactory)11 Intent (android.content.Intent)10 Bundle (android.os.Bundle)10 Optional (com.gh4a.utils.Optional)10 PullRequestReviewCommentService (com.meisolsson.githubsdk.service.pull_request.PullRequestReviewCommentService)10 Single (io.reactivex.Single)9 Context (android.content.Context)7 LayoutInflater (android.view.LayoutInflater)7 CommentRequest (com.meisolsson.githubsdk.model.request.CommentRequest)7 List (java.util.List)7 View (android.view.View)6 R (com.gh4a.R)6 IntentUtils (com.gh4a.utils.IntentUtils)6 User (com.meisolsson.githubsdk.model.User)6 ReactionRequest (com.meisolsson.githubsdk.model.request.ReactionRequest)6 CreateReviewComment (com.meisolsson.githubsdk.model.request.pull_request.CreateReviewComment)6 ReactionService (com.meisolsson.githubsdk.service.reactions.ReactionService)6