Search in sources :

Example 1 with EditReviewCommentModel

use of com.fastaccess.data.dao.EditReviewCommentModel in project FastHub by k0shk0sh.

the class PullRequestTimelineFragment method onActivityResult.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == Activity.RESULT_OK) {
        if (data == null) {
            onRefresh();
            return;
        }
        Bundle bundle = data.getExtras();
        if (bundle != null) {
            boolean isNew = bundle.getBoolean(BundleConstant.EXTRA);
            if (requestCode == BundleConstant.REQUEST_CODE) {
                Comment commentsModel = bundle.getParcelable(BundleConstant.ITEM);
                if (commentsModel == null) {
                    // bundle size is too large? refresh the api
                    onRefresh();
                    return;
                }
                if (isNew) {
                    adapter.addItem(TimelineModel.constructComment(commentsModel));
                    recycler.smoothScrollToPosition(adapter.getItemCount());
                } else {
                    int position = adapter.getItem(TimelineModel.constructComment(commentsModel));
                    if (position != -1) {
                        adapter.swapItem(TimelineModel.constructComment(commentsModel), position);
                        recycler.smoothScrollToPosition(position);
                    } else {
                        adapter.addItem(TimelineModel.constructComment(commentsModel));
                        recycler.smoothScrollToPosition(adapter.getItemCount());
                    }
                }
            } else if (requestCode == BundleConstant.REVIEW_REQUEST_CODE) {
                EditReviewCommentModel commentModel = bundle.getParcelable(BundleConstant.ITEM);
                if (commentModel == null) {
                    // bundle size is too large? refresh the api
                    onRefresh();
                    return;
                }
                TimelineModel timelineModel = adapter.getItem(commentModel.getGroupPosition());
                if (isNew) {
                    if (timelineModel.getGroupedReviewModel() != null && timelineModel.getGroupedReviewModel().getComments() != null) {
                        timelineModel.getGroupedReviewModel().getComments().add(commentModel.getCommentModel());
                        adapter.notifyItemChanged(commentModel.getGroupPosition());
                    } else {
                        onRefresh();
                    }
                } else {
                    if (timelineModel.getGroupedReviewModel() != null && timelineModel.getGroupedReviewModel().getComments() != null) {
                        timelineModel.getGroupedReviewModel().getComments().set(commentModel.getCommentPosition(), commentModel.getCommentModel());
                        adapter.notifyItemChanged(commentModel.getGroupPosition());
                    } else {
                        onRefresh();
                    }
                }
            }
        } else {
            // bundle size is too large? refresh the api
            onRefresh();
        }
    }
}
Also used : Comment(com.fastaccess.data.dao.model.Comment) Bundle(android.os.Bundle) EditReviewCommentModel(com.fastaccess.data.dao.EditReviewCommentModel) TimelineModel(com.fastaccess.data.dao.TimelineModel)

Example 2 with EditReviewCommentModel

use of com.fastaccess.data.dao.EditReviewCommentModel in project FastHub by k0shk0sh.

the class PullRequestTimelinePresenter method onItemClick.

@Override
public void onItemClick(int position, View v, TimelineModel item) {
    if (getView() == null)
        return;
    PullRequest pullRequest = getView().getPullRequest();
    if (pullRequest != null) {
        if (item.getType() == TimelineModel.COMMENT) {
            if (v.getId() == R.id.commentMenu) {
                PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
                popupMenu.inflate(R.menu.comments_menu);
                String username = Login.getUser().getLogin();
                boolean isOwner = CommentsHelper.isOwner(username, pullRequest.getLogin(), item.getComment().getUser().getLogin()) || isCollaborator;
                popupMenu.getMenu().findItem(R.id.delete).setVisible(isOwner);
                popupMenu.getMenu().findItem(R.id.edit).setVisible(isOwner);
                popupMenu.setOnMenuItemClickListener(item1 -> {
                    if (getView() == null)
                        return false;
                    if (item1.getItemId() == R.id.delete) {
                        getView().onShowDeleteMsg(item.getComment().getId());
                    } else if (item1.getItemId() == R.id.reply) {
                        getView().onReply(item.getComment().getUser(), item.getComment().getBodyHtml());
                    } else if (item1.getItemId() == R.id.edit) {
                        getView().onEditComment(item.getComment());
                    } else if (item1.getItemId() == R.id.share) {
                        ActivityHelper.shareUrl(v.getContext(), item.getComment().getHtmlUrl());
                    }
                    return true;
                });
                popupMenu.show();
            } else {
                onHandleReaction(v.getId(), item.getComment().getId(), ReactionsProvider.COMMENT);
            }
        } else if (item.getType() == TimelineModel.EVENT) {
            GenericEvent issueEventModel = item.getGenericEvent();
            if (issueEventModel.getCommitUrl() != null) {
                SchemeParser.launchUri(v.getContext(), Uri.parse(issueEventModel.getCommitUrl()));
            } else if (issueEventModel.getLabel() != null) {
                FilterIssuesActivity.startActivity(v, pullRequest.getLogin(), pullRequest.getRepoId(), false, true, isEnterprise(), "label:\"" + issueEventModel.getLabel().getName() + "\"");
            } else if (issueEventModel.getMilestone() != null) {
                FilterIssuesActivity.startActivity(v, pullRequest.getLogin(), pullRequest.getRepoId(), false, true, isEnterprise(), "milestone:\"" + issueEventModel.getMilestone().getTitle() + "\"");
            } else if (issueEventModel.getAssignee() != null) {
                FilterIssuesActivity.startActivity(v, pullRequest.getLogin(), pullRequest.getRepoId(), false, true, isEnterprise(), "assignee:\"" + issueEventModel.getAssignee().getLogin() + "\"");
            } else if (issueEventModel.getEvent() == IssueEventType.committed) {
                SchemeParser.launchUri(v.getContext(), issueEventModel.getUrl().replace("git/", ""));
            } else {
                SourceModel sourceModel = issueEventModel.getSource();
                if (sourceModel != null) {
                    if (sourceModel.getCommit() != null) {
                        SchemeParser.launchUri(v.getContext(), sourceModel.getCommit().getUrl());
                    } else if (sourceModel.getPullRequest() != null) {
                        SchemeParser.launchUri(v.getContext(), sourceModel.getPullRequest().getUrl());
                    } else if (sourceModel.getIssue() != null) {
                        SchemeParser.launchUri(v.getContext(), sourceModel.getIssue().getHtmlUrl());
                    } else if (sourceModel.getRepository() != null) {
                        SchemeParser.launchUri(v.getContext(), sourceModel.getRepository().getUrl());
                    }
                }
            }
        } else if (item.getType() == TimelineModel.HEADER) {
            if (v.getId() == R.id.commentMenu) {
                PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
                popupMenu.inflate(R.menu.comments_menu);
                String username = Login.getUser().getLogin();
                boolean isOwner = CommentsHelper.isOwner(username, item.getPullRequest().getLogin(), item.getPullRequest().getUser().getLogin()) || isCollaborator;
                popupMenu.getMenu().findItem(R.id.edit).setVisible(isOwner);
                popupMenu.setOnMenuItemClickListener(item1 -> {
                    if (getView() == null)
                        return false;
                    if (item1.getItemId() == R.id.reply) {
                        getView().onReply(item.getPullRequest().getUser(), item.getPullRequest().getBodyHtml());
                    } else if (item1.getItemId() == R.id.edit) {
                        Activity activity = ActivityHelper.getActivity(v.getContext());
                        if (activity == null)
                            return false;
                        CreateIssueActivity.startForResult(activity, item.getPullRequest().getLogin(), item.getPullRequest().getRepoId(), item.getPullRequest(), isEnterprise());
                    } else if (item1.getItemId() == R.id.share) {
                        ActivityHelper.shareUrl(v.getContext(), item.getPullRequest().getHtmlUrl());
                    }
                    return true;
                });
                popupMenu.show();
            } else {
                onHandleReaction(v.getId(), item.getPullRequest().getNumber(), ReactionsProvider.HEADER);
            }
        } else if (item.getType() == TimelineModel.GROUP) {
            GroupedReviewModel reviewModel = item.getGroupedReviewModel();
            if (v.getId() == R.id.addCommentPreview) {
                if (getView() != null) {
                    EditReviewCommentModel model = new EditReviewCommentModel();
                    model.setCommentPosition(-1);
                    model.setGroupPosition(position);
                    model.setInReplyTo(reviewModel.getId());
                    getView().onReplyOrCreateReview(null, null, position, -1, model);
                }
            }
        }
    }
}
Also used : SourceModel(com.fastaccess.data.dao.timeline.SourceModel) GenericEvent(com.fastaccess.data.dao.timeline.GenericEvent) EditReviewCommentModel(com.fastaccess.data.dao.EditReviewCommentModel) PullRequest(com.fastaccess.data.dao.model.PullRequest) CreateIssueActivity(com.fastaccess.ui.modules.repos.issues.create.CreateIssueActivity) FilterIssuesActivity(com.fastaccess.ui.modules.filter.issues.FilterIssuesActivity) Activity(android.app.Activity) GroupedReviewModel(com.fastaccess.data.dao.GroupedReviewModel) PopupMenu(android.widget.PopupMenu)

Example 3 with EditReviewCommentModel

use of com.fastaccess.data.dao.EditReviewCommentModel in project FastHub by k0shk0sh.

the class PullRequestTimelinePresenter method onClick.

@Override
public void onClick(int groupPosition, int commentPosition, @NonNull View v, @NonNull ReviewCommentModel comment) {
    if (getView() == null || getView().getPullRequest() == null)
        return;
    if (v.getId() == R.id.commentMenu) {
        PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
        popupMenu.inflate(R.menu.comments_menu);
        String username = Login.getUser().getLogin();
        boolean isOwner = CommentsHelper.isOwner(username, getView().getPullRequest().getLogin(), comment.getUser().getLogin()) || isCollaborator;
        popupMenu.getMenu().findItem(R.id.delete).setVisible(isOwner);
        popupMenu.getMenu().findItem(R.id.edit).setVisible(isOwner);
        popupMenu.setOnMenuItemClickListener(item1 -> {
            if (getView() == null)
                return false;
            if (item1.getItemId() == R.id.delete) {
                getView().onShowReviewDeleteMsg(comment.getId(), groupPosition, commentPosition);
            } else if (item1.getItemId() == R.id.reply) {
                EditReviewCommentModel model = new EditReviewCommentModel();
                model.setGroupPosition(groupPosition);
                model.setCommentPosition(commentPosition);
                model.setInReplyTo(comment.getId());
                getView().onReplyOrCreateReview(comment.getUser(), comment.getBodyHtml(), groupPosition, commentPosition, model);
            } else if (item1.getItemId() == R.id.edit) {
                getView().onEditReviewComment(comment, groupPosition, commentPosition);
            } else if (item1.getItemId() == R.id.share) {
                ActivityHelper.shareUrl(v.getContext(), comment.getHtmlUrl());
            }
            return true;
        });
        popupMenu.show();
    } else {
        onHandleReaction(v.getId(), comment.getId(), ReactionsProvider.REVIEW_COMMENT);
    }
}
Also used : EditReviewCommentModel(com.fastaccess.data.dao.EditReviewCommentModel) PopupMenu(android.widget.PopupMenu)

Example 4 with EditReviewCommentModel

use of com.fastaccess.data.dao.EditReviewCommentModel in project FastHub by k0shk0sh.

the class PullRequestTimelineFragment method onEditReviewComment.

@Override
public void onEditReviewComment(@NonNull ReviewCommentModel item, int groupPosition, int childPosition) {
    EditReviewCommentModel model = new EditReviewCommentModel();
    model.setCommentPosition(childPosition);
    model.setGroupPosition(groupPosition);
    model.setInReplyTo(item.getId());
    Intent intent = new Intent(getContext(), EditorActivity.class);
    if (getPullRequest() == null)
        return;
    intent.putExtras(Bundler.start().put(BundleConstant.ID, getPullRequest().getRepoId()).put(BundleConstant.EXTRA_TWO, getPullRequest().getLogin()).put(BundleConstant.EXTRA_THREE, getPullRequest().getNumber()).put(BundleConstant.EXTRA_FOUR, item.getId()).put(BundleConstant.EXTRA, item.getBody()).put(BundleConstant.REVIEW_EXTRA, model).put(BundleConstant.EXTRA_TYPE, BundleConstant.ExtraType.EDIT_REVIEW_COMMENT_EXTRA).putStringArrayList("participants", CommentsHelper.getUsersByTimeline(adapter.getData())).put(BundleConstant.IS_ENTERPRISE, isEnterprise()).end());
    View view = getFromView();
    ActivityHelper.startReveal(this, intent, view, BundleConstant.REVIEW_REQUEST_CODE);
}
Also used : EditReviewCommentModel(com.fastaccess.data.dao.EditReviewCommentModel) Intent(android.content.Intent) BindView(butterknife.BindView) View(android.view.View) DynamicRecyclerView(com.fastaccess.ui.widgets.recyclerview.DynamicRecyclerView) MessageDialogView(com.fastaccess.ui.widgets.dialog.MessageDialogView)

Aggregations

EditReviewCommentModel (com.fastaccess.data.dao.EditReviewCommentModel)4 PopupMenu (android.widget.PopupMenu)2 Activity (android.app.Activity)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 View (android.view.View)1 BindView (butterknife.BindView)1 GroupedReviewModel (com.fastaccess.data.dao.GroupedReviewModel)1 TimelineModel (com.fastaccess.data.dao.TimelineModel)1 Comment (com.fastaccess.data.dao.model.Comment)1 PullRequest (com.fastaccess.data.dao.model.PullRequest)1 GenericEvent (com.fastaccess.data.dao.timeline.GenericEvent)1 SourceModel (com.fastaccess.data.dao.timeline.SourceModel)1 FilterIssuesActivity (com.fastaccess.ui.modules.filter.issues.FilterIssuesActivity)1 CreateIssueActivity (com.fastaccess.ui.modules.repos.issues.create.CreateIssueActivity)1 MessageDialogView (com.fastaccess.ui.widgets.dialog.MessageDialogView)1 DynamicRecyclerView (com.fastaccess.ui.widgets.recyclerview.DynamicRecyclerView)1