use of com.meisolsson.githubsdk.model.ReviewComment in project gh4a by slapperwan.
the class ReviewViewHolder method bind.
@Override
public void bind(TimelineItem.TimelineReview item) {
Review review = item.review();
mShowDetailsButton.setTag(review);
AvatarHandler.assignAvatar(mAvatarView, review.user());
mAvatarContainer.setTag(review.user());
formatTitle(review);
boolean hasBody = !TextUtils.isEmpty(review.body());
if (hasBody) {
mImageGetter.bind(mBodyView, review.bodyHtml(), review.id());
mBodyView.setVisibility(View.VISIBLE);
} else {
mBodyView.setVisibility(View.GONE);
}
if (mCallback.canQuote()) {
mBodyView.setCustomSelectionActionModeCallback(mQuoteActionModeCallback);
} else {
mBodyView.setCustomSelectionActionModeCallback(null);
}
boolean hasDiffs = !item.getDiffHunks().isEmpty();
if (mDisplayReviewDetails && hasDiffs) {
LayoutInflater inflater = LayoutInflater.from(mContext);
Map<String, FileDetails> files = new HashMap<>();
int viewIndex = 0;
for (TimelineItem.Diff diffHunk : item.getDiffHunks()) {
ReviewComment commitComment = diffHunk.getInitialComment();
String filename = commitComment.path();
int commentCount = diffHunk.comments.size();
boolean isOutdated = commitComment.position() == null;
if (files.containsKey(filename)) {
FileDetails details = files.get(filename);
details.isOutdated = details.isOutdated && isOutdated;
details.count += commentCount;
continue;
}
View row = mDetailsContainer.getChildAt(viewIndex);
if (row == null) {
row = inflater.inflate(R.layout.row_timeline_review_file_details, mDetailsContainer, false);
mDetailsContainer.addView(row);
row.setOnClickListener(this);
}
row.setTag(review);
row.setTag(R.id.review_comment_id, commitComment.id());
files.put(filename, new FileDetails(row, isOutdated, commentCount));
viewIndex += 1;
}
for (Map.Entry<String, FileDetails> detailsEntry : files.entrySet()) {
FileDetails fileDetails = detailsEntry.getValue();
TextView tvFile = fileDetails.row.findViewById(R.id.tv_file);
tvFile.setText("• " + detailsEntry.getKey());
if (fileDetails.isOutdated) {
tvFile.setPaintFlags(tvFile.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
} else {
tvFile.setPaintFlags(tvFile.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
}
TextView tvFileComments = fileDetails.row.findViewById(R.id.tv_file_comments);
tvFileComments.setText(String.valueOf(fileDetails.count));
fileDetails.row.setVisibility(View.VISIBLE);
}
for (int i = viewIndex; i < mDetailsContainer.getChildCount(); i++) {
mDetailsContainer.getChildAt(i).setVisibility(View.GONE);
}
mDetailsContainer.setVisibility(View.VISIBLE);
mShowDetailsButton.setVisibility(View.VISIBLE);
mDetailsHeader.setVisibility(View.VISIBLE);
} else {
mDetailsContainer.setVisibility(View.GONE);
mShowDetailsButton.setVisibility(View.GONE);
mDetailsHeader.setVisibility(View.GONE);
}
if (hasBody && mDisplayReviewDetails && hasDiffs) {
mDetailsDivider.setVisibility(View.VISIBLE);
} else {
mDetailsDivider.setVisibility(View.GONE);
}
ivMenu.setVisibility(mDisplayReviewDetails ? View.VISIBLE : View.GONE);
ivMenu.setTag(review);
mEventIconView.setImageResource(getEventIconResId(review));
}
use of com.meisolsson.githubsdk.model.ReviewComment in project gh4a by slapperwan.
the class ReviewFragment method editComment.
@Override
public void editComment(GitHubCommentBase comment) {
Intent intent;
if (comment instanceof ReviewComment) {
intent = EditPullRequestCommentActivity.makeIntent(getActivity(), mRepoOwner, mRepoName, mIssueNumber, comment.id(), 0L, comment.body(), 0);
} else {
intent = EditIssueCommentActivity.makeIntent(getActivity(), mRepoOwner, mRepoName, mIssueNumber, comment.id(), comment.body(), 0);
}
startActivityForResult(intent, REQUEST_EDIT);
}
use of com.meisolsson.githubsdk.model.ReviewComment in project gh4a by slapperwan.
the class ReviewFragment method handleDeleteComment.
private void handleDeleteComment(GitHubCommentBase comment) {
final Single<Response<Void>> responseSingle;
if (comment instanceof ReviewComment) {
PullRequestReviewCommentService service = ServiceFactory.get(PullRequestReviewCommentService.class, false);
responseSingle = service.deleteComment(mRepoOwner, mRepoName, comment.id());
} else {
IssueCommentService service = ServiceFactory.get(IssueCommentService.class, false);
responseSingle = service.deleteIssueComment(mRepoOwner, mRepoName, comment.id());
}
responseSingle.map(ApiHelpers::mapToBooleanOrThrowOnFailure).compose(RxUtils.wrapForBackgroundTask(getBaseActivity(), R.string.deleting_msg, R.string.error_delete_comment)).subscribe(result -> reloadComments(false), error -> handleActionFailure("Deleting comment failed", error));
}
use of com.meisolsson.githubsdk.model.ReviewComment in project gh4a by slapperwan.
the class ReviewFragment method addReaction.
@Override
public Single<Reaction> addReaction(GitHubCommentBase comment, String content) {
final ReactionService service = ServiceFactory.get(ReactionService.class, false);
final ReactionRequest request = ReactionRequest.builder().content(content).build();
final Single<Response<Reaction>> responseSingle = comment instanceof ReviewComment ? service.createPullRequestReviewCommentReaction(mRepoOwner, mRepoName, comment.id(), request) : service.createIssueCommentReaction(mRepoOwner, mRepoName, comment.id(), request);
return responseSingle.map(ApiHelpers::throwOnFailure);
}
use of com.meisolsson.githubsdk.model.ReviewComment 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