Search in sources :

Example 1 with Comment

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

the class CommitCommentsFragment method onActivityResult.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == Activity.RESULT_OK) {
        if (requestCode == BundleConstant.REQUEST_CODE) {
            if (data == null) {
                onRefresh();
                return;
            }
            Bundle bundle = data.getExtras();
            if (bundle != null) {
                boolean isNew = bundle.getBoolean(BundleConstant.EXTRA);
                Comment commentsModel = bundle.getParcelable(BundleConstant.ITEM);
                if (commentsModel == null) {
                    // shit happens, refresh()?
                    onRefresh();
                    return;
                }
                adapter.notifyDataSetChanged();
                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 {
                // bundle size is too large? refresh the api
                onRefresh();
            }
        }
    }
}
Also used : Comment(com.fastaccess.data.dao.model.Comment) Bundle(android.os.Bundle)

Example 2 with Comment

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

the class CommitCommentsPresenter method onItemClick.

@Override
public void onItemClick(int position, View v, TimelineModel timelineModel) {
    if (getView() != null) {
        Comment item = timelineModel.getComment();
        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, login, item.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.getId());
                } else if (item1.getItemId() == R.id.reply) {
                    getView().onReply(item.getUser(), item.getBody());
                } else if (item1.getItemId() == R.id.edit) {
                    getView().onEditComment(item);
                } else if (item1.getItemId() == R.id.share) {
                    ActivityHelper.shareUrl(v.getContext(), item.getHtmlUrl());
                }
                return true;
            });
            popupMenu.show();
        } else {
            onHandleReaction(v.getId(), item.getId());
        }
    }
}
Also used : Comment(com.fastaccess.data.dao.model.Comment) PopupMenu(android.widget.PopupMenu)

Example 3 with Comment

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

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

use of com.fastaccess.data.dao.model.Comment 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)

Aggregations

Comment (com.fastaccess.data.dao.model.Comment)19 Bundle (android.os.Bundle)11 PopupMenu (android.widget.PopupMenu)8 NonNull (android.support.annotation.NonNull)7 Nullable (android.support.annotation.Nullable)7 View (android.view.View)7 R (com.fastaccess.R)7 CommentRequestModel (com.fastaccess.data.dao.CommentRequestModel)7 TimelineModel (com.fastaccess.data.dao.TimelineModel)7 Login (com.fastaccess.data.dao.model.Login)7 ReactionTypes (com.fastaccess.data.dao.types.ReactionTypes)7 BundleConstant (com.fastaccess.helper.BundleConstant)7 RxHelper (com.fastaccess.helper.RxHelper)7 RestProvider (com.fastaccess.provider.rest.RestProvider)7 BasePresenter (com.fastaccess.ui.base.mvp.presenter.BasePresenter)7 ArrayList (java.util.ArrayList)7 BaseMvp (com.fastaccess.ui.base.mvp.BaseMvp)6 ActivityHelper (com.fastaccess.helper.ActivityHelper)5 CommentsHelper (com.fastaccess.provider.timeline.CommentsHelper)5 ReactionsProvider (com.fastaccess.provider.timeline.ReactionsProvider)5