Search in sources :

Example 1 with UserFollowerService

use of com.meisolsson.githubsdk.service.users.UserFollowerService in project PocketHub by pockethub.

the class UserViewActivity method followUser.

private void followUser() {
    UserFollowerService service = ServiceGenerator.createService(this, UserFollowerService.class);
    Single<Response<Void>> followSingle;
    if (isFollowing) {
        followSingle = service.unfollowUser(user.login());
    } else {
        followSingle = service.followUser(user.login());
    }
    followSingle.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).as(AutoDisposeUtils.bindToLifecycle(this)).subscribe(aVoid -> isFollowing = !isFollowing, e -> ToastUtils.show(this, isFollowing ? R.string.error_unfollowing_person : R.string.error_following_person));
}
Also used : Response(retrofit2.Response) UserFollowerService(com.meisolsson.githubsdk.service.users.UserFollowerService)

Example 2 with UserFollowerService

use of com.meisolsson.githubsdk.service.users.UserFollowerService in project gh4a by slapperwan.

the class UserFragment method loadIsFollowingStateIfNeeded.

private void loadIsFollowingStateIfNeeded(boolean force) {
    if (mIsSelf || !Gh4Application.get().isAuthorized()) {
        return;
    }
    UserFollowerService service = ServiceFactory.get(UserFollowerService.class, force);
    service.isFollowing(mUser.login()).map(ApiHelpers::mapToBooleanOrThrowOnFailure).compose(makeLoaderSingle(ID_LOADER_IS_FOLLOWING, force)).subscribe(result -> {
        mIsFollowing = result;
        getActivity().invalidateOptionsMenu();
    }, this::handleLoadFailure);
}
Also used : UserFollowerService(com.meisolsson.githubsdk.service.users.UserFollowerService) ApiHelpers(com.gh4a.utils.ApiHelpers)

Example 3 with UserFollowerService

use of com.meisolsson.githubsdk.service.users.UserFollowerService in project gh4a by slapperwan.

the class UserFragment method toggleFollowingState.

private void toggleFollowingState() {
    UserFollowerService service = ServiceFactory.get(UserFollowerService.class, false);
    Single<Response<Void>> responseSingle = mIsFollowing ? service.unfollowUser(mUser.login()) : service.followUser(mUser.login());
    responseSingle.map(ApiHelpers::mapToBooleanOrThrowOnFailure).compose(RxUtils::doInBackground).subscribe(result -> {
        mIsFollowing = !mIsFollowing;
        updateFollowingAction();
        getActivity().invalidateOptionsMenu();
    }, error -> {
        handleActionFailure("Toggling following state failed", error);
        getActivity().invalidateOptionsMenu();
    });
}
Also used : Response(retrofit2.Response) UserFollowerService(com.meisolsson.githubsdk.service.users.UserFollowerService) ApiHelpers(com.gh4a.utils.ApiHelpers)

Aggregations

UserFollowerService (com.meisolsson.githubsdk.service.users.UserFollowerService)3 ApiHelpers (com.gh4a.utils.ApiHelpers)2 Response (retrofit2.Response)2