Search in sources :

Example 1 with WatchingService

use of com.meisolsson.githubsdk.service.activity.WatchingService in project gh4a by slapperwan.

the class RepositoryActivity method loadWatchingState.

private void loadWatchingState(boolean force) {
    if (!Gh4Application.get().isAuthorized()) {
        return;
    }
    WatchingService service = ServiceFactory.get(WatchingService.class, force);
    service.getRepositorySubscription(mRepoOwner, mRepoName).map(ApiHelpers::throwOnFailure).map(Subscription::subscribed).compose(RxUtils.mapFailureToValue(HttpURLConnection.HTTP_NOT_FOUND, false)).compose(makeLoaderSingle(ID_LOADER_WATCHING, force)).subscribe(result -> {
        mIsWatching = result;
        supportInvalidateOptionsMenu();
    }, this::handleLoadFailure);
}
Also used : WatchingService(com.meisolsson.githubsdk.service.activity.WatchingService) ApiHelpers(com.gh4a.utils.ApiHelpers)

Example 2 with WatchingService

use of com.meisolsson.githubsdk.service.activity.WatchingService in project gh4a by slapperwan.

the class RepositoryActivity method toggleWatchingState.

private void toggleWatchingState() {
    WatchingService service = ServiceFactory.get(WatchingService.class, false);
    final Single<?> responseSingle;
    if (mIsWatching) {
        responseSingle = service.deleteRepositorySubscription(mRepoOwner, mRepoName).map(ApiHelpers::throwOnFailure);
    } else {
        SubscriptionRequest request = SubscriptionRequest.builder().subscribed(true).build();
        responseSingle = service.setRepositorySubscription(mRepoOwner, mRepoName, request).map(ApiHelpers::throwOnFailure);
    }
    responseSingle.compose(RxUtils::doInBackground).subscribe(result -> {
        if (mIsWatching != null) {
            mIsWatching = !mIsWatching;
        }
        supportInvalidateOptionsMenu();
    }, error -> {
        handleActionFailure("Updating repo watching state failed", error);
        supportInvalidateOptionsMenu();
    });
}
Also used : SubscriptionRequest(com.meisolsson.githubsdk.model.request.activity.SubscriptionRequest) WatchingService(com.meisolsson.githubsdk.service.activity.WatchingService)

Aggregations

WatchingService (com.meisolsson.githubsdk.service.activity.WatchingService)2 ApiHelpers (com.gh4a.utils.ApiHelpers)1 SubscriptionRequest (com.meisolsson.githubsdk.model.request.activity.SubscriptionRequest)1