use of com.gh4a.utils.ApiHelpers in project gh4a by slapperwan.
the class UserFragment method loadTopRepositories.
private void loadTopRepositories(boolean force) {
RepositoryService service = ServiceFactory.get(RepositoryService.class, force, null, null, 5);
final Single<Response<Page<Repository>>> observable;
Map<String, String> filterData = new HashMap<>();
filterData.put("sort", "pushed");
filterData.put("affiliation", "owner,collaborator");
if (mIsSelf) {
observable = service.getUserRepositories(filterData, 1);
} else if (mUser.type() == UserType.Organization) {
observable = service.getOrganizationRepositories(mUser.login(), filterData, 1);
} else {
observable = service.getUserRepositories(mUser.login(), filterData, 1);
}
observable.map(ApiHelpers::throwOnFailure).map(Page::items).compose(makeLoaderSingle(ID_LOADER_REPO_LIST, force)).doOnSubscribe(disposable -> {
mContentView.findViewById(R.id.pb_top_repos).setVisibility(View.VISIBLE);
mContentView.findViewById(R.id.ll_top_repos).setVisibility(View.GONE);
}).subscribe(this::fillTopRepos, this::handleLoadFailure);
}
use of com.gh4a.utils.ApiHelpers 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();
});
}
use of com.gh4a.utils.ApiHelpers in project gh4a by slapperwan.
the class NotificationListFragment method markAsRead.
private void markAsRead(Repository repository, NotificationThread notification) {
NotificationService service = ServiceFactory.get(NotificationService.class, false);
final Single<Response<Void>> responseSingle;
if (notification != null) {
responseSingle = service.markNotificationRead(notification.id());
} else {
NotificationReadRequest request = NotificationReadRequest.builder().lastReadAt(mNotificationsLoadTime).build();
if (repository != null) {
responseSingle = service.markAllRepositoryNotificationsRead(repository.owner().login(), repository.name(), request);
} else {
responseSingle = service.markAllNotificationsRead(request);
}
}
responseSingle.map(ApiHelpers::mapToBooleanOrThrowOnFailure).compose(RxUtils::doInBackground).subscribe(result -> handleMarkAsRead(repository, notification), error -> handleActionFailure("Mark notifications as read failed", error));
}
use of com.gh4a.utils.ApiHelpers in project gh4a by slapperwan.
the class PullRequestFragment method loadHeadReference.
private void loadHeadReference(boolean force) {
GitService service = ServiceFactory.get(GitService.class, force);
PullRequestMarker head = mPullRequest.head();
Repository repo = head.repo();
Single<Optional<GitReference>> refSingle = repo == null ? Single.just(Optional.absent()) : service.getGitReference(repo.owner().login(), repo.name(), head.ref()).map(ApiHelpers::throwOnFailure).map(Optional::of).compose(RxUtils.mapFailureToValue(HttpURLConnection.HTTP_NOT_FOUND, Optional.<GitReference>absent())).compose(makeLoaderSingle(ID_LOADER_HEAD_REF, force));
refSingle.subscribe(refOpt -> {
mHeadReference = refOpt.orNull();
mHasLoadedHeadReference = true;
getActivity().invalidateOptionsMenu();
bindSpecialViews(mListHeaderView);
}, this::handleLoadFailure);
}
use of com.gh4a.utils.ApiHelpers in project gh4a by slapperwan.
the class IssueFragmentBase method addReaction.
@Override
public Single<Reaction> addReaction(GitHubCommentBase comment, String content) {
ReactionService service = ServiceFactory.get(ReactionService.class, false);
ReactionRequest request = ReactionRequest.builder().content(content).build();
return service.createIssueCommentReaction(mRepoOwner, mRepoName, comment.id(), request).map(ApiHelpers::throwOnFailure);
}
Aggregations