Search in sources :

Example 1 with ReviewComment

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));
}
Also used : HashMap(java.util.HashMap) TimelineItem(com.gh4a.model.TimelineItem) ReviewComment(com.meisolsson.githubsdk.model.ReviewComment) Review(com.meisolsson.githubsdk.model.Review) ImageView(android.widget.ImageView) View(android.view.View) StyleableTextView(com.gh4a.widget.StyleableTextView) TextView(android.widget.TextView) Paint(android.graphics.Paint) LayoutInflater(android.view.LayoutInflater) StyleableTextView(com.gh4a.widget.StyleableTextView) TextView(android.widget.TextView) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with ReviewComment

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);
}
Also used : CreateReviewComment(com.meisolsson.githubsdk.model.request.pull_request.CreateReviewComment) ReviewComment(com.meisolsson.githubsdk.model.ReviewComment) Intent(android.content.Intent)

Example 3 with ReviewComment

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));
}
Also used : Response(retrofit2.Response) IssueCommentService(com.meisolsson.githubsdk.service.issues.IssueCommentService) CreateReviewComment(com.meisolsson.githubsdk.model.request.pull_request.CreateReviewComment) ReviewComment(com.meisolsson.githubsdk.model.ReviewComment) ApiHelpers(com.gh4a.utils.ApiHelpers) PullRequestReviewCommentService(com.meisolsson.githubsdk.service.pull_request.PullRequestReviewCommentService)

Example 4 with ReviewComment

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);
}
Also used : ReactionRequest(com.meisolsson.githubsdk.model.request.ReactionRequest) Response(retrofit2.Response) CreateReviewComment(com.meisolsson.githubsdk.model.request.pull_request.CreateReviewComment) ReviewComment(com.meisolsson.githubsdk.model.ReviewComment) ReactionService(com.meisolsson.githubsdk.service.reactions.ReactionService) ApiHelpers(com.gh4a.utils.ApiHelpers)

Example 5 with ReviewComment

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

ReviewComment (com.meisolsson.githubsdk.model.ReviewComment)13 Intent (android.content.Intent)7 ApiHelpers (com.gh4a.utils.ApiHelpers)6 List (java.util.List)6 IntentUtils (com.gh4a.utils.IntentUtils)5 Optional (com.gh4a.utils.Optional)5 RxUtils (com.gh4a.utils.RxUtils)5 PullRequest (com.meisolsson.githubsdk.model.PullRequest)5 PullRequestReviewCommentService (com.meisolsson.githubsdk.service.pull_request.PullRequestReviewCommentService)5 Single (io.reactivex.Single)5 View (android.view.View)4 ServiceFactory (com.gh4a.ServiceFactory)4 TimelineItem (com.gh4a.model.TimelineItem)4 Review (com.meisolsson.githubsdk.model.Review)4 HashMap (java.util.HashMap)4 Response (retrofit2.Response)4 R (com.gh4a.R)3 GitHubEvent (com.meisolsson.githubsdk.model.GitHubEvent)3 GitHubFile (com.meisolsson.githubsdk.model.GitHubFile)3 Issue (com.meisolsson.githubsdk.model.Issue)3