Search in sources :

Example 41 with ApiHelpers

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);
}
Also used : Response(retrofit2.Response) LinearLayout(android.widget.LinearLayout) Repository(com.meisolsson.githubsdk.model.Repository) Bundle(android.os.Bundle) OrganizationMemberListActivity(com.gh4a.activities.OrganizationMemberListActivity) ImageView(android.widget.ImageView) Intent(android.content.Intent) HashMap(java.util.HashMap) Response(retrofit2.Response) Single(io.reactivex.Single) MenuItem(android.view.MenuItem) UserActivity(com.gh4a.activities.UserActivity) User(com.meisolsson.githubsdk.model.User) AvatarHandler(com.gh4a.utils.AvatarHandler) MenuInflater(android.view.MenuInflater) Page(com.meisolsson.githubsdk.model.Page) Map(java.util.Map) Menu(android.view.Menu) R(com.gh4a.R) View(android.view.View) StringUtils(com.gh4a.utils.StringUtils) ApiHelpers(com.gh4a.utils.ApiHelpers) OrganizationService(com.meisolsson.githubsdk.service.organizations.OrganizationService) LayoutInflater(android.view.LayoutInflater) UserFollowerService(com.meisolsson.githubsdk.service.users.UserFollowerService) Collection(java.util.Collection) FollowerFollowingListActivity(com.gh4a.activities.FollowerFollowingListActivity) RepositoryService(com.meisolsson.githubsdk.service.repositories.RepositoryService) GistListActivity(com.gh4a.activities.GistListActivity) UserType(com.meisolsson.githubsdk.model.UserType) ViewGroup(android.view.ViewGroup) DateFormat(android.text.format.DateFormat) RepositoryListActivity(com.gh4a.activities.RepositoryListActivity) List(java.util.List) TextView(android.widget.TextView) RepositoryActivity(com.gh4a.activities.RepositoryActivity) RxUtils(com.gh4a.utils.RxUtils) Gh4Application(com.gh4a.Gh4Application) ServiceFactory(com.gh4a.ServiceFactory) Repository(com.meisolsson.githubsdk.model.Repository) HashMap(java.util.HashMap) ApiHelpers(com.gh4a.utils.ApiHelpers) RepositoryService(com.meisolsson.githubsdk.service.repositories.RepositoryService)

Example 42 with ApiHelpers

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

Example 43 with ApiHelpers

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

Example 44 with ApiHelpers

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);
}
Also used : Repository(com.meisolsson.githubsdk.model.Repository) Optional(com.gh4a.utils.Optional) GitService(com.meisolsson.githubsdk.service.git.GitService) ApiHelpers(com.gh4a.utils.ApiHelpers) PullRequestMarker(com.meisolsson.githubsdk.model.PullRequestMarker) GitReference(com.meisolsson.githubsdk.model.git.GitReference) CreateGitReference(com.meisolsson.githubsdk.model.request.git.CreateGitReference)

Example 45 with ApiHelpers

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);
}
Also used : ReactionRequest(com.meisolsson.githubsdk.model.request.ReactionRequest) ReactionService(com.meisolsson.githubsdk.service.reactions.ReactionService) 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