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;
});
}
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();
}
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);
}
}
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);
}
}
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;
});
}
Aggregations