Search in sources :

Example 56 with ApiHelpers

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();
    });
}
Also used : Response(retrofit2.Response) ApiHelpers(com.gh4a.utils.ApiHelpers) StarringService(com.meisolsson.githubsdk.service.activity.StarringService)

Example 57 with ApiHelpers

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));
}
Also used : IssueService(com.meisolsson.githubsdk.service.issues.IssueService) User(com.meisolsson.githubsdk.model.User) Milestone(com.meisolsson.githubsdk.model.Milestone) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) Label(com.meisolsson.githubsdk.model.Label) Intent(android.content.Intent) Response(retrofit2.Response) IssueRequest(com.meisolsson.githubsdk.model.request.issue.IssueRequest) ApiHelpers(com.gh4a.utils.ApiHelpers)

Example 58 with ApiHelpers

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));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) Bundle(android.os.Bundle) ImageView(android.widget.ImageView) IssueMilestoneService(com.meisolsson.githubsdk.service.issues.IssueMilestoneService) TextInputLayout(android.support.design.widget.TextInputLayout) MarkdownPreviewWebView(com.gh4a.widget.MarkdownPreviewWebView) IssueState(com.meisolsson.githubsdk.model.IssueState) Label(com.meisolsson.githubsdk.model.Label) Locale(java.util.Locale) ContentType(com.meisolsson.githubsdk.model.ContentType) Issue(com.meisolsson.githubsdk.model.Issue) View(android.view.View) StringUtils(com.gh4a.utils.StringUtils) FloatingActionButton(android.support.design.widget.FloatingActionButton) ContextCompat(android.support.v4.content.ContextCompat) IssueLabelService(com.meisolsson.githubsdk.service.issues.IssueLabelService) ViewGroup(android.view.ViewGroup) RepositoryContentService(com.meisolsson.githubsdk.service.repositories.RepositoryContentService) List(java.util.List) TextView(android.widget.TextView) RxUtils(com.gh4a.utils.RxUtils) Optional(com.gh4a.utils.Optional) Nullable(android.support.annotation.Nullable) Typeface(android.graphics.Typeface) Context(android.content.Context) AppBarLayout(android.support.design.widget.AppBarLayout) CoordinatorLayout(android.support.design.widget.CoordinatorLayout) MarkdownButtonsBar(com.gh4a.widget.MarkdownButtonsBar) BasePagerActivity(com.gh4a.BasePagerActivity) Intent(android.content.Intent) Response(retrofit2.Response) Single(io.reactivex.Single) UiUtils(com.gh4a.utils.UiUtils) ArrayList(java.util.ArrayList) User(com.meisolsson.githubsdk.model.User) AvatarHandler(com.gh4a.utils.AvatarHandler) Milestone(com.meisolsson.githubsdk.model.Milestone) Content(com.meisolsson.githubsdk.model.Content) R(com.gh4a.R) IssueRequest(com.meisolsson.githubsdk.model.request.issue.IssueRequest) IssueService(com.meisolsson.githubsdk.service.issues.IssueService) RepositoryCollaboratorService(com.meisolsson.githubsdk.service.repositories.RepositoryCollaboratorService) DialogInterface(android.content.DialogInterface) ApiHelpers(com.gh4a.utils.ApiHelpers) LayoutInflater(android.view.LayoutInflater) PagerAdapter(android.support.v4.view.PagerAdapter) IdRes(android.support.annotation.IdRes) AlertDialog(android.support.v7.app.AlertDialog) Gh4Application(com.gh4a.Gh4Application) ObjectsCompat(android.support.v4.util.ObjectsCompat) SingleFactory(com.gh4a.utils.SingleFactory) ServiceFactory(com.gh4a.ServiceFactory) EditText(android.widget.EditText) RepositoryContentService(com.meisolsson.githubsdk.service.repositories.RepositoryContentService) ApiHelpers(com.gh4a.utils.ApiHelpers)

Example 59 with ApiHelpers

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

Example 60 with ApiHelpers

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<>()));
}
Also used : ApiRequestException(com.gh4a.ApiRequestException) ArrayList(java.util.ArrayList) ApiHelpers(com.gh4a.utils.ApiHelpers) CommitCompare(com.meisolsson.githubsdk.model.CommitCompare) RepositoryCommitService(com.meisolsson.githubsdk.service.repositories.RepositoryCommitService)

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