Search in sources :

Example 1 with TimelineItem

use of com.gh4a.model.TimelineItem 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 TimelineItem

use of com.gh4a.model.TimelineItem in project gh4a by slapperwan.

the class IssueFragmentBase method onAddData.

@Override
protected void onAddData(RootAdapter<TimelineItem, ?> adapter, List<TimelineItem> data) {
    super.onAddData(adapter, data);
    if (mInitialComment != null) {
        for (int i = 0; i < data.size(); i++) {
            TimelineItem item = data.get(i);
            if (item instanceof TimelineItem.TimelineComment) {
                TimelineItem.TimelineComment comment = (TimelineItem.TimelineComment) item;
                if (mInitialComment.matches(comment.comment().id(), comment.getCreatedAt())) {
                    scrollToAndHighlightPosition(i + 1);
                    break;
                }
            } else if (item instanceof TimelineItem.TimelineReview) {
                TimelineItem.TimelineReview review = (TimelineItem.TimelineReview) item;
                if (mInitialComment.matches(review.review().id(), review.getCreatedAt())) {
                    scrollToAndHighlightPosition(i + 1);
                    break;
                }
            }
        }
        mInitialComment = null;
    }
    updateMentionUsers();
}
Also used : TimelineItem(com.gh4a.model.TimelineItem)

Example 3 with TimelineItem

use of com.gh4a.model.TimelineItem in project gh4a by slapperwan.

the class ReviewFragment method selectAndRemoveFirstReply.

private void selectAndRemoveFirstReply(List<TimelineItem> data) {
    int groupCount = 0;
    TimelineItem.Reply firstReplyItem = null;
    TimelineItem.Diff firstDiffItem = null;
    for (TimelineItem timelineItem : data) {
        if (timelineItem instanceof TimelineItem.Diff) {
            groupCount += 1;
            if (groupCount > 1) {
                return;
            }
            if (firstDiffItem == null) {
                firstDiffItem = (TimelineItem.Diff) timelineItem;
            }
        } else if (firstDiffItem != null && timelineItem instanceof TimelineItem.Reply) {
            TimelineItem.Reply replyItem = (TimelineItem.Reply) timelineItem;
            if (replyItem.timelineComment.getParentDiff().equals(firstDiffItem)) {
                firstReplyItem = replyItem;
            }
        }
    }
    if (firstReplyItem != null) {
        mSelectedReplyCommentId = firstReplyItem.timelineComment.comment().id();
        // When there is only one reply item we don't need to display it
        data.remove(firstReplyItem);
    }
}
Also used : TimelineItem(com.gh4a.model.TimelineItem)

Example 4 with TimelineItem

use of com.gh4a.model.TimelineItem in project gh4a by slapperwan.

the class ReviewFragment method onAddData.

@Override
protected void onAddData(RootAdapter<TimelineItem, ?> adapter, List<TimelineItem> data) {
    selectAndRemoveFirstReply(data);
    // Lock the bottom sheet if there is no selected reply group
    mBottomSheet.setLocked(mSelectedReplyCommentId <= 0, R.string.no_reply_group_selected_hint);
    mCommentEditorHintResId = R.string.reply;
    for (TimelineItem item : data) {
        if (item instanceof TimelineItem.Reply) {
            mCommentEditorHintResId = R.string.review_reply_hint;
            break;
        }
    }
    mBottomSheet.updateHint();
    super.onAddData(adapter, data);
    if (mInitialComment != null) {
        highlightInitialComment(data);
    }
}
Also used : TimelineItem(com.gh4a.model.TimelineItem)

Example 5 with TimelineItem

use of com.gh4a.model.TimelineItem in project gh4a by slapperwan.

the class ReviewFragment method onCreateDataSingle.

@Override
protected Single<List<TimelineItem>> onCreateDataSingle(boolean bypassCache) {
    final PullRequestService prService = ServiceFactory.get(PullRequestService.class, bypassCache);
    final PullRequestReviewService reviewService = ServiceFactory.get(PullRequestReviewService.class, bypassCache);
    final PullRequestReviewCommentService commentService = ServiceFactory.get(PullRequestReviewCommentService.class, bypassCache);
    Single<TimelineItem.TimelineReview> reviewItemSingle = reviewService.getReview(mRepoOwner, mRepoName, mIssueNumber, mReview.id()).map(ApiHelpers::throwOnFailure).map(TimelineItem.TimelineReview::new);
    Single<List<ReviewComment>> reviewCommentsSingle = ApiHelpers.PageIterator.toSingle(page -> reviewService.getReviewComments(mRepoOwner, mRepoName, mIssueNumber, mReview.id())).compose(RxUtils.sortList(ApiHelpers.COMMENT_COMPARATOR)).cache();
    Single<Boolean> hasCommentsSingle = reviewCommentsSingle.map(comments -> !comments.isEmpty());
    Single<Optional<List<GitHubFile>>> filesSingle = hasCommentsSingle.flatMap(hasComments -> {
        if (!hasComments) {
            return Single.just(Optional.absent());
        }
        return ApiHelpers.PageIterator.toSingle(page -> prService.getPullRequestFiles(mRepoOwner, mRepoName, mIssueNumber, page)).map(Optional::of);
    });
    Single<Optional<List<ReviewComment>>> commentsSingle = hasCommentsSingle.flatMap(hasComments -> {
        if (!hasComments) {
            return Single.just(Optional.absent());
        }
        return ApiHelpers.PageIterator.toSingle(page -> commentService.getPullRequestComments(mRepoOwner, mRepoName, mIssueNumber, page)).compose(RxUtils.sortList(ApiHelpers.COMMENT_COMPARATOR)).map(Optional::of);
    });
    return Single.zip(reviewItemSingle, reviewCommentsSingle, filesSingle, commentsSingle, (reviewItem, reviewComments, filesOpt, commentsOpt) -> {
        if (!reviewComments.isEmpty()) {
            HashMap<String, GitHubFile> filesByName = new HashMap<>();
            if (filesOpt.isPresent()) {
                for (GitHubFile file : filesOpt.get()) {
                    filesByName.put(file.filename(), file);
                }
            }
            // Add all of the review comments to the review item creating necessary diff hunks
            for (ReviewComment reviewComment : reviewComments) {
                GitHubFile file = filesByName.get(reviewComment.path());
                reviewItem.addComment(reviewComment, file, true);
            }
            if (commentsOpt.isPresent()) {
                for (ReviewComment commitComment : commentsOpt.get()) {
                    if (reviewComments.contains(commitComment)) {
                        continue;
                    }
                    // Rest of the comments should be added only if they are under the same
                    // diff hunks as the original review comments.
                    GitHubFile file = filesByName.get(commitComment.path());
                    reviewItem.addComment(commitComment, file, false);
                }
            }
        }
        List<TimelineItem> items = new ArrayList<>();
        items.add(reviewItem);
        List<TimelineItem.Diff> diffHunks = new ArrayList<>(reviewItem.getDiffHunks());
        Collections.sort(diffHunks);
        for (TimelineItem.Diff diffHunk : diffHunks) {
            items.add(diffHunk);
            items.addAll(diffHunk.comments);
            if (!diffHunk.isReply()) {
                items.add(new TimelineItem.Reply(diffHunk.getInitialTimelineComment()));
            }
        }
        return items;
    });
}
Also used : CoordinatorLayout(android.support.design.widget.CoordinatorLayout) IssueCommentService(com.meisolsson.githubsdk.service.issues.IssueCommentService) Bundle(android.os.Bundle) PullRequestReviewService(com.meisolsson.githubsdk.service.pull_request.PullRequestReviewService) GitHubFile(com.meisolsson.githubsdk.model.GitHubFile) CreateReviewComment(com.meisolsson.githubsdk.model.request.pull_request.CreateReviewComment) FrameLayout(android.widget.FrameLayout) GitHubCommentBase(com.meisolsson.githubsdk.model.GitHubCommentBase) Intent(android.content.Intent) StringRes(android.support.annotation.StringRes) HashMap(java.util.HashMap) Response(retrofit2.Response) Single(io.reactivex.Single) ArrayList(java.util.ArrayList) PullRequestReviewCommentService(com.meisolsson.githubsdk.service.pull_request.PullRequestReviewCommentService) Reaction(com.meisolsson.githubsdk.model.Reaction) PullRequestService(com.meisolsson.githubsdk.service.pull_request.PullRequestService) R(com.gh4a.R) TimelineItemAdapter(com.gh4a.adapter.timeline.TimelineItemAdapter) View(android.view.View) IntentUtils(com.gh4a.utils.IntentUtils) Review(com.meisolsson.githubsdk.model.Review) ApiHelpers(com.gh4a.utils.ApiHelpers) ReactionService(com.meisolsson.githubsdk.service.reactions.ReactionService) LayoutInflater(android.view.LayoutInflater) ReviewComment(com.meisolsson.githubsdk.model.ReviewComment) EditPullRequestCommentActivity(com.gh4a.activities.EditPullRequestCommentActivity) ReactionRequest(com.meisolsson.githubsdk.model.request.ReactionRequest) ViewGroup(android.view.ViewGroup) RecyclerView(android.support.v7.widget.RecyclerView) RootAdapter(com.gh4a.adapter.RootAdapter) List(java.util.List) AlertDialog(android.support.v7.app.AlertDialog) RxUtils(com.gh4a.utils.RxUtils) EditorBottomSheet(com.gh4a.widget.EditorBottomSheet) Optional(com.gh4a.utils.Optional) EditIssueCommentActivity(com.gh4a.activities.EditIssueCommentActivity) TimelineItem(com.gh4a.model.TimelineItem) Nullable(android.support.annotation.Nullable) ServiceFactory(com.gh4a.ServiceFactory) Activity(android.app.Activity) Collections(java.util.Collections) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PullRequestService(com.meisolsson.githubsdk.service.pull_request.PullRequestService) GitHubFile(com.meisolsson.githubsdk.model.GitHubFile) ArrayList(java.util.ArrayList) List(java.util.List) PullRequestReviewCommentService(com.meisolsson.githubsdk.service.pull_request.PullRequestReviewCommentService) Optional(com.gh4a.utils.Optional) CreateReviewComment(com.meisolsson.githubsdk.model.request.pull_request.CreateReviewComment) ReviewComment(com.meisolsson.githubsdk.model.ReviewComment) TimelineItem(com.gh4a.model.TimelineItem) PullRequestReviewService(com.meisolsson.githubsdk.service.pull_request.PullRequestReviewService)

Aggregations

TimelineItem (com.gh4a.model.TimelineItem)6 Intent (android.content.Intent)3 View (android.view.View)3 R (com.gh4a.R)3 ServiceFactory (com.gh4a.ServiceFactory)3 EditIssueCommentActivity (com.gh4a.activities.EditIssueCommentActivity)3 ApiHelpers (com.gh4a.utils.ApiHelpers)3 IntentUtils (com.gh4a.utils.IntentUtils)3 RxUtils (com.gh4a.utils.RxUtils)3 GitHubCommentBase (com.meisolsson.githubsdk.model.GitHubCommentBase)3 IssueCommentService (com.meisolsson.githubsdk.service.issues.IssueCommentService)3 Single (io.reactivex.Single)3 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 List (java.util.List)3 Response (retrofit2.Response)3 Bundle (android.os.Bundle)2 AttrRes (android.support.annotation.AttrRes)2 AlertDialog (android.support.v7.app.AlertDialog)2 EditPullRequestCommentActivity (com.gh4a.activities.EditPullRequestCommentActivity)2