Search in sources :

Example 31 with ApiHelpers

use of com.gh4a.utils.ApiHelpers in project gh4a by slapperwan.

the class NotificationListFragment method unsubscribe.

@Override
public void unsubscribe(NotificationHolder notificationHolder) {
    NotificationThread notification = notificationHolder.notification;
    NotificationService service = ServiceFactory.get(NotificationService.class, false);
    SubscriptionRequest request = SubscriptionRequest.builder().subscribed(false).build();
    service.setNotificationThreadSubscription(notification.id(), request).map(ApiHelpers::throwOnFailure).compose(RxUtils::doInBackground).subscribe(result -> handleMarkAsRead(null, notification));
}
Also used : SubscriptionRequest(com.meisolsson.githubsdk.model.request.activity.SubscriptionRequest) NotificationThread(com.meisolsson.githubsdk.model.NotificationThread) ApiHelpers(com.gh4a.utils.ApiHelpers) NotificationService(com.meisolsson.githubsdk.service.activity.NotificationService)

Example 32 with ApiHelpers

use of com.gh4a.utils.ApiHelpers in project gh4a by slapperwan.

the class PullRequestFragment method deletePullRequestBranch.

private void deletePullRequestBranch() {
    GitService service = ServiceFactory.get(GitService.class, false);
    PullRequestMarker head = mPullRequest.head();
    String owner = head.repo().owner().login();
    String repo = head.repo().name();
    service.deleteGitReference(owner, repo, "heads/" + head.ref()).map(ApiHelpers::mapToBooleanOrThrowOnFailure).compose(RxUtils.wrapForBackgroundTask(getBaseActivity(), R.string.deleting_msg, R.string.delete_branch_error)).subscribe(result -> {
        mHeadReference = null;
        onHeadReferenceUpdated();
    }, error -> handleActionFailure("Deleting PR branch failed", error));
}
Also used : GitService(com.meisolsson.githubsdk.service.git.GitService) ApiHelpers(com.gh4a.utils.ApiHelpers) PullRequestMarker(com.meisolsson.githubsdk.model.PullRequestMarker)

Example 33 with ApiHelpers

use of com.gh4a.utils.ApiHelpers in project gh4a by slapperwan.

the class PullRequestFragment method restorePullRequestBranch.

private void restorePullRequestBranch() {
    PullRequestMarker head = mPullRequest.head();
    if (head.repo() == null) {
        return;
    }
    String owner = head.repo().owner().login();
    String repo = head.repo().name();
    GitService service = ServiceFactory.get(GitService.class, false);
    CreateGitReference request = CreateGitReference.builder().ref("refs/heads/" + head.ref()).sha(head.sha()).build();
    service.createGitReference(owner, repo, request).map(ApiHelpers::throwOnFailure).compose(RxUtils.wrapForBackgroundTask(getBaseActivity(), R.string.saving_msg, R.string.restore_branch_error)).subscribe(result -> {
        mHeadReference = result;
        onHeadReferenceUpdated();
    }, error -> handleActionFailure("Restoring PR branch failed", error));
}
Also used : GitService(com.meisolsson.githubsdk.service.git.GitService) ApiHelpers(com.gh4a.utils.ApiHelpers) PullRequestMarker(com.meisolsson.githubsdk.model.PullRequestMarker) CreateGitReference(com.meisolsson.githubsdk.model.request.git.CreateGitReference)

Example 34 with ApiHelpers

use of com.gh4a.utils.ApiHelpers in project gh4a by slapperwan.

the class UserActivity method loadUser.

private void loadUser(boolean force) {
    UserService service = ServiceFactory.get(UserService.class, force);
    service.getUser(mUserLogin).map(ApiHelpers::throwOnFailure).compose(makeLoaderSingle(ID_LOADER_USER, force)).subscribe(result -> {
        mUser = result;
        invalidateTabs();
        setContentShown(true);
        invalidateOptionsMenu();
    }, this::handleLoadFailure);
}
Also used : UserService(com.meisolsson.githubsdk.service.users.UserService) ApiHelpers(com.gh4a.utils.ApiHelpers)

Example 35 with ApiHelpers

use of com.gh4a.utils.ApiHelpers in project gh4a by slapperwan.

the class UserPasswordLoginDialogFragment method makeLoginSingle.

private Single<Pair<String, User>> makeLoginSingle(LoginService.AuthorizationRequest request) {
    return getService().createAuthorization(request).map(ApiHelpers::throwOnFailure).compose(RxUtils::doInBackground).flatMap(response -> {
        UserService userService = ServiceFactory.get(UserService.class, true, null, response.token(), null);
        Single<User> userSingle = userService.getUser().map(ApiHelpers::throwOnFailure).compose(RxUtils::doInBackground);
        return Single.zip(Single.just(response), userSingle, (r, user) -> Pair.create(r.token(), user));
    });
}
Also used : User(com.meisolsson.githubsdk.model.User) RxUtils(com.gh4a.utils.RxUtils) UserService(com.meisolsson.githubsdk.service.users.UserService) 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