Search in sources :

Example 1 with IssueEventService

use of com.meisolsson.githubsdk.service.issues.IssueEventService in project gh4a by slapperwan.

the class IssueFragment method onCreateDataSingle.

@Override
protected Single<List<TimelineItem>> onCreateDataSingle(boolean bypassCache) {
    final int issueNumber = mIssue.number();
    final IssueEventService eventService = ServiceFactory.get(IssueEventService.class, bypassCache);
    final IssueCommentService commentService = ServiceFactory.get(IssueCommentService.class, bypassCache);
    Single<List<TimelineItem>> commentSingle = ApiHelpers.PageIterator.toSingle(page -> commentService.getIssueComments(mRepoOwner, mRepoName, issueNumber, page)).compose(RxUtils.mapList(TimelineItem.TimelineComment::new));
    Single<List<TimelineItem>> eventSingle = ApiHelpers.PageIterator.toSingle(page -> eventService.getIssueEvents(mRepoOwner, mRepoName, issueNumber, page)).compose(RxUtils.filter(event -> INTERESTING_EVENTS.contains(event.event()))).compose((RxUtils.mapList(TimelineItem.TimelineEvent::new)));
    return Single.zip(commentSingle, eventSingle, (comments, events) -> {
        ArrayList<TimelineItem> result = new ArrayList<>();
        result.addAll(comments);
        result.addAll(events);
        Collections.sort(result, TimelineItem.COMPARATOR);
        return result;
    });
}
Also used : IssueCommentService(com.meisolsson.githubsdk.service.issues.IssueCommentService) ApiHelpers(com.gh4a.utils.ApiHelpers) GitHubCommentBase(com.meisolsson.githubsdk.model.GitHubCommentBase) Intent(android.content.Intent) Response(retrofit2.Response) Single(io.reactivex.Single) ArrayList(java.util.ArrayList) PullRequestActivity(com.gh4a.activities.PullRequestActivity) List(java.util.List) TextView(android.widget.TextView) RxUtils(com.gh4a.utils.RxUtils) IssueState(com.meisolsson.githubsdk.model.IssueState) IssueEventService(com.meisolsson.githubsdk.service.issues.IssueEventService) R(com.gh4a.R) EditIssueCommentActivity(com.gh4a.activities.EditIssueCommentActivity) TimelineItem(com.gh4a.model.TimelineItem) Issue(com.meisolsson.githubsdk.model.Issue) View(android.view.View) AttrRes(android.support.annotation.AttrRes) ServiceFactory(com.gh4a.ServiceFactory) Collections(java.util.Collections) IntentUtils(com.gh4a.utils.IntentUtils) IssueCommentService(com.meisolsson.githubsdk.service.issues.IssueCommentService) TimelineItem(com.gh4a.model.TimelineItem) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IssueEventService(com.meisolsson.githubsdk.service.issues.IssueEventService)

Example 2 with IssueEventService

use of com.meisolsson.githubsdk.service.issues.IssueEventService in project gh4a by slapperwan.

the class PullRequestFragment method onCreateDataSingle.

@Override
protected Single<List<TimelineItem>> onCreateDataSingle(boolean bypassCache) {
    final int issueNumber = mIssue.number();
    final IssueEventService eventService = ServiceFactory.get(IssueEventService.class, bypassCache);
    final IssueCommentService commentService = ServiceFactory.get(IssueCommentService.class, bypassCache);
    final PullRequestService prService = ServiceFactory.get(PullRequestService.class, bypassCache);
    final PullRequestReviewService reviewService = ServiceFactory.get(PullRequestReviewService.class, bypassCache);
    final PullRequestReviewCommentService prCommentService = ServiceFactory.get(PullRequestReviewCommentService.class, bypassCache);
    Single<List<TimelineItem>> issueCommentItemSingle = ApiHelpers.PageIterator.toSingle(page -> commentService.getIssueComments(mRepoOwner, mRepoName, issueNumber, page)).compose(RxUtils.mapList(TimelineItem.TimelineComment::new));
    Single<List<TimelineItem>> eventItemSingle = ApiHelpers.PageIterator.toSingle(page -> eventService.getIssueEvents(mRepoOwner, mRepoName, issueNumber, page)).compose(RxUtils.filter(event -> INTERESTING_EVENTS.contains(event.event()))).compose((RxUtils.mapList(TimelineItem.TimelineEvent::new)));
    Single<Map<String, GitHubFile>> filesByNameSingle = ApiHelpers.PageIterator.toSingle(page -> prService.getPullRequestFiles(mRepoOwner, mRepoName, issueNumber, page)).map(files -> {
        Map<String, GitHubFile> filesByName = new HashMap<>();
        for (GitHubFile file : files) {
            filesByName.put(file.filename(), file);
        }
        return filesByName;
    }).cache();
    Single<List<Review>> reviewSingle = ApiHelpers.PageIterator.toSingle(page -> reviewService.getReviews(mRepoOwner, mRepoName, issueNumber, page)).cache();
    Single<List<ReviewComment>> prCommentSingle = ApiHelpers.PageIterator.toSingle(page -> prCommentService.getPullRequestComments(mRepoOwner, mRepoName, issueNumber, page)).compose(RxUtils.sortList(ApiHelpers.COMMENT_COMPARATOR)).cache();
    Single<LongSparseArray<List<ReviewComment>>> reviewCommentsByIdSingle = reviewSingle.compose(RxUtils.filter(r -> r.state() == ReviewState.Pending)).toObservable().flatMap(reviews -> {
        List<Observable<Pair<Long, List<ReviewComment>>>> obsList = new ArrayList<>();
        for (Review r : reviews) {
            Single<List<ReviewComment>> single = ApiHelpers.PageIterator.toSingle(page -> reviewService.getReviewComments(mRepoOwner, mRepoName, issueNumber, r.id()));
            obsList.add(Single.zip(Single.just(r.id()), single, Pair::create).toObservable());
        }
        return Observable.concat(obsList);
    }).toList().map(list -> {
        LongSparseArray<List<ReviewComment>> result = new LongSparseArray<>();
        for (Pair<Long, List<ReviewComment>> pair : list) {
            result.put(pair.first, pair.second);
        }
        return result;
    });
    Single<List<TimelineItem.TimelineReview>> reviewTimelineSingle = Single.zip(reviewSingle, filesByNameSingle, prCommentSingle, reviewCommentsByIdSingle, (prReviews, filesByName, commitComments, pendingCommentsById) -> {
        LongSparseArray<TimelineItem.TimelineReview> reviewsById = new LongSparseArray<>();
        List<TimelineItem.TimelineReview> reviews = new ArrayList<>();
        for (Review review : prReviews) {
            TimelineItem.TimelineReview timelineReview = new TimelineItem.TimelineReview(review);
            reviewsById.put(review.id(), timelineReview);
            reviews.add(timelineReview);
            if (review.state() == ReviewState.Pending) {
                for (ReviewComment pendingComment : pendingCommentsById.get(review.id())) {
                    GitHubFile commitFile = filesByName.get(pendingComment.path());
                    timelineReview.addComment(pendingComment, commitFile, true);
                }
            }
        }
        Map<String, TimelineItem.TimelineReview> reviewsBySpecialId = new HashMap<>();
        for (ReviewComment commitComment : commitComments) {
            GitHubFile file = filesByName.get(commitComment.path());
            if (commitComment.pullRequestReviewId() != null) {
                String id = TimelineItem.Diff.getDiffHunkId(commitComment);
                TimelineItem.TimelineReview review = reviewsBySpecialId.get(id);
                if (review == null) {
                    review = reviewsById.get(commitComment.pullRequestReviewId());
                    reviewsBySpecialId.put(id, review);
                }
                review.addComment(commitComment, file, true);
            }
        }
        return reviews;
    }).compose(RxUtils.filter(item -> {
        // noinspection CodeBlock2Expr
        return item.review().state() != ReviewState.Commented || !TextUtils.isEmpty(item.review().body()) || !item.getDiffHunks().isEmpty();
    }));
    Single<List<TimelineItem.TimelineComment>> commitCommentWithoutReviewSingle = Single.zip(prCommentSingle.compose(RxUtils.filter(comment -> comment.pullRequestReviewId() == 0)), filesByNameSingle, (comments, files) -> {
        List<TimelineItem.TimelineComment> items = new ArrayList<>();
        for (ReviewComment comment : comments) {
            items.add(new TimelineItem.TimelineComment(comment, files.get(comment.path())));
        }
        return items;
    });
    return Single.zip(issueCommentItemSingle, eventItemSingle, reviewTimelineSingle, commitCommentWithoutReviewSingle, (comments, events, reviewItems, commentsWithoutReview) -> {
        ArrayList<TimelineItem> result = new ArrayList<>();
        result.addAll(comments);
        result.addAll(events);
        result.addAll(reviewItems);
        result.addAll(commentsWithoutReview);
        Collections.sort(result, TimelineItem.COMPARATOR);
        return result;
    });
}
Also used : HttpURLConnection(java.net.HttpURLConnection) IssueCommentService(com.meisolsson.githubsdk.service.issues.IssueCommentService) Bundle(android.os.Bundle) PullRequestReviewService(com.meisolsson.githubsdk.service.pull_request.PullRequestReviewService) Status(com.meisolsson.githubsdk.model.Status) GitHubFile(com.meisolsson.githubsdk.model.GitHubFile) RepositoryStatusService(com.meisolsson.githubsdk.service.repositories.RepositoryStatusService) PullRequest(com.meisolsson.githubsdk.model.PullRequest) PullRequestReviewCommentService(com.meisolsson.githubsdk.service.pull_request.PullRequestReviewCommentService) IssueState(com.meisolsson.githubsdk.model.IssueState) Map(java.util.Map) Issue(com.meisolsson.githubsdk.model.Issue) View(android.view.View) AttrRes(android.support.annotation.AttrRes) PullRequestBranchInfoView(com.gh4a.widget.PullRequestBranchInfoView) IntentUtils(com.gh4a.utils.IntentUtils) Review(com.meisolsson.githubsdk.model.Review) Set(java.util.Set) EditPullRequestCommentActivity(com.gh4a.activities.EditPullRequestCommentActivity) List(java.util.List) RxUtils(com.gh4a.utils.RxUtils) GitService(com.meisolsson.githubsdk.service.git.GitService) Optional(com.gh4a.utils.Optional) EditIssueCommentActivity(com.gh4a.activities.EditIssueCommentActivity) TimelineItem(com.gh4a.model.TimelineItem) ReviewState(com.meisolsson.githubsdk.model.ReviewState) Repository(com.meisolsson.githubsdk.model.Repository) LongSparseArray(android.support.v4.util.LongSparseArray) Pair(android.util.Pair) GitHubCommentBase(com.meisolsson.githubsdk.model.GitHubCommentBase) Intent(android.content.Intent) HashMap(java.util.HashMap) GitReference(com.meisolsson.githubsdk.model.git.GitReference) Response(retrofit2.Response) Single(io.reactivex.Single) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) PullRequestService(com.meisolsson.githubsdk.service.pull_request.PullRequestService) MenuInflater(android.view.MenuInflater) CommitStatusBox(com.gh4a.widget.CommitStatusBox) IssueEventService(com.meisolsson.githubsdk.service.issues.IssueEventService) Menu(android.view.Menu) R(com.gh4a.R) Observable(io.reactivex.Observable) CreateGitReference(com.meisolsson.githubsdk.model.request.git.CreateGitReference) ApiHelpers(com.gh4a.utils.ApiHelpers) Iterator(java.util.Iterator) PullRequestMarker(com.meisolsson.githubsdk.model.PullRequestMarker) ReviewComment(com.meisolsson.githubsdk.model.ReviewComment) TextUtils(android.text.TextUtils) AlertDialog(android.support.v7.app.AlertDialog) ServiceFactory(com.gh4a.ServiceFactory) Comparator(java.util.Comparator) Collections(java.util.Collections) IssueCommentService(com.meisolsson.githubsdk.service.issues.IssueCommentService) LongSparseArray(android.support.v4.util.LongSparseArray) ArrayList(java.util.ArrayList) Review(com.meisolsson.githubsdk.model.Review) PullRequestService(com.meisolsson.githubsdk.service.pull_request.PullRequestService) GitHubFile(com.meisolsson.githubsdk.model.GitHubFile) List(java.util.List) ArrayList(java.util.ArrayList) IssueEventService(com.meisolsson.githubsdk.service.issues.IssueEventService) PullRequestReviewCommentService(com.meisolsson.githubsdk.service.pull_request.PullRequestReviewCommentService) Pair(android.util.Pair) TimelineItem(com.gh4a.model.TimelineItem) ReviewComment(com.meisolsson.githubsdk.model.ReviewComment) Observable(io.reactivex.Observable) Map(java.util.Map) HashMap(java.util.HashMap) PullRequestReviewService(com.meisolsson.githubsdk.service.pull_request.PullRequestReviewService)

Aggregations

Intent (android.content.Intent)2 AttrRes (android.support.annotation.AttrRes)2 View (android.view.View)2 R (com.gh4a.R)2 ServiceFactory (com.gh4a.ServiceFactory)2 EditIssueCommentActivity (com.gh4a.activities.EditIssueCommentActivity)2 TimelineItem (com.gh4a.model.TimelineItem)2 ApiHelpers (com.gh4a.utils.ApiHelpers)2 IntentUtils (com.gh4a.utils.IntentUtils)2 RxUtils (com.gh4a.utils.RxUtils)2 GitHubCommentBase (com.meisolsson.githubsdk.model.GitHubCommentBase)2 Issue (com.meisolsson.githubsdk.model.Issue)2 IssueState (com.meisolsson.githubsdk.model.IssueState)2 IssueCommentService (com.meisolsson.githubsdk.service.issues.IssueCommentService)2 IssueEventService (com.meisolsson.githubsdk.service.issues.IssueEventService)2 Bundle (android.os.Bundle)1 LongSparseArray (android.support.v4.util.LongSparseArray)1 AlertDialog (android.support.v7.app.AlertDialog)1 TextUtils (android.text.TextUtils)1 Pair (android.util.Pair)1