Search in sources :

Example 1 with PullRequest

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

the class PullRequestTimelinePresenter method onHandleComment.

@Override
public void onHandleComment(@NonNull String text, @Nullable Bundle bundle) {
    if (getView() == null)
        return;
    PullRequest pullRequest = getView().getPullRequest();
    if (pullRequest != null) {
        if (bundle == null) {
            CommentRequestModel commentRequestModel = new CommentRequestModel();
            commentRequestModel.setBody(text);
            manageDisposable(RxHelper.getObservable(RestProvider.getIssueService(isEnterprise()).createIssueComment(pullRequest.getLogin(), pullRequest.getRepoId(), pullRequest.getNumber(), commentRequestModel)).doOnSubscribe(disposable -> sendToView(view -> view.showBlockingProgress(0))).subscribe(comment -> sendToView(view -> view.addComment(TimelineModel.constructComment(comment))), throwable -> {
                onError(throwable);
                sendToView(PullRequestTimelineMvp.View::onHideBlockingProgress);
            }));
        }
    }
}
Also used : PullRequestStatusModel(com.fastaccess.data.dao.PullRequestStatusModel) Comment(com.fastaccess.data.dao.model.Comment) GenericEvent(com.fastaccess.data.dao.timeline.GenericEvent) Bundle(android.os.Bundle) SourceModel(com.fastaccess.data.dao.timeline.SourceModel) ActivityHelper(com.fastaccess.helper.ActivityHelper) TimelineModel(com.fastaccess.data.dao.TimelineModel) CommentsHelper(com.fastaccess.provider.timeline.CommentsHelper) Uri(android.net.Uri) InputHelper(com.fastaccess.helper.InputHelper) NonNull(android.support.annotation.NonNull) CreateIssueActivity(com.fastaccess.ui.modules.repos.issues.create.CreateIssueActivity) SchemeParser(com.fastaccess.provider.scheme.SchemeParser) ArrayList(java.util.ArrayList) RxHelper(com.fastaccess.helper.RxHelper) PopupMenu(android.widget.PopupMenu) EditReviewCommentModel(com.fastaccess.data.dao.EditReviewCommentModel) View(android.view.View) Observable(io.reactivex.Observable) ReactionTypes(com.fastaccess.data.dao.types.ReactionTypes) BasePresenter(com.fastaccess.ui.base.mvp.presenter.BasePresenter) BundleConstant(com.fastaccess.helper.BundleConstant) CommentRequestModel(com.fastaccess.data.dao.CommentRequestModel) Login(com.fastaccess.data.dao.model.Login) RestProvider(com.fastaccess.provider.rest.RestProvider) GroupedReviewModel(com.fastaccess.data.dao.GroupedReviewModel) BaseMvp(com.fastaccess.ui.base.mvp.BaseMvp) ReactionsProvider(com.fastaccess.provider.timeline.ReactionsProvider) SparseArray(android.util.SparseArray) List(java.util.List) PullRequest(com.fastaccess.data.dao.model.PullRequest) IssueEventType(com.fastaccess.data.dao.types.IssueEventType) R(com.fastaccess.R) FilterIssuesActivity(com.fastaccess.ui.modules.filter.issues.FilterIssuesActivity) ReviewCommentModel(com.fastaccess.data.dao.ReviewCommentModel) TimelineConverter(com.fastaccess.provider.timeline.TimelineConverter) Nullable(android.support.annotation.Nullable) Activity(android.app.Activity) Collections(java.util.Collections) CommentRequestModel(com.fastaccess.data.dao.CommentRequestModel) PullRequest(com.fastaccess.data.dao.model.PullRequest)

Example 2 with PullRequest

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

the class PullRequestTimelinePresenter method onLongClick.

@Override
public void onLongClick(int groupPosition, int commentPosition, @NonNull View v, @NonNull ReviewCommentModel model) {
    if (getView() == null || getView().getPullRequest() == null)
        return;
    PullRequest pullRequest = getView().getPullRequest();
    String login = pullRequest.getLogin();
    String repoId = pullRequest.getRepoId();
    if (!InputHelper.isEmpty(login) && !InputHelper.isEmpty(repoId)) {
        ReactionTypes type = ReactionTypes.get(v.getId());
        if (type != null) {
            getView().showReactionsPopup(type, login, repoId, model.getId(), ReactionsProvider.REVIEW_COMMENT);
        } else {
            onClick(groupPosition, commentPosition, v, model);
        }
    }
}
Also used : PullRequest(com.fastaccess.data.dao.model.PullRequest) ReactionTypes(com.fastaccess.data.dao.types.ReactionTypes)

Example 3 with PullRequest

use of com.fastaccess.data.dao.model.PullRequest 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 4 with PullRequest

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

the class PullRequestTimelinePresenter method onItemLongClick.

@Override
public void onItemLongClick(int position, View v, TimelineModel item) {
    if (getView() == null || getView().getPullRequest() == null)
        return;
    if (item.getType() == TimelineModel.COMMENT || item.getType() == TimelineModel.HEADER) {
        if (v.getId() == R.id.commentMenu && item.getType() == TimelineModel.COMMENT) {
            Comment comment = item.getComment();
            if (getView() != null)
                getView().onReply(comment.getUser(), comment.getBody());
        } else {
            PullRequest pullRequest = getView().getPullRequest();
            String login = pullRequest.getLogin();
            String repoId = pullRequest.getRepoId();
            if (!InputHelper.isEmpty(login) && !InputHelper.isEmpty(repoId)) {
                ReactionTypes type = ReactionTypes.get(v.getId());
                if (type != null) {
                    if (item.getType() == TimelineModel.HEADER) {
                        getView().showReactionsPopup(type, login, repoId, item.getPullRequest().getNumber(), ReactionsProvider.HEADER);
                    } else {
                        getView().showReactionsPopup(type, login, repoId, item.getComment().getId(), ReactionsProvider.COMMENT);
                    }
                } else {
                    onItemClick(position, v, item);
                }
            }
        }
    } else {
        onItemClick(position, v, item);
    }
}
Also used : Comment(com.fastaccess.data.dao.model.Comment) PullRequest(com.fastaccess.data.dao.model.PullRequest) ReactionTypes(com.fastaccess.data.dao.types.ReactionTypes)

Example 5 with PullRequest

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

the class PullRequestTimelinePresenter method onHandleReaction.

@Override
public void onHandleReaction(int vId, long idOrNumber, @ReactionsProvider.ReactionType int reactionType) {
    if (getView() == null || getView().getPullRequest() == null)
        return;
    PullRequest pullRequest = getView().getPullRequest();
    String login = pullRequest.getLogin();
    String repoId = pullRequest.getRepoId();
    Observable observable = getReactionsProvider().onHandleReaction(vId, idOrNumber, login, repoId, reactionType, isEnterprise());
    if (// noinspection unchecked
    observable != null)
        manageObservable(observable);
}
Also used : PullRequest(com.fastaccess.data.dao.model.PullRequest) Observable(io.reactivex.Observable)

Aggregations

PullRequest (com.fastaccess.data.dao.model.PullRequest)20 Bundle (android.os.Bundle)7 NonNull (android.support.annotation.NonNull)6 Nullable (android.support.annotation.Nullable)6 R (com.fastaccess.R)6 Login (com.fastaccess.data.dao.model.Login)6 BundleConstant (com.fastaccess.helper.BundleConstant)6 InputHelper (com.fastaccess.helper.InputHelper)6 RxHelper (com.fastaccess.helper.RxHelper)6 RestProvider (com.fastaccess.provider.rest.RestProvider)6 BaseMvp (com.fastaccess.ui.base.mvp.BaseMvp)6 BasePresenter (com.fastaccess.ui.base.mvp.presenter.BasePresenter)6 Observable (io.reactivex.Observable)6 ArrayList (java.util.ArrayList)6 Activity (android.app.Activity)5 CommentRequestModel (com.fastaccess.data.dao.CommentRequestModel)5 Comment (com.fastaccess.data.dao.model.Comment)5 PopupMenu (android.widget.PopupMenu)4 EditReviewCommentModel (com.fastaccess.data.dao.EditReviewCommentModel)4 GroupedReviewModel (com.fastaccess.data.dao.GroupedReviewModel)4